pyrtid.regularization.TVRegularizator#
- class pyrtid.regularization.TVRegularizator(grid: ~pyrtid.utils.grid.RectilinearGrid, eps: float = 1e-20, preconditioner: ~pyrtid.utils.preconditioner.Preconditioner = <pyrtid.utils.preconditioner.NoTransform object>)[source]#
Bases:
RegularizatorApply a Total Variation (sharpening) regularization.
- Attributes
grid (RectilinearGrid) – RectilinearGrid of the field.
eps (float) – Small factor added in the square root to deal with the singularity at $nabla u = 0$ when computing the gradient. The default is 1e-20.
preconditioner (Preconditioner) – Parameter pre-transformation operator (variable change for the solver). The default is the identity function: f(x) = x, which means no change is made.
- __init__(grid: ~pyrtid.utils.grid.RectilinearGrid, eps: float = 1e-20, preconditioner: ~pyrtid.utils.preconditioner.Preconditioner = <pyrtid.utils.preconditioner.NoTransform object>) None#
Initialize the instance.
- Parameters
preconditioner (Preconditioner) – Whether the regularization is applied to the preconditioned values or not, by default False.
Methods definition
- _eval_loss(values: ndarray[Any, dtype[float64]]) float[source]#
Compute the gradient of the regularization loss function analytically.
\[\]mathcal{R}_{TN}(u) = frac{1}{2} sum_{j=1}^{M} sum_{i=1}^{N} left( dfrac{u_{i+1, j} - u_{i,j}}{dx} right)^{2}
- Parameters
values (NDArrayFloat) – The parameter for which the regularization is computed.
- Return type
- _eval_loss_gradient_analytical(values: ndarray[Any, dtype[float64]]) ndarray[Any, dtype[float64]][source]#
Compute the gradient of the regularization loss function analytically.
- Parameters
values (NDArrayFloat) – The parameter for which the regularization is computed.
- Returns
The regularization gradient.
- Return type
NDArrayFloat
- eval_loss(values: ndarray[Any, dtype[float64]]) float#
Compute the regularization loss function.
- Parameters
values (NDArrayFloat) – The parameter for which the regularization is computed.
- Returns
The regularization gradient.
- Return type
NDArrayFloat
- eval_loss_gradient(values: ndarray[Any, dtype[float64]], is_finite_differences: bool = False, max_workers: int = 1) ndarray[Any, dtype[float64]]#
Compute the gradient of the regularization loss function.
- Parameters
values (NDArrayFloat) – The parameter for which the regularization is computed.
is_finite_differences (bool) – If true, a numerical approximation by 2nd order finite difference is returned. Cost twice the values dimensions in terms of loss function calls. The default is False.
max_workers (int) – Number of workers used if the gradient is approximated by finite differences. If different from one, the calculation relies on multi-processing to decrease the computation time. The default is 1.
- Returns
The regularization gradient (not preconditioned).
- Return type
NDArrayFloat
- eval_loss_gradient_analytical(values: ndarray[Any, dtype[float64]]) ndarray[Any, dtype[float64]]#
Compute the gradient of the regularization loss function analytically.
- Parameters
values (NDArrayFloat) – The parameter for which the regularization is computed.
- Returns
The regularization gradient.
- Return type
NDArrayFloat