# TransportMaps.L2.L2_distance¶

## Module Contents¶

### Functions¶

 misfit_squared(f1, f2, x[, params1, params2, idxs_slice]) Compute $$\vert f_1 - f_2 \vert^2$$ grad_a_misfit_squared(f1, f2, x[, params1, params2, ...]) Compute $$\nabla_{\bf a}\vert f_{1,{\bf a}} - f_2 \vert^2$$ hess_a_misfit_squared(f1, f2, x[, params1, params2, ...]) Compute $$\nabla^2_{\bf a}\vert f_{1,{\bf a}} - f_2 \vert^2$$ L2_misfit(*args, **kwargs) Compute $$\Vert f_1 - f_2 \Vert_{L^2_\pi}$$ L2squared_misfit(f1, f2[, d, params1, params2, qtype, ...]) Compute $$\Vert f_1 - f_2 \Vert^2_{L^2_\pi}$$ grad_a_L2squared_misfit(f1, f2[, d, params1, params2, ...]) Compute $$\nabla_{\bf a}\Vert f_{1,{\bf a}} - f_2 \Vert^2_{L^2_\pi}$$ hess_a_L2squared_misfit(f1, f2[, d, params1, params2, ...]) Compute $$\nabla^2_{\bf a}\Vert f_{1,{\bf a}} - f_2 \Vert^2_{L^2_\pi}$$ storage_hess_a_L2squared_misfit(f1, f2[, d, params1, ...]) Assemble $$\nabla^2_{\bf a}\Vert f_{1,{\bf a}} - f_2 \Vert^2_{L^2_\pi}$$. Evaluate the action of $$\nabla^2_{\bf a}\Vert f_{1,{\bf a}} - f_2 \Vert^2_{L^2_\pi}$$ on $$v$$.
TransportMaps.L2.L2_distance.misfit_squared(f1, f2, x, params1=None, params2=None, idxs_slice=None)[source]

Compute $$\vert f_1 - f_2 \vert^2$$

Parameters:
• f1 (Function or ndarray [$$m$$]) – function $$f_1$$ or its functions values

• f2 (Function or ndarray [$$m$$]) – function $$f_2$$ or its functions values

• x (ndarray [$$m,d$$]) – quadrature points used for the approximation of $$\mathbb{E}_{\pi}$$

• params1 (dict) – parameters for function $$f_1$$

• params2 (dict) – parameters for function $$f_2$$

• idxs_slice (slice) – slice of points to be

Returns:

(ndarray) – misfit $$\vert f_1 - f_2 \vert^2$$

TransportMaps.L2.L2_distance.grad_a_misfit_squared(f1, f2, x, params1=None, params2=None, idxs_slice=None)[source]

Compute $$\nabla_{\bf a}\vert f_{1,{\bf a}} - f_2 \vert^2$$

Parameters:
• f1 (Function or ndarray [$$m$$]) – function $$f_1$$ or its functions values

• f2 (Function or ndarray [$$m$$]) – function $$f_2$$ or its functions values

• x (ndarray [$$m,d$$]) – quadrature points used for the approximation of $$\mathbb{E}_{\pi}$$

• params1 (dict) – parameters for function $$f_1$$

• params2 (dict) – parameters for function $$f_2$$

• idxs_slice (slice) – slice of points to be

Returns:

(ndarray) – misfit

$$\nabla_{\bf a}\vert f_{1,{\bf a}} - f_2 \vert^2$$

TransportMaps.L2.L2_distance.hess_a_misfit_squared(f1, f2, x, params1=None, params2=None, idxs_slice=None)[source]

Compute $$\nabla^2_{\bf a}\vert f_{1,{\bf a}} - f_2 \vert^2$$

Parameters:
• f1 (Function or ndarray [$$m$$]) – function $$f_1$$ or its functions values

• f2 (Function or ndarray [$$m$$]) – function $$f_2$$ or its functions values

• x (ndarray [$$m,d$$]) – quadrature points used for the approximation of $$\mathbb{E}_{\pi}$$

• params1 (dict) – parameters for function $$f_1$$

• params2 (dict) – parameters for function $$f_2$$

• idxs_slice (slice) – slice of points to be

Returns:

(ndarray) – misfit

$$\nabla^2_{\bf a}\vert f_{1,{\bf a}} - f_2 \vert^2$$

TransportMaps.L2.L2_distance.L2_misfit(*args, **kwargs)[source]

Compute $$\Vert f_1 - f_2 \Vert_{L^2_\pi}$$

Parameters:
• f1 (Function or ndarray [$$m$$]) – function $$f_1$$ or its functions values

• f2 (Function or ndarray [$$m$$]) – function $$f_2$$ or its functions values

• d (Distribution) – distribution $$\pi$$

• params1 (dict) – parameters for function $$f_1$$

• params2 (dict) – parameters for function $$f_2$$

• qtype (int) – quadrature type to be used for the approximation of $$\mathbb{E}_{\pi}$$

• qparams (object) – parameters necessary for the construction of the quadrature

• x (ndarray [$$m,d$$]) – quadrature points used for the approximation of $$\mathbb{E}_{\pi}$$

• w (ndarray [$$m$$]) – quadrature weights used for the approximation of $$\mathbb{E}_{\pi}$$

• batch_size (int) – this defines whether to evaluate in batches or not. A size 1 correspond to a completely non-vectorized evaluation. A size None correspond to a completely vectorized one. (Note: if nprocs > 1, then the batch size defines the size of the batch for each process)

• mpi_pool (mpi_map.MPI_Pool) – pool of processes to be used for the evaluation of f1 and f2

Returns:

(float) – misfit $$\Vert f_1 - f_2 \Vert_{L^2_\pi}$$

Note

The parameters (qtype,qparams) and (x,w) are mutually exclusive, but one pair of them is necessary.

TransportMaps.L2.L2_distance.L2squared_misfit(f1, f2, d=None, params1=None, params2=None, qtype=None, qparams=None, x=None, w=None, batch_size=None, mpi_pool=None)[source]

Compute $$\Vert f_1 - f_2 \Vert^2_{L^2_\pi}$$

Parameters:
• f1 (Function or ndarray [$$m$$]) – function $$f_1$$ or its functions values

• f2 (Function or ndarray [$$m$$]) – function $$f_2$$ or its functions values

• d (Distribution) – distribution $$\pi$$

• params1 (dict) – parameters for function $$f_1$$

• params2 (dict) – parameters for function $$f_2$$

• qtype (int) – quadrature type to be used for the approximation of $$\mathbb{E}_{\pi}$$

• qparams (object) – parameters necessary for the construction of the quadrature

• x (ndarray [$$m,d$$]) – quadrature points used for the approximation of $$\mathbb{E}_{\pi}$$

• w (ndarray [$$m$$]) – quadrature weights used for the approximation of $$\mathbb{E}_{\pi}$$

• batch_size (int) – this defines whether to evaluate in batches or not. A size 1 correspond to a completely non-vectorized evaluation. A size None correspond to a completely vectorized one. (Note: if nprocs > 1, then the batch size defines the size of the batch for each process)

• mpi_pool (mpi_map.MPI_Pool) – pool of processes to be used for the evaluation of f1 and f2

Returns:

(float) – misfit $$\Vert f_1 - f_2 \Vert^2_{L^2_\pi}$$

Note

The parameters (qtype,qparams) and (x,w) are mutually exclusive, but one pair of them is necessary.

TransportMaps.L2.L2_distance.grad_a_L2squared_misfit(f1, f2, d=None, params1=None, params2=None, qtype=None, qparams=None, x=None, w=None, batch_size=None, mpi_pool=None)[source]

Compute $$\nabla_{\bf a}\Vert f_{1,{\bf a}} - f_2 \Vert^2_{L^2_\pi}$$

Parameters:
• f1 (ParametricFunctionApproximation) – function $$f_1$$

• f2 (Function or ndarray [$$m$$]) – function $$f_2$$ or its functions values

• d (Distribution) – distribution $$\pi$$

• params1 (dict) – parameters for function $$f_1$$

• params2 (dict) – parameters for function $$f_2$$

• qtype (int) – quadrature type to be used for the approximation of $$\mathbb{E}_{\pi}$$

• qparams (object) – parameters necessary for the construction of the quadrature

• x (ndarray [$$m,d$$]) – quadrature points used for the approximation of $$\mathbb{E}_{\pi}$$

• w (ndarray [$$m$$]) – quadrature weights used for the approximation of $$\mathbb{E}_{\pi}$$

• batch_size (int) – this defines whether to evaluate in batches or not. A size 1 correspond to a completely non-vectorized evaluation. A size None correspond to a completely vectorized one. (Note: if nprocs > 1, then the batch size defines the size of the batch for each process)

• mpi_pool (mpi_map.MPI_Pool) – pool of processes to be used for the evaluation of f1 and f2

Returns:

(ndarray [$$N$$]) – misfit gradient

$$\nabla_{\bf a}\Vert f_1 - f_2 \Vert_{L^2_\pi}$$

Note

The parameters (qtype,qparams) and (x,w) are mutually exclusive, but one pair of them is necessary.

TransportMaps.L2.L2_distance.hess_a_L2squared_misfit(f1, f2, d=None, params1=None, params2=None, qtype=None, qparams=None, x=None, w=None, batch_size=None, mpi_pool=None)[source]

Compute $$\nabla^2_{\bf a}\Vert f_{1,{\bf a}} - f_2 \Vert^2_{L^2_\pi}$$

Parameters:
• f1 (ParametricFunctionApproximation) – function $$f_1$$

• f2 (Function or ndarray [$$m$$]) – function $$f_2$$ or its functions values

• d (Distribution) – distribution $$\pi$$

• params1 (dict) – parameters for function $$f_1$$

• params2 (dict) – parameters for function $$f_2$$

• qtype (int) – quadrature type to be used for the approximation of $$\mathbb{E}_{\pi}$$

• qparams (object) – parameters necessary for the construction of the quadrature

• x (ndarray [$$m,d$$]) – quadrature points used for the approximation of $$\mathbb{E}_{\pi}$$

• w (ndarray [$$m$$]) – quadrature weights used for the approximation of $$\mathbb{E}_{\pi}$$

• batch_size (int) – this defines whether to evaluate in batches or not. A size 1 correspond to a completely non-vectorized evaluation. A size None correspond to a completely vectorized one. (Note: if nprocs > 1, then the batch size defines the size of the batch for each process)

• mpi_pool (mpi_map.MPI_Pool) – pool of processes to be used for the evaluation of f1 and f2

Returns:

(ndarray [$$N,N$$]) – misfit Hessian

$$\nabla^2_{\bf a}\Vert f_1 - f_2 \Vert_{L^2_\pi}$$

Note

The parameters (qtype,qparams) and (x,w) are mutually exclusive, but one pair of them is necessary.

TransportMaps.L2.L2_distance.storage_hess_a_L2squared_misfit(f1, f2, d=None, params1=None, params2=None, qtype=None, qparams=None, x=None, w=None, batch_size=None, mpi_pool=None)[source]

Assemble $$\nabla^2_{\bf a}\Vert f_{1,{\bf a}} - f_2 \Vert^2_{L^2_\pi}$$.

Parameters:
• f1 (ParametricFunctionApproximation) – function $$f_1$$

• f2 (Function or ndarray [$$m$$]) – function $$f_2$$ or its functions values

• d (Distribution) – distribution $$\pi$$

• params1 (dict) – parameters for function $$f_1$$

• params2 (dict) – parameters for function $$f_2$$

• qtype (int) – quadrature type to be used for the approximation of $$\mathbb{E}_{\pi}$$

• qparams (object) – parameters necessary for the construction of the quadrature

• x (ndarray [$$m,d$$]) – quadrature points used for the approximation of $$\mathbb{E}_{\pi}$$

• w (ndarray [$$m$$]) – quadrature weights used for the approximation of $$\mathbb{E}_{\pi}$$

• batch_size (int) – this defines whether to evaluate in batches or not. A size 1 correspond to a completely non-vectorized evaluation. A size None correspond to a completely vectorized one. (Note: if nprocs > 1, then the batch size defines the size of the batch for each process)

• mpi_pool (mpi_map.MPI_Pool) – pool of processes to be used for the evaluation of f1 and f2

Returns:

(None) – the result is stored in params1['hess_a_L2_misfit']

Note

The parameters (qtype,qparams) and (x,w) are mutually exclusive, but one pair of them is necessary.

Note

the dictionary params1 must be provided

TransportMaps.L2.L2_distance.action_stored_hess_a_L2squared_misfit(H, v)[source]

Evaluate the action of $$\nabla^2_{\bf a}\Vert f_{1,{\bf a}} - f_2 \Vert^2_{L^2_\pi}$$ on $$v$$.

Parameters:
• v (ndarray [$$N,N$$]) – vector $$v$$

• v – Hessian $$\nabla^2_{\bf a}\Vert f_{1,{\bf a}} - f_2 \Vert^2_{L^2_\pi}$$

Returns:

(ndarray` [$$N$$]) –

$$\langle\nabla^2_{\bf a}\Vert f_{1,{\bf a}} - f_2 \Vert^2_{L^2_\pi},v\rangle$$