leaspy.io.realizations.realization
.Realization
- class Realization(name: str, shape: Tuple[int, ...], variable_type: str)
Bases:
object
Contains the realization of a given parameter.
- Parameters
- namestr
Variable name
- shapetuple of int
Shape of variable (multiple dimensions allowed)
- variable_typestr
'individual'
or'population'
variable?
- Attributes
- namestr
Variable name
- shapetuple of int
Shape of variable (multiple dimensions allowed)
- variable_typestr
'individual'
or'population'
variable?- tensor_realizations
torch.Tensor
Actual realizations, whose shape is given by shape
Methods
from_tensor
(name, shape, variable_type, ...)Create realization from variable infos and torch tensor object
initialize
(n_individuals, model, *[, ...])Initialize realization from a given model.
Set autograd for tensor of realizations
set_tensor_realizations_element
(element, dim)Manually change the value (in-place) of tensor_realizations at dimension dim.
Unset autograd for tensor of realizations
- classmethod from_tensor(name: str, shape: Tuple[int, ...], variable_type: str, tensor_realization: FloatTensor)
Create realization from variable infos and torch tensor object
- Parameters
- namestr
Variable name
- shapetuple of int
Shape of variable (multiple dimensions allowed)
- variable_typestr
'individual'
or'population'
variable?- tensor_realization
torch.Tensor
Actual realizations, whose shape is given by shape
- Returns
- initialize(n_individuals: int, model: AbstractModel, *, individual_variable_init_at_mean: bool = False)
Initialize realization from a given model.
- Parameters
- n_individualsint > 0
Number of individuals
- model
AbstractModel
The model you want realizations for.
- individual_variable_init_at_meanbool (default False)
If True: individual variable will be initialized at its mean (from model parameters) Otherwise: individual variable will be a random draw from a Gaussian distribution with loc and scale parameter from model parameters.
- Raises
LeaspyModelInputError
if unknown variable type
- set_autograd()
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: torch.FloatTensor, dim: tuple[int, ...])
Manually change the value (in-place) of tensor_realizations at dimension dim.
- unset_autograd()
Unset autograd for tensor of realizations
TODO remove? only in legacy code
- Raises
ValueError
if inconsistent internal request
See also