Simulator#

class Simulator(wrapper=None, data=None, parameters=None)[source]#

Bases: object

A Simulator class for a model in the CPM toolbox. It is designed to run a model for multiple participants and store the output in a format that can be used for further analysis.

Parameters:
wrapperWrapper

An initialised Wrapper object for the model.

datapandas.core.groupby.generic.DataFrameGroupBy or list of dictionaries

The data required for the simulation. If it is a pandas.core.groupby.generic.DataFrameGroupBy, as returned by pandas.DataFrame.groupby(), each group must contain the data (or environment) for a single participant. If it is a list of dictionaries, each dictionary must contain the data (or environment) for a single participant.

parametersParameters, pd.DataFrame, pd.Series or list

The parameters required for the simulation. It can be a Parameters object or a list of dictionaries whose length is equal to data. If it is a Parameters object, Simulator will use the same parameters for all simulations. It is a list of dictionaries, it will use match the parameters with data, so that for example parameters[6] will be used for the simulation of data[6].

Returns:
simulatorSimulator

A Simulator object.

run()[source]#

Runs the simulation.

Notes

Data is sorted according to the group IDs as ordered by pandas.

export(save=False, path=None)[source]#

Return the trial- and participant-level information about the simulation.

Parameters:
savebool

If True, the output will be saved to a file.

pathstr

The path to save the output to.

Returns:
pandas.DataFrame

A dataframe containing the the model output for each participant and trial. If the output variable is organised as an array with more than one dimension, the output will be flattened.

update(parameters=None)[source]#

Updates the parameters of the simulation.

generate(variable='dependent')[source]#

Generate data for parameter recovery, etc.

Parameters:
variable: str

Name of the variable to pull out from model output.

reset()[source]#

Resets the simulation.

save(filename=None)[source]#

Saves the simulation results.

Parameters:
filenamestr

The name of the file to save the results to.