macrostat.core.Parameters#

class macrostat.core.Parameters(parameters: dict | None = None, hyperparameters: dict | None = None, *args, **kwargs)[source]#

Bases: object

A class for handling parameters for the MacroStat model.

__init__(parameters: dict | None = None, hyperparameters: dict | None = None, *args, **kwargs)[source]#

Initialize the parameters for the model. If no parameters are provided, the default parameters will be used, and if only some parameters are provided, the missing parameters will be set to their default values.

Parameters:
  • parameters (dict | None) – The parameters to initialize the model with. If None, the default parameters will be used.

  • hyperparameters (dict | None) – The hyperparameters to initialize the model with. If None, the default hyperparameters will be used.

  • bounds (dict | None) – The bounds to initialize the model with. If None, the default bounds will be used

Methods

__init__([parameters, hyperparameters])

Initialize the parameters for the model.

from_csv(file_path, *args, **kwargs)

Initialize the parameters from a CSV file.

from_excel(file_path, *args, **kwargs)

Initialize the parameters from an Excel file.

from_json(file_path, *args, **kwargs)

Initialize the parameters from a JSON file.

get_bounds()

Return the bounds for the parameters.

get_default_hyperparameters()

Return the default hyperparameters.

get_default_parameters()

Return the default parameters.

get_values()

Return the values for the parameters.

is_equal(other)

Compare the parameters to another Parameters object.

set_bound(key, value)

Set the bounds for a single parameter

set_notation(key, value)

Set the notation for a single parameter.

set_unit(key, value)

Set the unit for a single parameter.

to_csv(file_path[, sphinx_math])

Convert the parameters to a CSV file.

to_excel(file_path, *args, **kwargs)

Convert the parameters to an Excel file.

to_json(file_path, *args, **kwargs)

Convert the parameters to a JSON file.

to_nn_parameters()

Convert the parameters to a nn.ParameterDict.

vectorize_parameters()

Vectorize the parameters.

verify_bounds()

Verify that the bounds are valid.

verify_parameters()

Verify that the parameters are within the bounds.

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

Initialize the parameters from a CSV file.

Parameters:

file_path (os.PathLike) – The path to the CSV file to load the parameters from.

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

Initialize the parameters from an Excel file.

Parameters:

file_path (os.PathLike) – The path to the Excel file to load the parameters from.

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

Initialize the parameters from a JSON file.

Parameters:

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

get_bounds()[source]#

Return the bounds for the parameters.

get_default_hyperparameters()[source]#

Return the default hyperparameters.

The hyperparameters are the parameters that are not directly used in the model, but rather for the simulation and calibration. They must include: 1. The number of timesteps to simulate 2. The scenario trigger, i.e. the timestep at which the scenario starts 3. The seed for the random number generator 4. The device to use for the simulation 5. May include other parameters, such as flags for the model

get_default_parameters()[source]#

Return the default parameters.

Should return a dictionary with the keys being the parameter names, and a subdictionary with the keys including: - “Value”: The value of the parameter. - “Lower”: The lower bound of the parameter. - “Upper”: The upper bound of the parameter. - “Unit”: The unit of the parameter. - “Notation”: The notation of the parameter.

get_values()[source]#

Return the values for the parameters.

is_equal(other: Parameters)[source]#

Compare the parameters to another Parameters object.

set_bound(key: str, value: tuple)[source]#

Set the bounds for a single parameter

Parameters:
  • key (str) – The key of the parameter to set the bounds for.

  • value (tuple) – The bounds to set for the parameter.

set_notation(key: str, value: str)[source]#

Set the notation for a single parameter.

set_unit(key: str, value: str)[source]#

Set the unit for a single parameter.

to_csv(file_path: PathLike, sphinx_math: bool = False)[source]#

Convert the parameters to a CSV file.

Parameters:
  • file_path (os.PathLike) – The path to the CSV file to save the parameters to.

  • sphinx_math (bool) – Whether to use Sphinx math notation in the CSV file.

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

Convert the parameters to an Excel file.

Parameters:

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

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

Convert the parameters to a JSON file.

Parameters:

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

to_nn_parameters()[source]#

Convert the parameters to a nn.ParameterDict.

vectorize_parameters()[source]#

Vectorize the parameters.

This function generates vectors out of the list of individual parameters. It does so by respecting the “vector_sectors” hyperparameter. If this hyperparameter exists, then:

1. for each parameter of the form “sector.name” a vector of zeros of size (len(vector_sectors),1) will be generated and populated with the values of the sector. The sectors index is computed as the index of the sector name in the sorted vector_sectors list. 2. for each parameter of the form “rowsec.colsec.name” a matrix of zeros of size (len(vector_sectors),len(vector_sectors)) will be generated and populated with the values of the sector. The sectors index is computed as the index of the sector name in the sorted vector_sectors list. The first sector is the row, the second the column of the matrix to be populated

verify_bounds()[source]#

Verify that the bounds are valid. By testing first that all parameters have bounds, and then that the bounds are valid.

verify_parameters()[source]#

Verify that the parameters are within the bounds.