inversion_ideas.DataMisfit#

class inversion_ideas.DataMisfit(data, uncertainty, simulation, *, build_hessian=False, estimate_hessian_diagonal=False)#

L2 data misfit.

Parameters:
data(n_data) array

Array with observed data values.

uncertainty(n_data) array

Array with data uncertainty.

simulationSimulation

Instance of Simulation.

build_hessianbool, optional

If True, the hessian() method will build the Hessian matrix and allocate it in memory. If False, the hessian() method will return a LinearOperator that represents the Hessian matrix. Default to False.

Warning

Hessian matrices are usually very large. Use build_hessian=True only if you need to build it.

estimate_hessian_diagonalbool, optional

If True, the hessian_diagonal() method will estimate the diagonal of the Hessian, even if the Jacobian of the simulation is a LinearOperator. If False, an error will be raised when calling the hessian_diagonal() method in case the Jacobian of the simulation is a LinearOperator.

Important

Estimating the diagonal of a LinearOperator require a high number of dot products between the operator and multiple unit vectors. This might lead to very expensive computations. Enable estimate_hessian_diagonal only if you really need to.

Attributes

n_data

Number of data values.

n_params

Number of model parameters.

name

Name of the objective function.

weights

Data weights: 1D array with the square of the inverse of the uncertainties.

weights_matrix

Diagonal matrix with the square root of the regularization weights.

Methods

__call__(model)

Evaluate the data misfit function.

chi_factor(model)

Compute the chi factor for the given model.

gradient(model)

Gradient vector of the data misfit function.

hessian(model)

Evaluate the hessian of the data misfit function for a given model.

hessian_diagonal(model)

Get the main diagonal of the Hessian.

info()

Get information about the objective function.

residual(model)

Residual vector.

set_name(value)

Set name for the objective function.

Notes

The L2 data misfit objective function is defined as:

\[\phi_d(\mathbf{m}) = \sum\limits_{i=1}^N \frac{ \left\lvert f_i(\mathbf{m}) - d_i^\text{obs} \right\rvert^2 }{ \epsilon_i^2 }\]

where \(\mathbf{m}\) is the model vector, \(d_i^\text{obs}\) is the \(i\)-th observed datum, \(f_i(\mathbf{m})\) is the forward modelling function for the \(i\)-th datum, and \(\epsilon_i\) is the uncertainty of the \(i\)-th datum.

The data misfit term can be expressed in terms of weights \(w_i = 1 / \epsilon_i^2\):

\[\phi_d(\mathbf{m}) = \sum\limits_{i=1}^N w_i \left\lvert f_i(\mathbf{m}) - d_i^\text{obs} \right\rvert^2\]

And also in matrix form:

\[\phi_d(\mathbf{m}) = \left\lVert \mathbf{W} \left[ \mathbf{f}(\mathbf{m}) - \mathbf{d}^\text{obs} \right] \right\rVert^2\]

where \(\mathbf{W}\) is a diagonal matrix with the square root of the weights

\[\begin{split}\mathbf{W} = \begin{bmatrix} \sqrt{w_1} & & 0 \\ & \ddots & \\ 0 & & \sqrt{w_N} \\ \end{bmatrix},\end{split}\]

\(\mathbf{d}^\text{obs}\) is the vector of observed data

\[\begin{split}\mathbf{d}^\text{obs} = \begin{bmatrix} d_1^\text{obs} \\ \vdots \\ d_N^\text{obs} \\ \end{bmatrix},\end{split}\]

and \(\mathbf{f}(\mathbf{m})\) is the forward modelling vector

\[\begin{split}\mathbf{f}(\mathbf{m}) = \begin{bmatrix} f_1(\mathbf{m}) \\ \vdots \\ f_N(\mathbf{m}) \\ \end{bmatrix}.\end{split}\]

Attributes#

DataMisfit.n_data#

Number of data values.

DataMisfit.n_params#

Number of model parameters.

DataMisfit.name#

Name of the objective function.

DataMisfit.weights#

Data weights: 1D array with the square of the inverse of the uncertainties.

DataMisfit.weights_matrix#

Diagonal matrix with the square root of the regularization weights.

Methods#

Methods documentation

DataMisfit.__call__(model)#

Evaluate the data misfit function.

Parameters:
model(n_params) array

Array with model values.

Returns:
float

Value of the data misfit for the given model.

Notes

Evaluates the data misfit objective function defined as:

\[\phi_d(\mathbf{m}) = \sum\limits_{i=1}^N \frac{ \left\lvert f_i(\mathbf{m}) - d_i^\text{obs} \right\rvert^2 }{ \epsilon_i^2 }\]

where \(\mathbf{m}\) is the model vector, \(d_i^\text{obs}\) is the \(i\)-th observed datum, \(f_i(\mathbf{m})\) is the forward modelling function for the \(i\)-th datum, and \(\epsilon_i\) is the uncertainty of the \(i\)-th datum.


DataMisfit.chi_factor(model)#

Compute the chi factor for the given model.

Parameters:
model(n_params,) array

Array with model values.

Returns:
float

Chi factor for the given model.

Notes

The chi factor of a data misfit term \(\phi_d(\mathbf{m})\) is defined as a function of the model vector \(\mathbf{m}\) as follows:

\[\chi(\mathbf{m}) = \frac{\phi_d(\mathbf{m})}{N} = \frac{1}{N} \sum\limits_{i=1}^N \frac{ \left\lvert f_i(\mathbf{m}) - d_i^\text{obs} \right\rvert^2 }{ \epsilon_i^2 }\]

References


DataMisfit.gradient(model)#

Gradient vector of the data misfit function.

Parameters:
model(n_params) array

Array with model values.

Returns:
(n_params,) array

Gradient vector of the data misfit for the given model.

Notes

Computes the gradient of the data misfit as:

\[\nabla\phi_d(\mathbf{m}) = 2 \mathbf{J}^\text{T} \mathbf{W}^\text{T} \mathbf{W} \mathbf{J} \left[ \mathbf{f}(\mathbf{m}) - \mathbf{d}^\text{obs} \right],\]

where \(\mathbf{J}\) is the Jacobian matrix of the simulation (the forward model), \(\mathbf{W}\) is a diagonal matrix with the square root of the weights, \(\mathbf{d}^\text{obs}\) is the vector of observed data, and \(\mathbf{f}(\mathbf{m})\) is the forward modelling vector.


DataMisfit.hessian(model)#

Evaluate the hessian of the data misfit function for a given model.

Important

If build_hessian is set to True, this method will attempt to return a 2D dense or sparse array. If it’s False, it’ll return a LinearOperator.

Warning

Hessian matrices are usually very large. Use build_hessian=True only if you need to build it.

Parameters:
model(n_params) array

Array with model values.

Returns:
(n_params, n_params) array or LinearOperator

2D array or LinearOperator that represents the Hessian matrix of the objective funciton, or an approximate version of it.

Notes

Computes the Hessian matrix of the data misfit as:

\[\bar{\bar{\nabla}} \phi_d(\mathbf{m}) = 2 \mathbf{J}^\text{T} \mathbf{W}^\text{T} \mathbf{W} \mathbf{J},\]

where \(\mathbf{J}\) is the Jacobian matrix of the simulation (the forward model), and \(\mathbf{W}\) is a diagonal matrix with the square root of the weights.


DataMisfit.hessian_diagonal(model)#

Get the main diagonal of the Hessian.

Important

If the Jacobian of the simulation is a LinearOperator, the diagonal of the Hessian will be estimated only if estimate_hessian_diagonal is True. Diagonal estimations can be expensive computational tasks for large problems. Make sure you to enable diagonal estimations only if you need it.

Parameters:
model(n_params) array

Array with model values.

Returns:
(n_params,) array

Array containing the diagonal of the Hessian.


DataMisfit.info()#

Get information about the objective function.


DataMisfit.residual(model)#

Residual vector.

Parameters:
model(n_params) array

Array with model values.

Returns:
(n_data) array

Array with residual vector.

Notes

Residual vector defined as:

\[\mathbf{r} = \mathbf{f}(\mathbf{m}) - \mathbf{d}\]

where \(\mathbf{d}\) is the vector with observed data, \(\mathbf{f}\) is the forward model, and \(\mathbf{m}\) is the model vector.


DataMisfit.set_name(value)#

Set name for the objective function.