예제 #1
0
def get_sampler_args_sa(filename, user_core_models={}):
    '''Shortcut for setting up simulated annealing for one model
    
    :meta: private
    '''

    config_data, core_models = setup_helper(filename, from_config, user_core_models)
    models, params = compile_models(core_models, config_data)
    
    guess            = {}
    bounds           = {}
    priors           = {}
    step_size        = {}
    blocks           = []
    fixed_parameters = []
    trials           = []
    for key in config_data:
        models[key]['init']                    = config_data[key]['init']
        models[key]['tspan']                   = config_data[key]['tspan']
        models[key]['int_args']['solver_args'] = config_data[key]['solver_args']
        
        temp      = {param + '_' + str(key): float(config_data[key]['guess'][param]) for param in config_data[key]['guess']}
        guess     = {**guess, **temp}
        
        temp      = {param + '_' + str(key): config_data[key]['parameter_bounds'][param] for param in config_data[key]['parameter_bounds']}
        bounds    = {**bounds, **temp} 
        
        temp      = {param + '_' + str(key): config_data[key]['priors'][param] for param in config_data[key]['priors']}
        priors    = {**priors, **temp}
    
        temp      = {param + '_' + str(key): config_data[key]['step_size'][param] for param in config_data[key]['step_size']}
        step_size = {**step_size, **temp}
        
        blocks += [[param + '_' + str(key) for param in block] for block in config_data[key]['sa_args'].get('blocks', [])]
        
        fixed_parameters   += [param + '_' + str(key) for param in config_data[key]['fixed_parameters']]
        fixed_parameters   += [i     + '_' + str(key) for i     in core_models[key-1]['inputs']]
        
        if 'trials' in config_data[key]['sa_args']:
            trials.append(config_data[key]['sa_args']['trials'])
        
    sampler_args = {'data'     : {},
                    'guess'    : guess,
                    'models'   : models, 
                    'fixed_parameters'     : fixed_parameters,
                    'priors'   : priors,
                    'bounds'   : bounds,
                    'blocks'   : blocks,
                    'step_size': step_size,
                    'trials'   : max(trials) if trials else 3000,
                    }
        
    return sampler_args, config_data
예제 #2
0
def get_sampler_args_bh(filename, user_core_models={}):
    '''Shortcut for setting up differential evolution for one model
    
    :meta: private
    '''

    config_data    = from_config(filename, 'bh') if type(filename) == str else filename
    core_models    = [mh.quick_search(config_data[key]['system_type']) for key in config_data]
    models, params = compile_models(core_models, config_data)
    
    guess            = {}
    bounds           = {}
    priors           = {}
    fixed_parameters = []
    step_size        = {}
    scipy_args       = {}
    for key in config_data:
        models[key]['init']                    = config_data[key]['init']
        models[key]['tspan']                   = config_data[key]['tspan']
        models[key]['int_args']['solver_args'] = config_data[key]['solver_args']
        
        temp      = {param + '_' + str(key): float(config_data[key]['guess'][param]) for param in config_data[key]['guess']}
        guess     = {**guess, **temp}
        
        temp      = {param + '_' + str(key): config_data[key]['parameter_bounds'][param] for param in config_data[key]['parameter_bounds']}
        bounds    = {**bounds, **temp} 
        
        temp      = {param + '_' + str(key): config_data[key]['priors'][param] for param in config_data[key]['priors']}
        priors    = {**priors, **temp}
        
        temp      = {param + '_' + str(key): config_data[key]['step_size'][param] for param in config_data[key]['step_size']}
        step_size = {**step_size, **temp}
        
        fixed_parameters   += [param + '_' + str(key) for param in config_data[key]['fixed_parameters']]
        fixed_parameters   += [i     + '_' + str(key) for i     in core_models[key-1]['inputs']]
        
        scipy_args = config_data[key]['bh_args'] if 'bh_args' in config_data[key] else scipy_args
        
    sampler_args = {'data'               : {},
                    'guess'              : guess,
                    'models'             : models, 
                    'fixed_parameters'               : fixed_parameters,
                    'priors'             : priors,
                    'bounds'             : bounds,
                    'step_size'          : step_size,
                    'scipy_args'         : scipy_args,
                    'step_size_is_ratio' : False
                    }
        
    return sampler_args, config_data
예제 #3
0
def get_sensitivity_args(filename, user_core_models={}):
    '''Reads the config file and adds combines it with core_model data. If you are
    using a core model that is not in the database, you must provide the core_model
    using the core_models argument where the key is the system_type. Returns a 
    dictionary of keyword arguments and the config_data.
    
    :param filename: The name of the file to read
    :type filename: str
    :param user_core_model: A dictionary of core_models indexed by their system_type.
        core_models already in the database do not need to be specified here.
    :type user_core_model: dict, optional
    '''
    config_data, core_models = setup_helper(filename, from_config,
                                            user_core_models)
    models, params = compile_models(core_models, config_data)

    bounds = {}
    fixed_parameters = []

    for key in config_data:
        models[key]['init'] = config_data[key]['init']
        models[key]['tspan'] = config_data[key]['tspan']
        models[key]['int_args']['solver_args'] = config_data[key][
            'solver_args']

        temp = {
            param + '_' + str(key): config_data[key]['parameter_bounds'][param]
            for param in config_data[key]['parameter_bounds']
        }
        bounds = {**bounds, **temp}

        fixed_parameters += [
            param + '_' + str(key)
            for param in config_data[key]['fixed_parameters']
        ]

    sensitivity_args = {
        'models': models,
        'params': params,
        'parameter_bounds': bounds,
        'fixed_parameters': fixed_parameters,
        'analysis_type': 'sobol',
        'N': 1000
    }

    return sensitivity_args, config_data