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.
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.
- 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.