pysdic.ComposedParametrization#

The pysdic.ComposedParametrization provides a standardized way to manage composed parametrizations, allowing for the combination of multiple parametrizations \([P_1, P_2, \dots, P_n]\) into a single parametrization \(P = P_n \circ \dots \circ P_1\).

The syntax P2 @ P1 is equivalent to ComposedParametrization([P1, P2]).

ComposedParametrization class#

class ComposedParametrization(parametrizations)[source]#

Bases: Parametrization

A composition of multiple pysdic.Parametrization instances.

This class allows you to compose multiple parametrizations together, where the output of one parametrization is fed as the input to the next. The resulting composition behaves like a single parametrization that encodes parameters through the sequence of parametrizations.

For example, if you have two parametrizations \(P_1\) and \(P_2\), you can create a composition \(P = P_2 \circ P_1\) such that:

\[P(\vec{p}) = P_2(P_1(\vec{p}))\]

where \(\vec{p}\) are the parameters to encode. The decoding map is applied in the reverse order:

\[P^{-1}(\vec{p}) = P_1^{-1}(P_2^{-1}(\vec{p}))\]

See also

  • Class pysdic.Parametrization for the base class of parametrizations.

  • The syntax P2 @ P1 which is equivalent to ComposedParametrization([P1, P2]).

Note

The number of parametrizations in the composition must be at least 1 and cannot be changed after initialization. In addition, the parametrizations stored in the composition cannot be changed after initialization.

Note

Locking the composition (by an owner of the package) also locks all its parametrizations, recursively for nested compositions.

Note

The capability flags of the composition are derived from the flags of the parametrizations: a flag is True only if it is True for all the parametrizations. For example, the composition is left invertible if all the parametrizations are left invertible, since:

\[P_1^{-1} \circ P_2^{-1} \circ P_2 \circ P_1 = P_1^{-1} \circ P_1 = \text{Id}\]
Parameters:

parametrizations (List[Parametrization]) – A list of parametrization instances to compose together. The output dimension of each parametrization must match the input dimension of the next. The order of the list is \([P_1, P_2, ..., P_n]\) where \(P_1\) is the first parametrization applied to the parameters.

Implemented methods and attributes#

The following sections provide an overview of the attributes and methods defined in the pysdic.ComposedParametrization class.

Attributes#

The pysdic.ComposedParametrization defines or redefines the following attributes:

ComposedParametrization.input_dim

[Get] the input dimension \(n_i\) of the composition, i.e. the input dimension of the first parametrization \(P_1\).

ComposedParametrization.n_parametrizations

[Get] the number of parametrizations in the composition.

ComposedParametrization.output_dim

[Get] the output dimension \(n_o\) of the composition, i.e. the output dimension of the last parametrization \(P_n\).

ComposedParametrization.parametrizations

[Get] the list of parametrizations that are composed together.

Methods#

The pysdic.ComposedParametrization implements the following backend methods to encode and decode the composed parametrization:

ComposedParametrization._encode(p_i, *[, ...])

Encode the parameters through the sequence of parametrizations.

ComposedParametrization._decode(p_o, *[, ...])

Decode the encoded parameters through the sequence of parametrizations in reverse.

Note

The encode and decode methods of the composition accept the additional argument kwargs: a list with one dictionary of keyword arguments per parametrization, in the order \([P_1, \dots, P_n]\) (the same order for decode, even if the decoding is applied in reverse).