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:
objectA 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.
- scenarios#
The scenarios of the model.
- variables#
The variables of the model.
- behavior#
The behavior class of the model.
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:
parameters (macrostat.core.parameters.Parameters | dict) – The parameters of the model.
hyperparameters (dict (optional)) – The hyperparameters of the model.
scenarios (macrostat.core.scenarios.Scenarios | dict (optional)) – The scenarios of the model.
variables (macrostat.core.variables.Variables | dict (optional)) – The variables of the model.
behavior (macrostat.core.behavior.Behavior (optional)) – The behavior of the model.
name (str (optional)) – The name of the model.
log_level (int (optional)) – The log level, defaults to logging.INFO but can be set to logging.DEBUG for more verbose output.
log_file (str (optional)) – The log file, defaults to “macrostat_model.log” in the current working directory.
Methods
__init__([parameters, hyperparameters, ...])Initialization of the model class.
compute_theoretical_steady_state([scenario])Compute the theoretical steady state of the model.
get_model_training_instance([scenario])Simulate the model.
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).
- get_model_training_instance(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).
- 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.