Estimation

This module wraps the call to PyDream. It unpacks parameter lists and generates the likelihood function.

DREAM_vp_parallel provides paralellization running multiple PyDream instances next to each other using one Python call. The parallelization over subjects can be done either via this function or separated into different Python calls.

The main interface function of interest is dream_estim_and_save.

scenewalk.estimation.DREAM_param_estimation.dream_estim_and_save(sw_model, priors, default_params, x_dat, y_dat, dur_dat, im_dat, densities_dat, num_processes_subjs, num_processes_trials, nchains, niter, vp_nr=None, destin_dir=None, model_name=None)

Run and Save dream chains Saves PyDream.

Parameters
sw_modelscenewalk model object

scenewalk model object

priorsdict

dictionary of priors of the to be estimated parameters

default_paramsdict

dictionary where the keys are all the parameters the model needs and to be estimated ones are None

x_dat, y_dat, dur_dat, im_datarrays

data of shape subject[trial[path[]]]

densities_datarray

empirical densities

num_processes_subjsint

number of cores to parallelize the model evaluation over on subj basis number of subjects in one “dream”

num_processes_trialsint

number of cores to parallelize the model evaluation over on trial basis

nchainsint

number of PyDream chains to run

niterint

number of PyDream iterations

vp_nrint

id number of vp, for filename when running multiple estims

destin_dirstr

directory where to save the chains

model_namestr

additional name to add to the estimation id

Example Estimation Script

An example estimation project can be found under demo/estimation_pydream. The dream_estim.ipynb shows how to populate the arguments, priors and defaults. The run_dream.py file shows how to call the estimation module.

Full Estimation Doc

Dream Interface for Scenewalk Model

Lisa Schwetlick 2019

University of Potsdam

scenewalk.estimation.DREAM_param_estimation.dream_estim_and_save(sw_model, priors, default_params, x_dat, y_dat, dur_dat, im_dat, densities_dat, num_processes_subjs, num_processes_trials, nchains, niter, vp_nr=None, destin_dir=None, model_name=None)

Run and Save dream chains Saves PyDream.

Parameters
sw_modelscenewalk model object

scenewalk model object

priorsdict

dictionary of priors of the to be estimated parameters

default_paramsdict

dictionary where the keys are all the parameters the model needs and to be estimated ones are None

x_dat, y_dat, dur_dat, im_datarrays

data of shape subject[trial[path[]]]

densities_datarray

empirical densities

num_processes_subjsint

number of cores to parallelize the model evaluation over on subj basis number of subjects in one “dream”

num_processes_trialsint

number of cores to parallelize the model evaluation over on trial basis

nchainsint

number of PyDream chains to run

niterint

number of PyDream iterations

vp_nrint

id number of vp, for filename when running multiple estims

destin_dirstr

directory where to save the chains

model_namestr

additional name to add to the estimation id

class scenewalk.estimation.DREAM_param_estimation.generate_custom_likelihood_function(sw_model, params, default_params, x_dat, y_dat, dur_dat, im_dat, densities_dat, num_processes_subjs, num_processes_trials)

generates a custom log likelihood function with the given setup … wrapper, because pydream log likelihood function only works with one argument (the parvals) This needs to be a class because a fucntion that returns a function can’t be pickled, and pickling is necessary for the paralellization.

Parameters
sw_modelscenewalk model object

scenewalk model object

paramsdict

dictionary of to be estimated parameters

default_paramsdict

dictionary where the keys are all the parameters the model needs and to be estimated ones are None

x_dat, y_dat, dur_dat, im_datarrays

data of shape subject[trial[path[]]]

densities_datarray

empirical densities

num_processesint

number of cores to parallelize the model evaluation over

Methods

custom_loglik(self, parvals)

evaluate scenewalk

custom_loglik(self, parvals)

evaluate scenewalk

Parameters
parvalslist

parameter values for the model

Returns
float

Likelihood value

scenewalk.estimation.DREAM_param_estimation.main()

Dream commandline interface

scenewalk.estimation.DREAM_param_estimation.param_list_from_estim_and_default(priors, default_params, parvals)

Turns a list of just the etsimated params into a list of all params including the defaults.

Parameters
priorsdict

dictionary of priors

default_paramsdict

dictionary where the keys are all the parameters the model needs and to be estimated ones are None

parvalslist

list of estimated params

Returns
list

list of all the params the model needs, including defaults and estimated

scenewalk.estimation.DREAM_param_estimation.trpd(my_mean, my_std, lb, ub)

Truncated normal prior distribution bounded between lb and ub with a sd of (ub-lb)/2 and a mean at the centre of the range

Parameters
my_meanfloat

mean value of the truncated gaussian

my_stdfloat

standard deviation of the truncated gaussian

lbfloat

lower bound of the truncated gaussian

ubfloat

upper bound of the truncated gaussian

Returns
pydream prior
scenewalk.estimation.DREAM_param_estimation.trunc_unif(lb, ub)

make uniform prior

Parameters
lbfloat

lower bound of the uniform prior

ubfloat

upper bound of the uniform prior

Returns
  • pydream prior

Parallel Dream Interface for Scenewalk Model

Lisa Schwetlick 2019

University of Potsdam

scenewalk.estimation.DREAM_vp_parallel.do_multiprocess(function_args, num_processes)

Opens pool of workers for parallelization

Parameters
function_argslist

list of args to pass to Estimation

num_processesint

how many pararell processes we want to run.

Returns
bool

True if sucess

scenewalk.estimation.DREAM_vp_parallel.dream_and_save_parallel(sw_model, priors, default_params, x_dat, y_dat, dur_dat, im_dat, densities_dat, nchains, niter, vp_list, num_processes_dreams, num_processes_subjs, num_processes_trials)

Run multiple pydream jobs for individual subjects.

Parameters
sw_modelscenewalk model object

scenewalk model object

priorsdict

dictionary of priors of the to be estimated parameters

default_paramsdict

dictionary where the keys are all the parameters the model needs and to be estimated ones are None

x_dat, y_dat, dur_dat, im_datarrays

data of shape subject[trial[path[]]]

densities_datarray

empirical densities

nchainsint

number of PyDream chains to run

niterint

number of PyDream iterations

vp_listlist

list of id numbers of subjects

num_processes_dreamsint

number of dreams to run

num_processes_subjsint

(only use when not estimating subjs individually) number of processes per subject

num_processes_trialsint

number of parallel threads per subject

scenewalk.estimation.DREAM_vp_parallel.multi_process_like(args)

unpack args into multi-process function