leaspy.io.realizations
.IndividualRealization
- class IndividualRealization(name: str, shape: Tuple[int, ...], *, n_individuals: int, **kwargs)
Bases:
AbstractRealization
Class for realizations of individual variables.
- Parameters:
- nameParamType
The name of the variable associated with the realization.
- shapeTuple[int, …]
The shape of the tensor realization.
- n_individualsint
The number of individuals related to this realization.
- **kwargsdict
Additional parameters (including tensor and tensor_copy).
- Attributes:
- tensor
Methods
initialize
(model, *[, init_at_mean])Initialize the realization from a model instance.
initialize_around_mean
(mean, std)Initialize the realization around the provided mean value.
initialize_at_mean
(mean)Initialize the realization at provided mean value.
Set autograd for tensor of realizations.
set_tensor_realizations_element
(element, dim)Manually change the value (in-place) of tensor_realizations at dimension dim.
to_dict
()Return a serialized dictionary of realization attributes.
Unset autograd for tensor of realizations
- initialize(model: AbstractModel, *, init_at_mean: bool = False, **kwargs: KwargsType)
Initialize the realization from a model instance.
- Parameters:
- modelAbstractModel
The model from which to initialize the realization.
- init_at_meanbool, optional
If True, the realization is initialized at the corresponding variable mean value, otherwise it the initial value is sampled around its mean value with a normal distribution.
- **kwargsKwargsType
Additional parameters for initialization.
- initialize_around_mean(mean: Tensor, std: Tensor) None
Initialize the realization around the provided mean value.
The initial value is sampled according to a normal distribution with provided mean and std parameters.
- Parameters:
- meantorch.Tensor
Mean value around which to sample the initial value.
- stdtorch.Tensor
Standard deviation for the normal distribution used to sample the initial value.
- initialize_at_mean(mean: Tensor) None
Initialize the realization at provided mean value.
- Parameters:
- meantorch.Tensor
The mean at which to initialize the realization.
- set_autograd() None
Set autograd for tensor of realizations.
TODO remove? only in legacy code
- Raises:
ValueError
if inconsistent internal request
See also
- set_tensor_realizations_element(element: Tensor, dim: tuple[int, ...]) None
Manually change the value (in-place) of tensor_realizations at dimension dim.
- Parameters:
- elementtorch.Tensor
The element to put in the tensor realization.
- dimTuple[int, …]
The dimension where to put the element.
- to_dict()
Return a serialized dictionary of realization attributes.
- unset_autograd() None
Unset autograd for tensor of realizations
TODO remove? only in legacy code
- Raises:
ValueError
if inconsistent internal request
See also