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.
- simulation
Simulation Instance of Simulation.
- build_hessianbool, optional
If True, the
hessian()method will build the Hessian matrix and allocate it in memory. If False, thehessian()method will return aLinearOperatorthat represents the Hessian matrix. Default to False.Warning
Hessian matrices are usually very large. Use
build_hessian=Trueonly 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 thesimulationis aLinearOperator. If False, an error will be raised when calling thehessian_diagonal()method in case the Jacobian of thesimulationis aLinearOperator.Important
Estimating the diagonal of a
LinearOperatorrequire a high number of dot products between the operator and multiple unit vectors. This might lead to very expensive computations. Enableestimate_hessian_diagonalonly if you really need to.
- data(
Attributes
Number of data values.
Number of model parameters.
Name of the objective function.
Data weights: 1D array with the square of the inverse of the uncertainties.
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:
- Returns:
floatValue 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.
- model(n_params,)
- Returns:
floatChi 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:
- Returns:
- (n_params,)
array Gradient vector of the data misfit for the given model.
- (n_params,)
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_hessianis set to True, this method will attempt to return a 2D dense or sparse array. If it’s False, it’ll return aLinearOperator.Warning
Hessian matrices are usually very large. Use
build_hessian=Trueonly if you need to build it.- Parameters:
- Returns:
- (
n_params,n_params)arrayorLinearOperator 2D array or
LinearOperatorthat 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
simulationis aLinearOperator, the diagonal of the Hessian will be estimated only ifestimate_hessian_diagonalis True. Diagonal estimations can be expensive computational tasks for large problems. Make sure you to enable diagonal estimations only if you need it.
- DataMisfit.info()#
Get information about the objective function.
- DataMisfit.residual(model)#
Residual vector.
- Parameters:
- Returns:
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.