def main(): parser = argparse.ArgumentParser() parser.add_argument('--config', **config.SECTIONS['general']['config']) sino_params = ('consumer', 'data-tags') reco_params = ('dependencies', 'pvs') tomo_params = config.ALL_PARAMS gui_params = tomo_params print(tomo_params) cmd_parsers = [ ('init', init, (), "Create configuration file"), ('update', update, tomo_params, "Update configuration file"), ] subparsers = parser.add_subparsers(title="Commands", metavar='') for cmd, func, sections, text in cmd_parsers: cmd_params = config.Params(sections=sections) cmd_parser = subparsers.add_parser(cmd, help=text, formatter_class=argparse.ArgumentDefaultsHelpFormatter) cmd_parser = cmd_params.add_arguments(cmd_parser) cmd_parser.set_defaults(_func=func) args = config.parse_known_args(parser, subparser=True) log_level = logging.DEBUG if args.verbose else logging.INFO LOG.setLevel(log_level) stream_handler = logging.StreamHandler(sys.stdout) stream_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s')) LOG.addHandler(stream_handler) if args.log: file_handler = logging.FileHandler(args.log) file_handler.setFormatter(logging.Formatter('%(name)s:%(levelname)s: %(message)s')) LOG.addHandler(file_handler) try: config.log_values(args) args._func(args) except RuntimeError as e: LOG.error(str(e)) sys.exit(1)
def plot_single_var(yy, var_name, tt, num_samples=c.num_samples, on_off=c.on_off, days_on=c.days_on): # Removes first three cycles tt_mask = np.where(tt >= 84, True, False) tt = tt[tt_mask] yy = yy[tt_mask] yy = get_variable(var_name, yy, tt, c.Params(), days_on) title, ylabel, ylim = get_plotting_params(var_name) if on_off: on_off_mask = np.where((tt % 28) >= days_on, True, False) on_tt = tt[~on_off_mask] off_tt = tt[on_off_mask] on_yy = yy[~on_off_mask] off_yy = yy[on_off_mask] plt.plot(on_tt, on_yy, '.') plt.plot(off_tt, off_yy, '.') plt.title(title) plt.ylabel(ylabel) plt.xlabel('time (days)') plt.ylim((0, ylim)) plt.show() else: plt.plot(tt, yy) plt.title(title) plt.ylabel(ylabel) plt.xlabel('time (days)') plt.ylim((0, ylim)) plt.show()
def solve(days_on=c.days_on, lam_up=c.lam_up, lam_down=c.lam_down, func_form=c.func_form, e_dose=None, p_dose=None, missed_start=c.missed_start, days_missed=c.days_missed): """ Params: days_on (float) number of days taking hormonal birth control lam_up (float) if func_form is "soft_step", lam_up is lam_up param for soft_step() lam_down (float) if func_form is "soft_step", lam_down is lam_down param for soft_step() if func_form is "exp_decay", lam_down is the lam param for exp_decay() if func_form is "lin_decay", lam_down is the intercept param for lin_decay() func_form (string) indicates which functional form is being used to represent hormone dosing e_dose (float) default value is None, if e_dose = None, e_dose = c.e_dose p_dose (float) default value is None, if p_dose = None, p_dose = c.p_dose Returns: tt (ndarray) yy (ndarray) """ params = c.Params() print(f"missed days: {days_missed}") print(f"missed start: {missed_start}") if e_dose is not None: params.e_dose = e_dose if p_dose is not None: params.p_dose = p_dose tt = np.linspace(0, c.upper_bound, c.num_samples) yy = ddeint(derivs, initial_conditions, tt, fargs=(params, days_on, lam_up, lam_down, func_form, missed_start, days_missed)) return tt, yy
import numpy as np import matplotlib.pyplot as plt import config as c import sympy as sp p = c.Params() # E_2 = p.e_0 + p.e_1*GrF + p.e_2*DomF + p.e_3*Lut_4 + p.e_dose # P_4 = p.p_0 + p.p_1*Lut_3 + p.p_2*Lut_4 + p.p_dose # P_app = ((p.p_0 + p.p_1*Lut_3 + p.p_2*Lut_4 + p.p_dose)/2)*(1 + ((p.e_0 + p.e_1*GrF + p.e_2*DomF + p.e_3*Lut_4 + p.e_dose)**p.mu / (p.K_mPapp**p.mu + (p.e_0 + p.e_1*GrF + p.e_2*DomF + p.e_3*Lut_4 + p.e_dose)**p.mu))) # InhA = p.h_0 + p.h_1*DomF + p.h_2*Lut_2 + p.h_3*Lut_3 def create_matrix(e_dose, p_dose): RP_LH, LH, RP_FSH, FSH, RcF, GrF, DomF, Sc_1, Sc_2, Lut_1, Lut_2, Lut_3, Lut_4 = sp.symbols( 'RP_LH LH RP_FSH FSH RcF GrF DomF Sc_1 Sc_2 Lut_1 Lut_2 Lut_3 Lut_4') print(f'edose before: {p.e_dose}') p.e_dose = e_dose print(f'edose after: {p.e_dose}') p.p_dose = p_dose # Pituitary and hypothaalamus axis matrix = sp.Matrix([ # RP_LH ((p.V_0LH + (p.V_1LH*((p.e_0 + p.e_1*GrF + p.e_2*DomF + p.e_3*Lut_4 + p.e_dose)**8)/(p.K_mLH**8 + (p.e_0 + p.e_1*GrF + p.e_2*DomF + p.e_3*Lut_4 + p.e_dose)**8)))/(1+((((p.p_0 + p.p_1*Lut_3 + p.p_2*Lut_4 + p.p_dose)/2)*(1 + ((p.e_0 + p.e_1*GrF + p.e_2*DomF + p.e_3*Lut_4 + p.e_dose)**p.mu / (p.K_mPapp**p.mu + (p.e_0 + p.e_1*GrF + p.e_2*DomF + p.e_3*Lut_4 + p.e_dose)**p.mu))))/p.K_iLHP))) - \ ((p.k_LH*(1 + p.c_LHP*(((p.p_0 + p.p_1*Lut_3 + p.p_2*Lut_4 + p.p_dose)/2)*(1 + ((p.e_0 + p.e_1*GrF + p.e_2*DomF + p.e_3*Lut_4 + p.e_dose)**p.mu / (p.K_mPapp**p.mu + (p.e_0 + p.e_1*GrF + p.e_2*DomF + p.e_3*Lut_4 + p.e_dose)**p.mu)))))*RP_LH)/(1+p.c_LHE*(p.e_0 + p.e_1*GrF + p.e_2*DomF + p.e_3*Lut_4 + p.e_dose))), # LH (p.k_LH*(1+p.c_LHP*(((p.p_0 + p.p_1*Lut_3 + p.p_2*Lut_4 + p.p_dose)/2)*(1 + ((p.e_0 + p.e_1*GrF + p.e_2*DomF + p.e_3*Lut_4 + p.e_dose)**p.mu / (p.K_mPapp**p.mu + (p.e_0 + p.e_1*GrF + p.e_2*DomF + p.e_3*Lut_4 + p.e_dose)**p.mu)))))*RP_LH)/(p.v*(1+p.c_LHE*(p.e_0 + p.e_1*GrF + p.e_2*DomF + p.e_3*Lut_4 + p.e_dose))) - p.a_LH*LH, # RP_FSH (p.v_FSH/(1+(p.h_0 + p.h_1*DomF + p.h_2*Lut_2 + p.h_3*Lut_3)/p.K_iFSH_InhA)) - \
import data_exploration import utilities import supervised import unsupervised import personalized_autoencoder # workspace print("Actual workspace: ", os.getcwd()) # logger # sys.stdout = config.Logger("log/log.txt") # loading data and params and elementary exploration loader = config.Loader() params = config.Params() # elementary exploration data_exploration.summary(loader) # manage missing starting_data = data_exploration.manage_missing(loader.data) # variable distribution per class and linear correlation data_exploration.variable_distribution(starting_data) data_exploration.linear_correlation(starting_data) # shuffle starting_data = shuffle(starting_data).reset_index(drop=True) # Supervised - naive attempt
def plot_four_variables_red(yy, var_names, tt, num_samples=c.num_samples, on_off=c.on_off, days_on=c.days_on, lam_up=c.lam_up, lam_down=c.lam_down, func_form=c.func_form, missed_start=c.missed_start, days_missed=c.days_missed): # Removes first 3 cycles tt_mask = np.where(tt >= 84, True, False) tt = tt[tt_mask] yy = yy[tt_mask] dosing = calc_e_dose(np.asarray(tt), 1, func_form, lam_up=lam_up, lam_down=lam_down, missed_start=missed_start, days_missed=days_missed) print(np.asarray(tt)) print(dosing) # print(tt) # dosing = np.where((tt%28)>=days_on, 0, 1) y = [] titles = [] ylabels = [] ylims = [] print('\nStarting to get variables') for var in var_names: print(f'Getting {var}') y.append( get_variable(var, yy, tt, c.Params(), days_on, lam_up=lam_up, lam_down=lam_down, func_form=func_form, missed_start=missed_start, days_missed=days_missed)) title, ylabel, ylim = get_plotting_params(var) titles.append(title) ylabels.append(ylabel) ylims.append(ylim) fig, axs = plt.subplots(2, 2) if on_off: ax1 = axs[0, 0] ax2 = ax1.twinx() ax1.plot(tt, y[0]) ax2.plot(tt, dosing, c='r') ax2.set(ylim=(-3, 1.5)) else: axs[0, 0].plot(tt, y[0]) axs[0, 0].set_title(var_names[0]) if on_off: ax1 = axs[0, 1] ax2 = ax1.twinx() ax1.plot(tt, y[1]) ax2.plot(tt, dosing, c='r') ax2.set(ylim=(-3, 1.5)) else: axs[0, 1].plot(tt, y[1]) axs[0, 1].set_title(var_names[1]) if on_off: ax1 = axs[1, 1] ax2 = ax1.twinx() ax1.plot(tt, y[3]) ax2.plot(tt, dosing, c='r') ax2.set(ylim=(-3, 1.5)) else: axs[1, 1].plot(tt, y[3]) axs[1, 1].set_title(var_names[3]) if on_off: ax1 = axs[1, 0] ax2 = ax1.twinx() ax1.plot(tt, y[2]) ax2.plot(tt, dosing, c='r') ax2.set(ylim=(-3, 1.5)) else: axs[1, 0].plot(tt, y[2]) axs[1, 0].set_title(var_names[2]) i = 0 for ax in axs.flat: ax.set(xlabel='Time (days)', ylabel=ylabels[i], ylim=(0, ylims[i])) i += 1 fig.suptitle('Dose: ' + c.dosing) plt.tight_layout() plt.show()
def plot_four_variables(yy, var_names, tt, num_samples=c.num_samples, on_off=c.on_off, days_on=c.days_on, lam_up=c.lam_up, lam_down=c.lam_down, func_form=c.func_form): # Removes first 3 cycles tt_mask = np.where(tt >= 84, True, False) tt = tt[tt_mask] yy = yy[tt_mask] if on_off: on_off_mask = np.where((tt % 28) >= days_on, True, False) on_tt = tt[~on_off_mask] off_tt = tt[on_off_mask] y = [] titles = [] ylabels = [] ylims = [] for var in var_names: y.append( get_variable(var, yy, tt, c.Params(), days_on, lam_up, lam_down)) title, ylabel, ylim = get_plotting_params(var) titles.append(title) ylabels.append(ylabel) ylims.append(ylim) fig, axs = plt.subplots(2, 2) if on_off: on_yy = y[0][~on_off_mask] off_yy = y[0][on_off_mask] axs[0, 0].plot(on_tt, on_yy, '.', markersize=1) axs[0, 0].plot(off_tt, off_yy, '.', markersize=1) else: axs[0, 0].plot(tt, y[0]) axs[0, 0].set_title(var_names[0]) if on_off: on_yy = y[1][~on_off_mask] off_yy = y[1][on_off_mask] axs[0, 1].plot(on_tt, on_yy, '.', markersize=1) axs[0, 1].plot(off_tt, off_yy, '.', markersize=1) else: axs[0, 1].plot(tt, y[1]) axs[0, 1].set_title(var_names[1]) if on_off: on_yy = y[3][~on_off_mask] off_yy = y[3][on_off_mask] axs[1, 1].plot(on_tt, on_yy, '.', markersize=1) axs[1, 1].plot(off_tt, off_yy, '.', markersize=1) else: axs[1, 1].plot(tt, y[3]) axs[1, 1].set_title(var_names[3]) if on_off: on_yy = y[2][~on_off_mask] off_yy = y[2][on_off_mask] axs[1, 0].plot(on_tt, on_yy, '.', markersize=1) axs[1, 0].plot(off_tt, off_yy, '.', markersize=1) else: axs[1, 0].plot(tt, y[2]) axs[1, 0].set_title(var_names[2]) i = 0 for ax in axs.flat: ax.set(xlabel='Time (days)', ylabel=ylabels[i], ylim=(0, ylims[i])) i += 1 fig.suptitle('Dose: ' + c.dosing) plt.tight_layout() plt.show()