Variables#

This class is the base class for all variable classes. It contains the common methods for all variable classes.

Constructor#

Variables([variable_info, timeseries, ...])

Variables class for the MacroStat model.

Initialization and Loading#

Variables.from_json(file_path, *args, **kwargs)

Read the timeseries from a JSON file.

Variables.from_excel(file_path, *args, **kwargs)

Initialize the variables from an Excel file.

Variable Management#

Variables.get_stock_variables()

Get all the stock variables from the info dictionary.

Variables.get_flow_variables()

Get all the flow variables from the info dictionary.

Variables.get_index_variables()

Get all the index variables from the info dictionary.

Variables.initialize_tensors()

Initialize the output tensors, creating two different dictionaries.

Variables.new_state(**kwargs)

Initialize the state variables for the given period.

Variables.update_history(state)

Update the history variables for the given period.

Variables.record_state(t, state_vars)

Record the state variables for the given period.

Variables.verify_sfc_info()

Verify that the sfc information in the info dictionary is complete.

Accounting Functions#

Variables.balance_sheet_theoretical([...])

Calculate the theoretical balance sheet of the model based on the information in the info dictionary.

Variables.balance_sheet_actual()

Calculate the actual balance sheet of the model.

Variables.transaction_matrix_theoretical([...])

Calculate the theoretical transaction matrix of the model based on the information in the info dictionary.

Variables.transaction_matrix_actual()

Calculate the actual transaction matrix of the model.

Variables.compare(other)

Compare the variables to another Variables object or DataFrame.

Serialization / IO#

Variables.to_json(file_path)

Convert the parameters to a JSON file.

Variables.to_excel(file_path)

Convert the variables to an Excel file.

Variables.to_pandas()

Convert the variables to a pandas DataFrame.

Variables.info_to_csv(file_path[, sphinx_math])

Convert the variables information to a CSV file.

Notes#

The Variables class manages the variables of a MacroStat model, including the output tensors from simulations. It provides methods for handling variable characteristics (dimension, name, unit, description, notation) and includes accounting functions for balance sheets and transaction matrices.

Example#

A typical workflow for variables might look like:

>>> variables = Variables(parameters)
>>> variables.initialize_tensors()
>>> variables.record_state(0, {'x': torch.tensor([1.0])})
>>> variables.to_json('variables.json')