Esempio n. 1
0
def generate_samples(sp, n_runs, VPD=2.0, tmax=180):
    var_vals = [traits[sp][get_part(v)][v] for v in var_names[:-1]]
    var_vals.extend([Rmax])
    problem_bounds = [[min(0.5 * v, 2.0 * v),
                       max(0.5 * v, 2.0 * v)] for v in var_vals]
    #     problem_bounds = [[min(0.25*v,4.0*v), max(0.25*v,4.0*v)] for v in var_vals]
    problem = {
        'num_vars': n_vars,
        'names': var_names,
        'bounds': problem_bounds
    }
    # generate samples
    param_values = saltelli.sample(problem, n_runs, calc_second_order=False)
    print len(param_values)
    ''' parallel processing '''
    ncores = mp.cpu_count()
    print('There are %s cores on this machine ' % (str(ncores), ))
    pool = mp.Pool()
    param_cores = np.array_split(param_values, ncores, axis=0)
    param_augmented = [(p, VPD, tmax) for p in param_cores]
    Y_pooled = pool.map(evaluate_model, param_augmented)
    Y = np.vstack(Y_pooled)  # output shape (len(param_values), 2)

    with open(
            '/Users/xuefeng/Dropbox/Projects/Isohydricity/Sobol/Si_' + sp +
            '_vpd' + str(int(VPD)) + '_tmax' + str(tmax) + '_outcomes.pickle',
            'wb') as handle:
        pickle.dump(Y, handle)
    with open(
            '/Users/xuefeng/Dropbox/Projects/Isohydricity/Sobol/Si_' + sp +
            '_vpd' + str(int(VPD)) + '_tmax' + str(tmax) + '_params.pickle',
            'wb') as handle:
        pickle.dump(param_values, handle)
    return Y, param_values
Esempio n. 2
0
def define_problem(sp):
    var_vals = [traits[sp][get_part(v)][v] for v in var_names]
    problem_bounds = [[min(0.5 * v, 2.0 * v),
                       max(0.5 * v, 2.0 * v)] for v in var_vals]
    problem = {
        'num_vars': n_vars,
        'names': var_names,
        'bounds': problem_bounds
    }
    return problem
Esempio n. 3
0
def Sobol(sp, n_runs):
    var_vals = [traits[sp][get_part(v)][v] for v in var_names[:-1]]
    var_vals.extend([Rmax])
    problem_bounds = [[min(0.5 * v, 2.0 * v),
                       max(0.5 * v, 2.0 * v)] for v in var_vals]
    problem = {
        'num_vars': n_vars,
        'names': var_names,
        'bounds': problem_bounds
    }
    # generate samples
    param_values = saltelli.sample(problem, n_runs, calc_second_order=False)
    print len(param_values)

    VPD = 2.0
    gridsize = 10
    Si_depo = np.zeros(
        (gridsize, n_vars, 4))  # number of increments, parameters, Assm/HF/CIs
    for i, tmax in enumerate(np.linspace(60, 240, gridsize)):
        print i,
        ''' parallel processing '''
        ncores = mp.cpu_count()
        print('There are %s cores on this machine ' % (str(ncores), ))
        pool = mp.Pool()
        param_cores = np.array_split(param_values, ncores, axis=0)
        param_augmented = [(p, VPD, tmax) for p in param_cores]
        Y_pooled = pool.map(evaluate_model, param_augmented)
        Y = np.vstack(Y_pooled)  # output shape (len(param_values), 2)

        # perform analysis
        Si_A = sobol.analyze(problem,
                             Y[:, 1],
                             calc_second_order=False,
                             print_to_console=True)
        try:
            Si_H = sobol.analyze(problem,
                                 Y[:, 0],
                                 calc_second_order=False,
                                 print_to_console=True)
        except:
            pass

        # store
        Si_depo[i, :, 0] = Si_H['ST']
        Si_depo[i, :, 1] = Si_A['ST_conf']
        Si_depo[i, :, 2] = Si_H['ST']
        Si_depo[i, :, 3] = Si_A['ST_conf']
        with open(
                '/Users/xuefeng/Dropbox/Projects/Isohydricity/Sobol/Si_' + sp +
                '_vpd' + str(int(VPD)) + '_tmax' + str(tmax) + '.pickle',
                'wb') as handle:
            pickle.dump(Si_depo, handle)
    return Si_depo
Esempio n. 4
0
def define_problem(sp='JUNI'):
    var_vals = [traits[sp][get_part(v)][v] for v in var_names[:-1]]
    var_vals.extend([Rmax])
    problem_bounds = [[min(0.5 * v, 2.0 * v),
                       max(0.5 * v, 2.0 * v)] for v in var_vals]
    # problem_bounds = [[min(0.25*v,4.0*v), max(0.25*v,4.0*v)] for v in var_vals]
    problem = {
        'num_vars': n_vars,
        'names': var_names,
        'bounds': problem_bounds
    }
    return problem