Пример #1
0
def generate_samples(problem, params, project_dir, method):
    """
    The Saltelli sampler generated 8000 samples. The Saltelli sampler generates N*(2D+2) samples, where in this
    example N is 1000 (the argument we supplied) and D is 3 (the number of model inputs).
    """

    if method == 'Saltelli':
        param_values = saltelli.sample(problem, params['samples'])
    elif method == 'FAST':
        param_values = fast_sampler.sample(problem, params['samples'])

    count = 0

    for i, X in enumerate(param_values):
        count += 1
        p, w, pred_fle = par.get_params(innate, X)
        _numpoints = 100
        t = [
            par._stoptime * float(i) / (_numpoints - 1)
            for i in range(_numpoints)
        ]
        w0 = innate.get_init(w, params)
        t, wsol = innate.solve(p, w0, t, params)
        APE_blood = []
        CH = []
        ACH = []
        for t1, w1 in zip(t, wsol):
            APE_blood.append(w1[1])
            CH.append(w1[10])
            ACH.append(w1[13])
        # Y_list.append(APE_blood)
        write_file(project_dir, method, APE_blood, 'AP')
        write_file(project_dir, method, CH, 'CH')
        write_file(project_dir, method, ACH, 'ACH')
        print(count, ' of ', len(param_values))
Пример #2
0
def get_peaks(p, w0, header, time):
    global RMSE_peaks
    params = {}
    params['h'] = 'h4'
    params['restrict'] = False
    params['case'] = 5
    time, model = innate.solve(p, w0, time, params)
    df_pred = pd.DataFrame(model)
    keys = df_pred.columns.values
    dictionary = dict(zip(keys, header))
    df_pred = df_pred.rename(columns=dictionary)
    placebo_n_a = df_pred['n_a']/max(df_pred['n_a'])
    placebo_nd_n = df_pred['nd_n']/max(df_pred['nd_n'])
    placebo_nd_a = df_pred['nd_a']/max(df_pred['nd_a'])

    params = {}
    params['h'] = 'h4'
    params['restrict'] = False
    params['case'] = 6
    time, model = innate.solve(p, w0, time, params)
    df_pred = pd.DataFrame(model)
    keys = df_pred.columns.values
    dictionary = dict(zip(keys, header))
    df_pred = df_pred.rename(columns=dictionary)
    supplemented_n_a = df_pred['n_a']/max(df_pred['n_a'])
    supplemented_nd_n = df_pred['nd_n']/max(df_pred['nd_n'])
    supplemented_nd_a = df_pred['nd_a']/max(df_pred['nd_a'])

    if max(placebo_nd_n) > max(supplemented_nd_n):
        nd_n_error = 0
    if max(placebo_nd_n) <= max(supplemented_nd_n):
        nd_n_error = abs(max(placebo_nd_n) - max(supplemented_nd_n))
    if max(placebo_nd_a) < max(supplemented_nd_a):
        nd_a_error = 0
    if max(placebo_nd_a) >= max(supplemented_nd_a):
        nd_a_error = abs(max(placebo_nd_a) - max(supplemented_nd_a))
    if max(placebo_n_a) < max(supplemented_n_a):
        n_a_error = abs(max(placebo_n_a) - max(supplemented_n_a))
    if max(placebo_n_a) >= max(supplemented_n_a):
        n_a_error = 0

    try:
        sum_error = np.sum([nd_n_error, nd_a_error, n_a_error])
    except UnboundLocalError as u_error:
        print(u_error)
        sum_error = 1*10**10

    RMSE_peaks = sum_error
    return sum_error
Пример #3
0
def get_objective_function(p0, params):
    files = get_files()
    df_cyto_data = get_cyto_data(files)
    df_ap_data = get_ap_data(files)
    header = get_header()
    p, w, pred_fle = par.get_params(innate, p0)
    w0 = innate.get_init(w, params)

    df_cyto_model, df_cyto_data = get_concentrations(df_data=df_cyto_data,
                                                     p=p,
                                                     w0=w0,
                                                     header=header,
                                                     blood_parameter='cytokine',
                                                     params=params)
    df_ap_model, df_ap_data = get_concentrations(df_data=df_ap_data,
                                                 p=p,
                                                 w0=w0,
                                                 header=header,
                                                 blood_parameter='ap',
                                                 params=params)

    rmse_p = get_rmse(params, df_cyto_data, df_ap_data, df_cyto_model, df_ap_model)
    rmse_n = get_peaks(p, w0, header, time=[par._stoptime * float(i) / (par._numpoints - 1)
                                            for i in range(par._numpoints)])
    rmse = rmse_p + rmse_n
    print('RMSE is {0}.'.format(rmse))
    return rmse
Пример #4
0
def get_rmse(params, df_cyto_data, df_ap_data, df_cyto_model, df_ap_model):
    # print("Computing RMSEs...")
    # note: Pro-inflammatory Cytokine = IL6, Anti-inflammatory Cytokine = IL10
    global RMSE_CH
    global RMSE_ACH
    global RMSE_AP
    global RMSE_peaks

    df_ch_data = df_cyto_data[df_cyto_data['cytokine'] == 'il6']
    df_ach_data = df_cyto_data[df_cyto_data['cytokine'] == 'il10']

    df_ch_model = df_cyto_model['ch']
    df_ach_model = df_cyto_model['ach']
    # df_ch_model = cyto.reverse_unit(df_cyto_model['ch'].tolist(), 'il6')
    # df_ach_model = cyto.reverse_unit(df_cyto_model['ach'].tolist(), 'il10')
    df_ap_model = np.add(df_ap_model['ap_eblood'], df_ap_model['ap_sblood'])
    df_ap_model_converted = innate.reverse_AP(df_ap_model, 'endo', 'blood')

    df_ch_data_median = df_ch_data['median']
    df_ach_data_median = df_ach_data['median']
    # df_ch_data_median = cyto.reverse_unit(df_ch_data['median'].tolist(), 'il6')
    # df_ach_data_median = cyto.reverse_unit(df_ach_data['median'].tolist(), 'il10')
    df_ap_data_median = df_ap_data['median']

    # normalize
    if max(df_ch_data_median) != 0: df_ch_data_median = df_ch_data_median/max(df_ch_data_median)
    if max(df_ch_model) != 0: df_ch_model = df_ch_model/max(df_ch_model.dropna())

    if max(df_ach_data_median) != 0: df_ach_data_median = df_ach_data_median/max(df_ach_data_median)
    if max(df_ach_model) != 0: df_ach_model = df_ach_model/max(df_ach_model.dropna())

    if max(df_ap_data_median) != 0: df_ap_data_median = df_ap_data_median/max(df_ap_data_median)
    if max(df_ap_model_converted) != 0: df_ap_model_converted = df_ap_model_converted/max(df_ap_model_converted.dropna())

    try:
        rmse_CH = (np.sqrt(mean_squared_error(y_true=df_ch_data_median,
                                              y_pred=df_ch_model,
                                              sample_weight=df_ch_data['weights'])))
        rmse_ACH = (np.sqrt(mean_squared_error(y_true=df_ach_data_median,
                                               y_pred=df_ach_model,
                                               sample_weight=df_ach_data['weights'])))
        rmse_AP = (np.sqrt(mean_squared_error(y_true=df_ap_data_median,
                                              y_pred=df_ap_model_converted,
                                              sample_weight=df_ap_data['weights'])))

    except ValueError as v_error:
        print(v_error)
        RMSE_CH, RMSE_ACH, RMSE_AP = 1e10, 1e10, 1e10

        rmse_CH = RMSE_CH
        rmse_ACH = RMSE_ACH
        rmse_AP = RMSE_AP

    sum_RMSE = np.sum([rmse_CH, rmse_ACH, rmse_AP])
    RMSE_CH = rmse_CH
    RMSE_ACH = rmse_ACH
    RMSE_AP = rmse_AP
    return sum_RMSE
Пример #5
0
def get_concentrations(df_data, p, w0, header, blood_parameter, params):
    # print("Getting concentrations for...", blood_parameter)
    df_data_rstrct, time_rstrct = get_restricted_data(df_data, blood_parameter, params)
    time, model = innate.solve(p, w0, time_rstrct, params)
    df_model = pd.DataFrame(model)
    keys = df_model.columns.values
    dictionary = dict(zip(keys, header))
    df_model = df_model.rename(columns=dictionary)
    df_model['time'] = time
    df_data_rstrct = set_weights(df_data_rstrct, blood_parameter)
    return df_model, df_data_rstrct