def posterior_prediction(parameter_vector, parameter_names=parameter_names):
    # Make predictions
    Mixed_Model.set_parameters(parameter_vector)
    dradf = Mixed_Model.doseresponse(times,
                                     'TotalpSTAT',
                                     'Ia',
                                     dose_range,
                                     parameters={'Ib': 0},
                                     scale_factor=sf,
                                     return_type='dataframe',
                                     dataframe_labels='Alpha')
    drbdf = Mixed_Model.doseresponse(times,
                                     'TotalpSTAT',
                                     'Ib',
                                     dose_range,
                                     parameters={'Ia': 0},
                                     scale_factor=sf,
                                     return_type='dataframe',
                                     dataframe_labels='Beta')

    posterior = IfnData('custom',
                        df=pd.concat((dradf, drbdf)),
                        conditions={
                            'Alpha': {
                                'Ib': 0
                            },
                            'Beta': {
                                'Ia': 0
                            }
                        })
    posterior.drop_sigmas()
    return posterior
def posterior_prediction(model, parameter_vector, parameter_names, sf,
                         test_times=[2.5, 5.0, 7.5, 10.0, 20.0, 60.0],
                         alpha_doses=np.logspace(-1, 5, 15),
                         beta_doses=np.logspace(-1, 5, 15)):
    """
    Produce predictions for IFNa and IFNb using model with parameters given
    as input to the function.
    """
    # Make predictions
    model.set_parameters(parameter_vector)
    dradf = model.doseresponse(test_times, 'TotalpSTAT', 'Ia',
                               alpha_doses, parameters={'Ib': 0},
                               scale_factor=sf,
                               return_type='dataframe',
                               dataframe_labels='Alpha')
    drbdf = model.doseresponse(test_times, 'TotalpSTAT', 'Ib',
                               beta_doses, parameters={'Ia': 0},
                               scale_factor=sf,
                               return_type='dataframe',
                               dataframe_labels='Beta')

    posterior = IfnData('custom', df=pd.concat((dradf, drbdf)),
                        conditions={'Alpha': {'Ib': 0},
                                    'Beta': {'Ia': 0}})
    posterior.drop_sigmas()
    return posterior
def posterior_prediction(parameter_vector, parameter_names=parameter_names):
    # Make predictions
    Mixed_Model.update_parameters(parameter_vector)
    dradf = Mixed_Model.mixed_dose_response(times, 'TotalpSTAT', 'Ia', list(np.logspace(1, 5.2)),
                                            parameters={'Ib': 0}, sf=scale_factor)
    drbdf = Mixed_Model.mixed_dose_response(times, 'TotalpSTAT', 'Ib', list(np.logspace(-1, 4)),
                                            parameters={'Ia': 0}, sf=scale_factor)

    posterior = IfnData('custom', df=pd.concat((dradf, drbdf)), conditions={'Alpha': {'Ib': 0}, 'Beta': {'Ia': 0}})
    posterior.drop_sigmas()
    return posterior
Exemple #4
0
    def __posterior_prediction__(self, parameter_dict, test_times,
                                 observable, dose_species, doses,
                                 scale_factor, conditions, dataframe_label):
        """
        Produce predictions for IFNa and IFNb using model with parameters given
        as input to the function.
        """
        # Update parameters
        if self.param_dist_flag:
            # find all distribution parameters
            dist_param_names = []
            for key in parameter_dict.keys():
                if key.endswith('_mu*'):
                    dist_param_names.append(key[:-4])
            # sample according to mu, std
            dist_param_dict = {}
            for pname in dist_param_names:
                mu = np.log10(parameter_dict[pname + '_mu*'])
                std = parameter_dict[pname + '_std*']
                sample = 10 ** np.random.normal(loc=mu, scale=std)
                dist_param_dict.update({pname: sample})
                # remove distribution parameters
                parameter_dict.pop(pname + '_mu*')
                parameter_dict.pop(pname + '_std*')
            # add sample to parameter_dict
            parameter_dict.update(dist_param_dict)

        parameter_dict.update(conditions)

        # Make predictions
        df = self.model.doseresponse(test_times, observable, dose_species,
                                     doses, parameters=parameter_dict,
                                     scale_factor=scale_factor,
                                     return_type='dataframe',
                                     dataframe_labels=dataframe_label)
        posterior = IfnData('custom', df=df, conditions=conditions)
        posterior.drop_sigmas()
        return posterior
Exemple #5
0
    # Make predictions
    times = [2.5, 5.0, 7.5, 10.0, 20.0, 60.0]
    test_doses = list(logspace(-1, 5.2))

    dradf = Mixed_Model.mixed_dose_response(times, 'TotalpSTAT', 'Ia', test_doses,
                                            parameters={'Ib': 0}, sf=scale_factor)
    drbdf = Mixed_Model.mixed_dose_response(times, 'TotalpSTAT', 'Ib', test_doses,
                                            parameters={'Ia': 0}, sf=scale_factor)

    dra60 = IfnData('custom', df=dradf, conditions={'Alpha': {'Ib': 0}})
    drb60 = IfnData('custom', df=drbdf, conditions={'Beta': {'Ia': 0}})

    # -------------------------------------------
    # Get comparisons of beta to alpha response
    # -------------------------------------------
    dra60_noSigma = dra60.drop_sigmas(in_place=False)
    drb60_noSigma = drb60.drop_sigmas(in_place=False)

    temp1 = drb60_noSigma.data_set.loc['Beta'] / dra60_noSigma.data_set.loc['Alpha']
    temp1 = pd.concat([temp1], keys=['Ratio'], names=['Dose_Species'])
    ratio_response = IfnData('custom', df=temp1)
    ratio_response.add_sigmas()

    temp2 = drb60_noSigma.data_set.loc['Beta'] - dra60_noSigma.data_set.loc['Alpha']
    temp2 = pd.concat([temp2], keys=['Difference'], names=['Dose_Species'])
    difference_response = IfnData('custom', df=temp2)
    difference_response.add_sigmas()

    # ---------------------------------------------
    # Signal integration requires a bit more work
    # ---------------------------------------------
def score_params(params):
    # --------------------
    # Set up Model
    # --------------------
    Mixed_Model, DR_method = lm.load_model()
    scale_factor, DR_KWARGS = lm.SCALE_FACTOR, lm.DR_KWARGS
    Mixed_Model.set_parameters(params)

    # Make predictions
    times = [2.5, 5.0, 7.5, 10.0, 20.0, 60.0]
    alpha_doses = [10, 100, 300, 1000, 3000, 10000, 100000]
    beta_doses = [0.2, 6, 20, 60, 200, 600, 2000]

    dra60 = DR_method(times,
                      'TotalpSTAT',
                      'Ia',
                      alpha_doses,
                      parameters={'Ib': 0},
                      sf=scale_factor,
                      **DR_KWARGS)

    drb60 = DR_method(times,
                      'TotalpSTAT',
                      'Ib',
                      beta_doses,
                      parameters={'Ia': 0},
                      sf=scale_factor,
                      **DR_KWARGS)
    sim_df = IfnData('custom',
                     df=pd.concat((dra60.data_set, drb60.data_set)),
                     conditions={
                         'Alpha': {
                             'Ib': 0
                         },
                         'Beta': {
                             'Ia': 0
                         }
                     })

    # --------------------
    # Set up Data
    # --------------------
    newdata_1 = IfnData("20190108_pSTAT1_IFN_Bcell")
    newdata_2 = IfnData("20190119_pSTAT1_IFN_Bcell")
    newdata_3 = IfnData("20190121_pSTAT1_IFN_Bcell")
    newdata_4 = IfnData("20190214_pSTAT1_IFN_Bcell")

    # Aligned data, to get scale factors for each data set
    alignment = DataAlignment()
    alignment.add_data([newdata_4, newdata_3, newdata_2, newdata_1])
    alignment.align()
    alignment.get_scaled_data()
    mean_data = alignment.summarize_data()

    # --------------------
    # Score model
    # --------------------
    sim_df.drop_sigmas()
    mean_data.drop_sigmas()

    # rmse = RMSE(mean_data.data_set.values, sim_df.data_set.values)
    mae = MAE(mean_data.data_set.values, sim_df.data_set.values)
    return mae
Exemple #7
0
                         'Beta': {
                             'Ia': 0
                         }
                     })

    # --------------------
    # Set up Data
    # --------------------
    newdata_1 = IfnData("20190108_pSTAT1_IFN_Bcell")
    newdata_2 = IfnData("20190119_pSTAT1_IFN_Bcell")
    newdata_3 = IfnData("20190121_pSTAT1_IFN_Bcell")
    newdata_4 = IfnData("20190214_pSTAT1_IFN_Bcell")

    # Aligned data, to get scale factors for each data set
    alignment = DataAlignment()
    alignment.add_data([newdata_4, newdata_3, newdata_2, newdata_1])
    alignment.align()
    alignment.get_scaled_data()
    mean_data = alignment.summarize_data()

    # --------------------
    # Score model
    # --------------------
    sim_df.drop_sigmas()
    mean_data.drop_sigmas()

    rmse = RMSE(mean_data.data_set.values, sim_df.data_set.values)
    mae = MAE(mean_data.data_set.values, sim_df.data_set.values)
    print("RMSE = ", rmse)
    print("MAE = ", mae)
    # Perform simulations
    # --------------------
    times = [2.5, 5.0, 10.0, 20.0, 30.0, 60.0]
    doses = [10, 100, 300, 1000, 3000, 10000, 100000]

    df = testModel.doseresponse(times,
                                'TotalpSTAT',
                                'Ia',
                                doses,
                                parameters={'Ib': 0},
                                scale_factor=4.1,
                                return_type='dataframe',
                                dataframe_labels='Alpha')
    print(df)
    DR_Simulation = IfnData('custom', df=df, conditions={'Alpha': {'Ib': 0}})
    DR_Simulation.drop_sigmas()

    # -----------------------------------------------------------
    # Load several sets of experimental data and align them
    # -----------------------------------------------------------

    # These datasets are already prepared for use in /ifndatabase
    expdata_1 = IfnData("20190214_pSTAT1_IFN_Bcell")
    expdata_2 = IfnData("20190121_pSTAT1_IFN_Bcell")
    expdata_3 = IfnData("20190119_pSTAT1_IFN_Bcell")
    expdata_4 = IfnData("20190108_pSTAT1_IFN_Bcell")

    # Aligned data, to get scale factors for each data set
    alignment = DataAlignment()
    alignment.add_data([expdata_1, expdata_2, expdata_3, expdata_4])
    alignment.align()