pysolvegn.build_affine_parametrization#

build_affine_parametrization(modes, offset=None, *, sparse=None)[source]#

Build a Parametrization based on an affine transformation.

The parametrization maps the optimized input parameters \(\mathbf{p}_{in}\) to the output parameters passed to the terms according to:

\[\mathbf{p}_{out} = M \mathbf{p}_{in} + \mathbf{p}_0\]

where \(M\) is the transformation matrix and \(\mathbf{p}_0\) is an optional offset.

The corresponding Jacobian is constant:

\[\mathbf{J}_P = \frac{\partial \mathbf{p}_{out}} {\partial \mathbf{p}_{in}} = M.\]
Parameters:
  • modes (Union[ArrayLike, scipy.sparse.spmatrix]) – The matrix of the affine transformation with shape (n_p_outputs, n_parameters), a dense array or a scipy.sparse matrix.

  • offset (Optional[ArrayLike], optional) – The offset of the affine transformation with shape (n_p_outputs,). If None, a zero offset is used.

  • sparse (Optional[bool], optional (default: None)) – If True, the Jacobian is a scipy.sparse.csr_matrix; if False, a dense numpy.ndarray. If None, the Jacobian has the format of modes (sparse for a scipy.sparse matrix, dense otherwise).

Returns:

A Parametrization implementing the affine transformation.

Return type:

Parametrization

Examples

A two-dimensional parameterization from one optimized parameter:

>>> parametrization = build_affine_parametrization(
...     modes=[[1.0], [2.0]],
...     offset=[0.0, 1.0],
... )

This defines:

\[\begin{split}\begin{bmatrix} p_{out,0} \\ p_{out,1} \end{bmatrix} = \begin{bmatrix} 1 \\ 2 \end{bmatrix} p_{in} + \begin{bmatrix} 0 \\ 1 \end{bmatrix}.\end{split}\]