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 linear operator that represents the Hessian matrix. Default to False.

Important

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 objective function for a given model.

chi_factor(model)

Compute chi factor.

gradient(model)

Gradient vector.

hessian(model)

Hessian matrix.

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[ 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, \(\mathbf{d}^\text{obs}\) is the vector of observed data, and \(f(\mathbf{m})\) is the forward modelling vector.

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 objective function for a given model.


DataMisfit.chi_factor(model)#

Compute chi factor.

Parameters:
model(n_params) array

Array with model values.


DataMisfit.gradient(model)#

Gradient vector.


DataMisfit.hessian(model)#

Hessian matrix.


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} = \mathcal{F}(\mathbf{m}) - \mathbf{d}\]

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


DataMisfit.set_name(value)#

Set name for the objective function.