macrostat.core.Model#

class macrostat.core.Model(parameters: ~macrostat.core.parameters.Parameters | dict | None = None, hyperparameters: dict | None = None, scenarios: ~macrostat.core.scenarios.Scenarios | dict = None, variables: ~macrostat.core.variables.Variables | dict = None, behavior: ~macrostat.core.behavior.Behavior = <class 'macrostat.core.behavior.Behavior'>, name: str = 'model', log_level: int = 20, log_file: str = 'macrostat_model.log')[source]#

Bases: object

A general class to represent a macroeconomic model.

This class provides a wrapper for users to write their underlying model behavior while maintaining a uniformly accessible interface.

parameters#

The parameters of the model.

Type:

macrostat.core.parameters.Parameters

scenarios#

The scenarios of the model.

Type:

macrostat.core.scenarios.Scenarios

variables#

The variables of the model.

Type:

macrostat.core.variables.Variables

behavior#

The behavior class of the model.

Type:

macrostat.core.behavior.Behavior

name#

The name of the model.

Type:

str

Example

A general workflow for a model might look like:

>>> model = Model()
>>> output = model.simulate()
>>> model.save()
__init__(parameters: ~macrostat.core.parameters.Parameters | dict | None = None, hyperparameters: dict | None = None, scenarios: ~macrostat.core.scenarios.Scenarios | dict = None, variables: ~macrostat.core.variables.Variables | dict = None, behavior: ~macrostat.core.behavior.Behavior = <class 'macrostat.core.behavior.Behavior'>, name: str = 'model', log_level: int = 20, log_file: str = 'macrostat_model.log')[source]#

Initialization of the model class.

Parameters:

Methods

__init__([parameters, hyperparameters, ...])

Initialization of the model class.

compute_theoretical_steady_state([scenario])

Compute the theoretical steady state of the model.

from_json(parameter_file, scenario_file, ...)

Initialize the model from a JSON file.

load(path)

Class method to load a model instance from a pickled file.

save(path)

Save the model object as a pickled file

simulate([scenario])

Simulate the model.

to_json(file_path, *args, **kwargs)

Convert the model to a JSON file split into parameters, scenarios, and variables.

compute_theoretical_steady_state(scenario: int | str = 0, *args, **kwargs)[source]#

Compute the theoretical steady state of the model.

This process generally follows the structure of the forward() function, but instead of simulating the model, the steady state is computed at each timestep. Therefore, (1) the model is initialized, and (2) for each timestep the parameter and scenario information is passed to the compute_theoretical_steady_state_per_step() function that computes the steady state at that timestep.

Parameters:

scenario (int (optional)) – The scenario to use for the model run, defaults to 0, which represents the default scenario (no shocks).

classmethod from_json(parameter_file: str, scenario_file: str, variable_file: str, *args, **kwargs)[source]#

Initialize the model from a JSON file.

classmethod load(path: PathLike)[source]#

Class method to load a model instance from a pickled file.

Parameters:

path (os.PathLike) – path to the targeted file containing the model.

Notes

Note

This implementation is dependent on your pickling version

save(path: PathLike)[source]#

Save the model object as a pickled file

Parameters:

path (os.PathLike) – path where the model will be stored. If it is None then the model’s name will be used and the file stored in the working directory.

Notes

Note

This implementation is dependent on your pickling version

simulate(scenario: int | str = 0, *args, **kwargs)[source]#

Simulate the model.

Parameters:

scenario (int (optional)) – The scenario to use for the model run, defaults to 0, which represents the default scenario (no shocks).

to_json(file_path: PathLike, *args, **kwargs)[source]#

Convert the model to a JSON file split into parameters, scenarios, and variables.

Parameters:

file_path (os.PathLike) – The path to the file to save the model to.