leaspy.models.stateful¶
Classes¶
Stateful models have an internal |
Module Contents¶
- class StatefulModel(name, **kwargs)[source]¶
Bases:
leaspy.models.base.BaseModelStateful models have an internal
Stateto handle parameters and variables.- Parameters:
- name
str The name of the model.
- name
- Attributes:
- state
State The internal state of the model, which contains the variables and their values.
- tracked_variables
set[str] Set of variable names that are tracked by the model. These variables are not necessarily part of the model’s state but are monitored for changes or updates. This can include variables that are relevant for the model’s operation but not directly stored in the state.
- state
- Parameters:
name (str)
- track_variable(variable)[source]¶
Track a variable by its name.
Parameters¶
- variable
VariableName The name of the variable to track. This variable will be monitored for changes or updates.
- Parameters:
variable (VariableName)
- Return type:
None
- variable
- track_variables(variables)[source]¶
Track multiple variables by their names.
- Parameters:
- variables
Iterable[VariableName] An iterable containing the names of the variables to track. Each variable will be monitored for changes or updates.
- variables
- Parameters:
variables (Iterable[VariableName])
- Return type:
None
- untrack_variable(variable)[source]¶
Untrack a variable by its name.
Parameters¶
- variable
VariableName The name of the variable to untrack. This variable will no longer be monitored for changes or updates.
- Parameters:
variable (VariableName)
- Return type:
None
- variable
- untrack_variables(variables)[source]¶
Untrack multiple variables by their names.
- Parameters:
- variables
Iterable[VariableName] An iterable containing the names of the variables to untrack. Each variable will no longer be monitored for changes or updates.
- variables
- Parameters:
variables (Iterable[VariableName])
- Return type:
None
- property state: State¶
Get the internal state of the model.
- Returns:
- State
State The internal state of the model, which contains the variables and their values.
- State
- Raises:
LeaspyModelInputErrorIf the model’s state is not initialized yet.
- Return type:
- property dag: VariablesDAG¶
Get the underlying DAG of the model’s state.
- Returns:
- :
VariablesDAG The directed acyclic graph (DAG) representing the model’s variables and their relationships
- :
- Return type:
- property hyperparameters_names: tuple[VariableName, Ellipsis]¶
Get the names of the model’s hyperparameters.
- Returns:
- :
tuple[VariableName, others…] A tuple containing the names of the model’s hyperparameters.
- :
- Return type:
tuple[VariableName, Ellipsis]
- property parameters_names: tuple[VariableName, Ellipsis]¶
Get the names of the model’s parameters.
- Returns:
- :
tuple[VariableName, others…] A tuple containing the names of the model’s parameters.
- :
- Return type:
tuple[VariableName, Ellipsis]
- property population_variables_names: tuple[VariableName, Ellipsis]¶
Get the names of the population latent variables.
- Returns:
- :
tuple[VariableName, …] A tuple containing the names of the population latent variables.
- :
- Return type:
tuple[VariableName, Ellipsis]
- property individual_variables_names: tuple[VariableName, Ellipsis]¶
Get the names of the individual latent variables.
- Returns:
- :
tuple[VariableName, …] A tuple containing the names of the individual latent variables.
- :
- Return type:
tuple[VariableName, Ellipsis]
- property parameters: DictParamsTorch¶
Dictionary of values for model parameters.
- Returns:
- :
DictParamsTorch A dictionary mapping parameter names to their values (as tensors).
- :
- Return type:
- property hyperparameters: DictParamsTorch¶
Dictionary of values for model hyperparameters.
- Returns:
- :
DictParamsTorch A dictionary mapping hyperparameter names to their values (as tensors).
- :
- Return type:
- initialize(dataset=None)[source]¶
Overloads base model initialization (in particular to handle internal model State).
<!> We do not put data variables in internal model state at this stage (done in algorithm)
- load_parameters(parameters)[source]¶
Instantiate or update the model’s parameters.
It assumes that all model hyperparameters are defined.
- Parameters:
- parameters
KwargsType] Contains the model’s parameters.
- parameters
- Parameters:
parameters (KwargsType)
- Return type:
None
- abstractmethod get_variables_specs()[source]¶
Return the specifications of the variables (latent variables, derived variables, model ‘parameters’) that are part of the model.
- Returns:
- NamedVariables
NamedVariables The specifications of the model’s variables.
- NamedVariables
- Return type:
- move_to_device(device)[source]¶
Move a model and its relevant attributes to the specified
torch.device.- Parameters:
- device
torch.device The device to which the model and its attributes should be moved.
- device
- Parameters:
device (device)
- Return type:
None