def test_scipy(self):
     global data
     global data_mu
     global data_sd
     global init
     global state_sd
     global tspan
     global sampler_args
     
     
     all_data = {'OD600': pd.read_csv('data/OD600_Data.csv', header=[0, 1]),
                 'Fluor': pd.read_csv('data/GFP_Data.csv', header=[0, 1])
                 }
     
     #Normalize Fluorescence by OD and convert to Molar
     all_data['Fluor'] = divide(all_data['Fluor'], all_data['OD600'])
     all_data['Fluor'] = multiply(all_data['Fluor'], 1e-6/(18.814*30))
     
     data_by_model_num = {1: {'OD600': all_data['OD600'],
                              'Fluor': all_data['Fluor']
                              }
                           }
     '''
     Iterate across each type of sampler
     '''
     filename_samplers = [('settings_cf_de_1.ini', 'de', cf.scipy_differential_evolution),
                          ('settings_cf_bh_1.ini', 'bh', cf.scipy_basinhopping),
                          ('settings_cf_da_1.ini', 'da', cf.scipy_dual_annealing)
                          ]
     
     for filename, sampler, sampler_function in filename_samplers:
         print('Test sampler', sampler)
         #Extract the necessary information
         #Note that subtraction of the blank has been included in this function!!!
         data, data_mu, data_sd, init, state_sd, tspan = import_data(all_data, data_by_model_num)
     
         sampler_args, config_data = sc.get_sampler_args(filename, sampler)
         
         states = {1: ['OD600', 'Glu', 'Fluor'],
                   }
         
         sampler_args = update_sampler_args(data, data_mu, data_sd, init, state_sd, tspan, sampler_args, states)
         
             
         result = sampler_function(**sampler_args)
     
         # assert type(result) == dict
         print()
 def test_get_sampler_args(self):
     global user_core_models
     global settings_file_1
     global sampler_args
     global config_data
 
     filename    = settings_file_1
     
     #Get arguments for simulation
     result = sc.get_sampler_args(filename, user_core_models=user_core_models)
     
     #Expect models, params, config_data = result
     assert len(result) == 2
     
     try:
        sampler_args, config_data = result
     except:
         sampler_args, config_data = result.values()   
Ejemplo n.º 3
0
        }
    }
    #Extract the necessary information
    #Note that subtraction of the blank has been included in this function!!!
    data, data_mu, data_sd, init, state_sd, tspan = import_data(
        all_data, data_by_model_num)
    '''
    Iterate across each type of sampler
    '''
    filename_samplers = [('settings_de.ini', 'de',
                          cf.scipy_differential_evolution),
                         ('settings_bh.ini', 'bh', cf.scipy_basinhopping),
                         ('settings_da.ini', 'da', cf.scipy_dual_annealing)]

    for filename, sampler, sampler_function in filename_samplers:
        sampler_args, config_data = sc.get_sampler_args(filename, sampler)

        states = {
            1: ['OD600', 'Glu', 'Fluor'],
        }

        sampler_args = update_sampler_args(data, data_mu, data_sd, init,
                                           state_sd, tspan, sampler_args,
                                           states)

        result = sampler_function(**sampler_args)
        '''
        The return value is a dictionary with the following values.
        'a': The accepted samples as a DataFrame
        'r': The rejected samples as a DataFrame if applicable
        's': The scipy return value if applicable
    directory = output_folder / 'simulation_results'

    sim.export_simulation_results(ym, em, prefix=prefix, directory=directory)
    '''Run curvefitting and model selection using the same configuration file.
    The steps are as follows:
        1. prepare configuration .ini file (aside from core model information)
            - guess, priors, parameter_bounds, fixed_parameters,
        2. get_sampler_args
        3. update sampler_args with information from experimental data file
        4. run curve fitting algorithm
        5. plot results: can include simulation from guess (optional)
        6. plot traces to check for convergence
        7. calculate and rank aic
    '''

    sampler_args, config_data = sc.get_sampler_args(
        model_files, user_core_models=user_core_models)
    print('\nsampler_args:\n', sampler_args)

    sampler_args['data'] = data_mu

    for model_num in sampler_args['models']:
        sampler_args['models'][model_num]['tspan'] = [tspan]
        sampler_args['models'][model_num]['sd'] = state_sd
        sampler_args['models'][model_num]['states'][-1] = 'Fluor/OD'
        model_init = {
            scenario: [
                init[model_num][scenario].get(state, 0)
                for state in sampler_args['models'][model_num]['states']
            ]
            for scenario in init[model_num]
        }
Ejemplo n.º 5
0
    of analysis are all very similar. This allows you to copy and paste sections as 
    appropriate.
    '''
    '''
    1. Reading the Settings File
    '''

    filename = 'settings_sa.ini'
    config_data = sc.from_config(filename, sampler='sa')
    '''
    2. Compiling Arguments
    '''

    core_model = mh.from_config('Monod_Constitutive_Single.ini')
    user_core_models = {core_model['system_type']: core_model}
    sampler_args, config_data = sc.get_sampler_args(
        config_data, sampler='sa', user_core_models=user_core_models)
    '''
    3. Wrapping for Models in Database
    
    For models already in the database, we can combine the above steps into a single 
    function call.
    '''

    new_sampler_args, new_config_data = sc.get_sampler_args(filename,
                                                            sampler='sa')
    '''
    Note that possible values for sampler are:
        'sa' : simulated annealing
        'bh' : scipy's basin hopping
        'da' : scipy's dual annealing
        'de' : scipy's differential evoluation