pysdic.ComposedTransformation#

The pysdic.ComposedTransformation provides a standardized way to manage composed transformations, allowing for the combination of multiple transformations \([T_1, T_2, \dots, T_n]\) into a single transformation \(T = T_n \circ \dots \circ T_1\).

The parameters of the composition are the concatenation of the parameters of the transformations, in the order of the composition. The syntax T2 @ T1 is equivalent to ComposedTransformation([T1, T2]).

ComposedTransformation class#

class ComposedTransformation(*args, **kwargs)[source]#

Bases: Transformation

A composition of multiple pysdic.Transformation instances.

This class allows you to compose multiple transformations together, where the output of one transformation is fed as the input to the next. The resulting composition behaves like a single transformation that applies the sequence of transformations.

For example, if you have two transformations \(T_1\) and \(T_2\), you can create a composition \(T = T_2 \circ T_1\) such that:

\[T(\vec{x_i}; \vec{p}) = T_2(T_1(\vec{x_i}; \vec{p}_1); \vec{p}_2)\]

where \(\vec{x_i}\) are the input points to the composition, which are first transformed by \(T_1\) and then by \(T_2\) to produce the final output points. The inverse map is applied in the reverse order:

\[T^{-1}(\vec{x_o}; \vec{p}) = T_1^{-1}(T_2^{-1}(\vec{x_o}; \vec{p}_2); \vec{p}_1)\]

The parameters of the composition are the concatenation of the parameters of the transformations, in the order of the composition:

\[\vec{p} = \begin{bmatrix} \vec{p}_1 & \vec{p}_2 & \dots & \vec{p}_n \end{bmatrix}\]

See also

  • Class pysdic.Transformation for the base class of transformations.

  • The syntax T2 @ T1 which is equivalent to ComposedTransformation([T1, T2]).

Note

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

Note

Locking the composition (by an owner of the package) also locks all its transformations. The parameters of the composition cannot be set if the composition or one of its transformations is locked (unless override_lock=True).

Note

The composition does not store its own parameters: getting the parameters of the composition reads the parameters of the transformations, and setting them splits the array and sets the parameters of each transformation. The transformations are not copied, so modifying the parameters of a transformation also modifies the parameters of the composition.

Note

The capability flags of the composition are derived from the flags of the transformations: a flag is True only if it is True for all the transformations. In addition, the Jacobian with respect to the parameters of a transformation must be propagated through the transformations applied after it, so:

  • has_apply_dp also requires has_apply_dx for \(T_2, \dots, T_n\).

  • has_invert_dp also requires has_invert_dx for \(T_1, \dots, T_{n-1}\).

Parameters:
  • transformations (List[Transformation]) – A list of transformation instances to compose together. The output dimension of each transformation must match the input dimension of the next. The order of the list is \([T_1, T_2, ..., T_n]\) where \(T_1\) is the first transformation applied to the input points and \(T_n\) is the last transformation that produces the final output points.

  • parameters (Optional[ArrayLike], optional (default: None)) – A 1D array of shape \((n_p,)\) with \(n_p = \sum_k n_{p,k}\) to set the parameters of all the transformations. If None, the current parameters of the transformations are kept.

Implemented methods and attributes#

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

Attributes#

The pysdic.ComposedTransformation defines or redefines the following attributes:

ComposedTransformation.input_dim

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

ComposedTransformation.n_parameters

[Get] the number of parameters \(n_p\) of the composition, i.e. the sum of the number of parameters of the transformations.

ComposedTransformation.n_transformations

[Get] the number of transformations in the composition.

ComposedTransformation.output_dim

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

ComposedTransformation.parameters

[Get] or [Set] the parameters of the composition.

ComposedTransformation.transformations

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

Methods#

The pysdic.ComposedTransformation redefines the following method to split the parameters between the transformations:

ComposedTransformation.set_parameters(value, *)

Set the parameters of the composition, with an option to override the lock.

The pysdic.ComposedTransformation implements the following backend methods to apply and invert the composed transformation:

ComposedTransformation._apply(x_i, *[, dx, ...])

Apply the composition of transformations to the input points \(\vec{x_i}\) to produce the output points \(\vec{x_o}\).

ComposedTransformation._invert(x_o, *[, dx, ...])

Apply the inverse of the composition of transformations to the output points \(\vec{x_o}\) to produce the input points \(\vec{x_i}\).

Note

The apply and invert methods of the composition accept the additional arguments kwargs (a list with one dictionary of keyword arguments per transformation, in the order \([T_1, \dots, T_n]\)) and bypass_dp (a sequence of booleans to skip the Jacobian with respect to the parameters of some transformations, whose columns are filled with NaN).