macrostat.core.Scenarios#
- class macrostat.core.Scenarios(parameters: Parameters, scenarios: dict | None = None, scenario_info: dict | None = None, calibration_variables: list[str] | None = None)[source]#
Bases:
objectScenarios class for the MacroStat model.
The aim of this class is to provide a uniform interface for handling scenarios, in particular for exogeneous shocks (e.g. also for the case where the shocks are calibrated to fit the data, such as using productivity shocks to fit the trajectory of GDP). It also contains user-specified scenarios such as exogenous supply shocks or the like.
- __init__(parameters: Parameters, scenarios: dict | None = None, scenario_info: dict | None = None, calibration_variables: list[str] | None = None)[source]#
Initialize the scenarios for the model.
If no scenarios are provided, the default scenarios will be used.
- Parameters:
parameters (Parameters) – The parameters of the model. These are necessary to create the default scenarios.
scenarios (dict | None) – The scenarios to initialize the model with. If None, the default scenarios will be used. Scenarios should be a str:dict (name:timeseries) dictionary.
scenario_info (dict | None) – The colors to use for the scenario variables. If None, the default colors will be used.
calibration_variables (list[str] | None) – The scenario variables that can be used in the calibration. If None, calibration will be based on the LabourProductivityGeneral, ProductivityShockGeneral, and ProductionLossGeneral scenario variables.
Methods
__init__(parameters[, scenarios, ...])Initialize the scenarios for the model.
add_scenario(timeseries[, name, colour])Add a scenario to the model.
from_excel(excel_path, parameters)Initialize the scenarios from an Excel file.
from_json(json_path, parameters)Initialize the scenarios from a JSON file.
Return the default scenario variable in vectorized form.
Return the default scenario values.
get_scenario_index(scenario)Get the index of a scenario by name.
to_excel(excel_path)Save the scenarios to an Excel file.
to_json(json_path)Save the scenarios to a JSON file.
to_nn_parameters([scenario])Convert the scenarios to a PyTorch ParameterDict.
vectorize_scenarios(timeseries)User-defined vectorization operations on the scenario timeseries.
Verify that the scenario info is consistent: 1.
- add_scenario(timeseries: dict, name: str = None, colour: str = None)[source]#
Add a scenario to the model.
- classmethod from_excel(excel_path: str, parameters: Parameters)[source]#
Initialize the scenarios from an Excel file.
- Parameters:
excel_path (str) – The path to the Excel file containing the scenarios.
parameters (Parameters) – The parameters of the model. These are necessary to create the default scenarios.
- classmethod from_json(json_path: str, parameters: Parameters)[source]#
Initialize the scenarios from a JSON file.
- Parameters:
json_path (str) – The path to the JSON file containing the scenarios.
parameters (Parameters) – The parameters of the model. These are necessary to create the default scenarios.
- get_default_scenario_values() dict[source]#
Return the default scenario values.
This function returns a dictionary of the scenario values with their default values.
- to_excel(excel_path: str)[source]#
Save the scenarios to an Excel file.
- Parameters:
excel_path (str) – The path to the Excel file to save the scenarios to.
- to_json(json_path: str)[source]#
Save the scenarios to a JSON file.
- Parameters:
json_path (str) – The path to the JSON file to save the scenarios to.
- to_nn_parameters(scenario: int = 0)[source]#
Convert the scenarios to a PyTorch ParameterDict.
- Parameters:
scenario (int) – The scenario to convert to PyTorch parameters.
- vectorize_scenarios(timeseries: dict)[source]#
User-defined vectorization operations on the scenario timeseries.
By default, scenarios are defined as single-column vectors where the rows (dim 0) matches the number of timesteps and the column is the scenario variable or paramter. However, for users with vectorized implementations, one can modify this function to create vectors of shape TxK as needed