respyabc¶
This module contains the main function respyabc.respyabc()
of the package. All other modules are mainly created to support this
function.
-
respyabc.respyabc.convert_dict_to_pyabc_distribution(parameters)[source]¶ Turn a dictionary including the prior distributions to a string with the code of the pyABCdistribution.
- Parameters
parameters (dict) – A dictionary contaning the parameters as keys and the corresponding distribution parameters in a tuple as values.
- Returns
output_string – string with the code of the pyABC.Distribution.
- Return type
str
-
respyabc.respyabc.get_abc_object_inference(distance_abc, population_size_abc, sampler, parameters_prior, model, model_to_simulate, params, options, descriptives, norm='norm', uniform='uniform')[source]¶ Returns abc object for inference.
- Parameters
distance_abc (function) – A function that takes two model specifications as inputs and computes the difference between the summary statistics of the two model outcomes.
population_size_abc (int) – Positive integer determining the number of particles to be drawn per population during the abc algorithm.
sampler (pyabc.sampler.function) – A function from the pyabc.sampler class.
parameters_prior (dictionary) – A dictionary contaning the parameters as keys and the corresponding distribution parameters in a tuple as values.
model (function) – A model as defined by
model.model_to_simulate (object produced by) –
respyabc.get_simulate_func_options()Model that specififes the respy set-up.params (pandas.DataFrame) – Parameter that specify the respy model.
options (pandas.DataFrame) – Options that specify the respy model.
descriptives ({"choice_frequencies", "wage_moments"}) – Determines how the descriptives with which the distance is computed are computed.
norm (str, optional) – Name of the normal distribution. Must be set for the eval comment. Currently only
"norm"is supported.uniform (str,) – Name of the uniform distribution. Must be set for the eval comment. Currently only
"uniform"is supported.
- Returns
history – An object containing the history of the abc-run.
- Return type
pyabc.object
-
respyabc.respyabc.get_abc_object_model_selection(distance_abc, population_size_abc, sampler, parameters_prior, model, model_to_simulate, params, options, descriptives, norm='norm', uniform='uniform')[source]¶ Returns abc object for model selection.
- Parameters
distance_abc (function) – A function that takes two model specifications as inputs and computes the difference between the summary statistics of the two model outcomes.
population_size_abc (int) – Positive integer determining the number of particles to be drawn per population during the abc algorithm.
sampler (pyabc.sampler.function) – A function from the pyabc.sampler class.
parameters_prior (dictionary) – A dictionary contaning the parameters as keys and the corresponding distribution parameters in a tuple as values.
model (function) – A model as defined by
models.compute_model().model_to_simulate (object produced by) –
respyabc.get_simulate_func_options()Model that specififes the respy set-up.params (pandas.DataFrame) – Parameter that specify the respy model.
options (pandas.DataFrame) – Options that specify the respy model.
descriptives ({"choice_frequencies", "wage_moments"}) – Determines how the descriptives with which the distance is computed are computed.
norm (str, optional) – Name of the normal distribution. Must be set for the eval comment. Currently only
"norm"is supported.uniform (str,) – Name of the uniform distribution. Must be set for the eval comment. Currently only
"uniform"is supported.
- Returns
history – An object containing the history of the abc-run.
- Return type
pyabc.object
-
respyabc.respyabc.get_simulate_func_options(params, options, method='n_step_ahead_with_sampling', df=None, n_simulation_periods=None)[source]¶ Rewrite respy’s get_simulation_function such that options can be passed and therefore the seed be changed before any run. Documentation is adapted from
respy.simulate.get_simulate_func()- Parameters
params (pandas.DataFrame) – DataFrame containing the model parameters.
options (dict) – Dictionary containing the model options.
method ({"n_step_ahead_with_sampling", "n_step_ahead_with_data", "one_step_ahead"}) – The simulation method which can be one of three and is explained in more detail in
respy.simulate.simulate().df (pandas.DataFrame or None, default None) – DataFrame containing one or multiple observations per individual.
n_simulation_periods (int or None, default None) – Simulate data for a number of periods. This options does not affect
options["n_periods"]which controls the number of periods for which decision rules are computed.
- Returns
simulate_function – Simulation function where all arguments except the parameter vector and the options are set.
- Return type
simulate()
-
respyabc.respyabc.respyabc(model, parameters_prior, data, distance_abc=<function compute_mean_squared_distance>, descriptives='choice_frequencies', sampler=<pyabc.sampler.multicore_evaluation_parallel.MulticoreEvalParallelSampler object>, population_size_abc=500, max_nr_populations_abc=10, minimum_epsilon_abc=0.05, database_path_abc=None, numb_individuals_respy=1000, numb_periods_respy=40, model_selection=False)[source]¶ Compute K&W 1994 model using pyabc. Workhorse of this project. Most other functions are used to support this function.
- Parameters
model (function) – A model as defined by
models.compute_model().parameters_prior (dictionary) – A dictionary contaning the parameters as keys and the corresponding distribution parameters in a tuple as values.
data (numpy.array) – Numeric array of shape (
numb_individuals_respy,number of choices).distance_abc (function) – A function that takes two model specifications as inputs and computes the difference between the summary statistics of the two model outcomes.
descriptives ({"choice_frequencies", "wage_moments"}) – Determines how the descriptives with which the distance is computed are computed. The default is
"choice_frequencies".sampler (pyabc.sampler.function, optional) – A function from the pyabc.sampler class.
population_size_abc (int, optional) – Positive integer determining the number of particles to be drawn per population during the abc algorithm.
max_nr_populations_abc (int, optional) – Positive integer determining the number of populations that are drawn for the abc algorithm.
minimum_epsilon_abc (float, optional) – Positive float determining the epsilon for the last population run of the abc algorithm.
database_path_abc (str, optional) – Path where the abc runs are stored. If
Noneis supplied, runs are saved in the local temp folder.numb_individuals_respy (int, optional) – Number of simulated independent individuals in the discrete choice model.
numb_periods_respy (int, optional) – Length of the decision horizon in the discrete choice model.
model_selection (bool, optional) – If
True, the function expects a model selection procedure, if False single inference is conducted.
- Returns
history – An object of class pyabc.smc containing all the information of the
abc.run.- Return type
pyabc.smc