Objectives
Objectives evaluate a reconstruction functional and its gradient for a conductivity $\sigma$. All buffers are allocated when the objective is built; the linear solver is swappable (DirectSolver, BlockCGSolver) and the gradient representation is chosen with an AbstractRieszMap.
ModularEIT.AbstractObjective — Type
AbstractObjectiveA reconstruction functional J(σ) with gradient, e.g. the least-squares data misfit through the adjoint state method (AdjointStateObjective) or the Kohn–Vogelius functional (KohnVogeliusObjective). Interface: objective_value, value_and_gradient!.
ModularEIT.objective_value — Function
objective_value(obj, σ)Value of the objective at the conductivity coefficients σ (forward solves only).
ModularEIT.value_and_gradient! — Function
value_and_gradient!(g, obj, σ)Value of the objective at σ; writes the gradient (in the representation of the objective's gradient Riesz map) into g.
Adjoint-state least squares
Theory: wiki articles Adjoint State Method and Adjoint Method for the Dirichlet Problem.
ModularEIT.AdjointStateObjective — Type
AdjointStateObjective(fm, inputs, data; mode = :neumann, solver = DirectSolver(),
misfit = SquaredEuclidean(), gradient = CoefficientGradient())Least-squares misfit J(σ) = ½ Σₛ ‖U eₛ(σ)‖² between predicted and measured data for the forward model fm, with the gradient from one adjoint solve and the Jacobian on request.
mode = :neumann:inputsare current patterns (n_inject × s),datathe measured voltages (n_measure × s). Voltages are compared after removing their mean (the ground is arbitrary), weighted byfm.measure_weights(boundary lengths for the continuum model).mode = :dirichlet:inputsare voltage patterns (n_control × s),datathe measured currents (n_inject × s, in the representation offm.P).
solver is any AbstractLinearSolver; misfit any AbstractMisfit; gradient the AbstractRieszMap applied to the coefficient gradient. All buffers are allocated here; evaluations only allocate inside the linear solvers.
Interface: objective_value, value_and_gradient!, residual!, residual_and_jacobian!, n_residual.
ModularEIT.residual! — Function
residual!(r, obj, σ)Whitened residual r = vec(U e) at σ (so that J = ½ ‖r‖²); returns r.
ModularEIT.residual — Function
residual(obj, θ)The residual vector of a least-squares objective (J = ½ ‖r‖²) at θ, allocating; see residual!. For an AdjointStateObjective with zero data and the plain misfit this is the vector of measured voltages, i.e. the forward map. With ChainRulesCore loaded, it has reverse (Jᵀ r̄, adjoint solves) and forward (J δθ, linearized solves) differentiation rules, as does objective_value (reverse: the adjoint-state gradient).
ModularEIT.residual_and_jacobian! — Function
residual_and_jacobian!(r, J, obj, σ)Whitened residual r and its Jacobian J = ∂r/∂σ (n_residual(obj) × n_σ, coefficient representation) at σ. Costs one block solve with k right-hand sides plus k × s sparse products with the conductivity tensor, k the residual entries per pattern (n_obs, or the rows of a ProjectedMisfit).
ModularEIT.n_residual — Function
n_residual(obj)Length of the residual vector (n_obs × s, stacked pattern by pattern).
Matrix-free Jacobians
For problems whose Jacobian does not fit into memory: J * v costs one linearized forward solve per pattern, J' * w one adjoint solve per pattern (both reuse the factorization of the forward problem). Column norms and the Gram matrix JᵀJ are accumulated from row blocks of the Jacobian without storing it. GaussNewton(; linear_solver = :cg) uses these.
J = jacobian_operator(obj, θ) # AdjointStateObjective or ParametrizedObjective
y = J * v; g = J' * w
s = jacobian_column_norms(obj, θ) # sensitivities
G, g = jacobian_gram(obj, θ) # JᵀJ and JᵀrModularEIT.jacobian_operator — Function
jacobian_operator(obj, σ)The Jacobian J = ∂r/∂σ of the residual at σ as a matrix-free operator: J * v (one linearized forward solve per pattern) and J' * w (one adjoint solve per pattern), with mul! for both, reusing the factorization of the forward solves. Neumann (current-driven) mode. The operator re-linearizes by itself if the objective has been evaluated at another σ in the meantime. For Krylov methods, Gauss–Newton with linear_solver = :cg, and problems whose Jacobian does not fit into memory.
ModularEIT.JacobianOperator — Type
JacobianOperatorMatrix-free Jacobian of an AdjointStateObjective; see jacobian_operator.
ModularEIT.ParametrizedJacobian — Type
ParametrizedJacobianMatrix-free Jacobian J_θ = J_σ P of a ParametrizedObjective; see jacobian_operator.
ModularEIT.jacobian_column_norms — Function
jacobian_column_norms(obj, θ)Column norms ‖J eⱼ‖ of the Jacobian of the least-squares objective obj at θ (sensitivities), accumulated from row blocks without storing J.
ModularEIT.jacobian_gram — Function
jacobian_gram(obj, θ)The Gram matrix JᵀJ (n × n) and Jᵀr of the Jacobian and residual of obj at θ, accumulated from row blocks without storing J: the Gauss–Newton Hessian and gradient, also for problems with far more residuals than parameters.
Automatic differentiation
With ChainRulesCore.jl loaded (e.g. through Zygote), objective_value and residual have differentiation rules, so they can be used inside differentiated programs, for instance with a conductivity produced by a neural network or when training through the forward model. The derivatives are computed by the adjoint-state and linearized solves of ModularEIT, not by differentiating through the finite element and linear solver code:
objective_value(obj, σ): reverse rule,J̄ ∇J(σ)(the objective must deliver coefficient gradients,gradient = CoefficientGradient());residual(obj, σ): reverse ruleJᵀ r̄(one adjoint solve per pattern) and forward ruleJ δσ(one linearized solve per pattern), matrix-free wherejacobian_operatoris available.
The residual of an AdjointStateObjective with zero data is the vector of measured voltages, so residual doubles as a differentiable forward map:
using ModularEIT, ModularEITFerrite, Zygote
forward = AdjointStateObjective(fm, currents, zero(data))
gradient(σ -> sum(abs2, residual(forward, σ)), σ)Enzyme.jl can use the same rules through Enzyme.@import_rrule.
Kohn–Vogelius
Theory: wiki article Kohn-Vogelius Functional.
ModularEIT.KohnVogeliusObjective — Type
KohnVogeliusObjective(fm, currents, voltages; solver = DirectSolver(), gradient = CoefficientGradient())Kohn–Vogelius functional J(σ) = ½ Σₛ ‖x_N,ₛ - x_D,ₛ‖²_{A(σ)} for the current patterns currents (n_inject × s) and the measured voltages voltages (n_control × s, at the injection sites: boundary dofs, points or all CEM electrodes). The gradient needs no adjoint solve. After an evaluation, boundary_error returns the voltage misfit of the current-driven solution and pattern_values the contribution of every pattern.
ModularEIT.boundary_error — Function
boundary_error(obj::KohnVogeliusObjective)Measured minus predicted voltages of the current-driven states at the last evaluation (Q x_N - V, mean removed per pattern).
ModularEIT.pattern_values — Function
pattern_values(obj::KohnVogeliusObjective)Contribution ½ ‖x_N,ₛ - x_D,ₛ‖²_A of every pattern at the last evaluation.
Misfit metrics
ModularEIT.AbstractMisfit — Type
AbstractMisfitMetric in which the data misfit is measured. J = ½ ‖U e‖² for a whitening operator U, e.g. SquaredEuclidean (U = I) or WeightedSquaredEuclidean (UᵀU = W).
ModularEIT.SquaredEuclidean — Type
SquaredEuclidean()J = ½ Σₛ ‖eₛ‖² over the patterns s.
ModularEIT.WeightedSquaredEuclidean — Type
WeightedSquaredEuclidean(W)J = ½ Σₛ eₛᵀ W eₛ for a symmetric positive definite W (n_obs × n_obs), e.g. inverse noise covariances or a boundary mass matrix. Whitened residual r = U e with UᵀU = W.
ModularEIT.ProjectedMisfit — Type
ProjectedMisfit(U)J = ½ Σₛ ‖U eₛ‖² for a rectangular U (k × n_obs, k ≤ n_obs): only k combinations of the measurements enter the misfit, e.g. the leading measurement modes of pattern_svd (truncate_patterns(p, K; measurements = M), a two-sided truncation of the data with K M residuals instead of n_obs K). The residual has k entries per pattern.
Abstract types of the reconstruction layer
ModularEIT.AbstractEITProblem — Type
AbstractEITProblemA complete reconstruction problem (discretization, forward model, data, objective, current iterate), solved by reconstruct!; see EITProblem.
ModularEIT.AbstractSolutionState — Type
AbstractSolutionStateState of an iterative reconstruction (iterate, step sizes, histories), e.g. the OptimizationState returned by minimize.
Wiki articles
Theory behind this page in the theory wiki:
- Linearized EIT and the Sensitivity Kernel
- Data Fidelity Terms
- Adjoint State Method
- State Equation
- Adjoint Equation
- Adjoint Method for the Dirichlet Problem
- Functional Derivative of the Data Misfit
- Kohn-Vogelius Functional
- Gauss-Newton Method
Index
ModularEITModularEITFerrite.ModularEITFerriteModularEITGridapModularEIT.ADMMModularEIT.AMGPreconditionerModularEIT.AbstractDiscretizationModularEIT.AbstractEITProblemModularEIT.AbstractElectrodeModelModularEIT.AbstractFastPreconditionerModularEIT.AbstractForwardModelModularEIT.AbstractInclusionModularEIT.AbstractLinearSolverModularEIT.AbstractMisfitModularEIT.AbstractNoiseModelModularEIT.AbstractObjectiveModularEIT.AbstractOptimizerModularEIT.AbstractParametrizationModularEIT.AbstractRegularizerModularEIT.AbstractRieszMapModularEIT.AbstractSolutionStateModularEIT.AdjointStateObjectiveModularEIT.ApproximationErrorModularEIT.ApproximationErrorObjectiveModularEIT.BlockCGSolverModularEIT.BlockCGStatsModularEIT.BlockMinresStatsModularEIT.CircleInclusionModularEIT.CoefficientGradientModularEIT.CompleteElectrodeModelModularEIT.ConductivityTensorModularEIT.ConformalMapModularEIT.ContinuumModelModularEIT.DCTPreconditionerModularEIT.DeviceSparseMatrixCSRModularEIT.DirectSolverModularEIT.EITProblemModularEIT.EllipseInclusionModularEIT.FEMatricesModularEIT.ForwardModelModularEIT.GapModelModularEIT.GaussNewtonModularEIT.GaussianNoiseModularEIT.GradientDescentModularEIT.InclusionPhantomModularEIT.InfeasibleConductivityErrorModularEIT.JacobiPreconditionerModularEIT.JacobianOperatorModularEIT.KohnVogeliusObjectiveModularEIT.L2GradientModularEIT.LBFGSModularEIT.OptimizationStateModularEIT.ParametrizedJacobianModularEIT.ParametrizedObjectiveModularEIT.PixelFunctionModularEIT.PointElectrodeModelModularEIT.PolarPreconditionerModularEIT.PolarStructureModularEIT.PolygonInclusionModularEIT.ProjectedCholeskyModularEIT.ProjectedMinresWorkspaceModularEIT.ProjectedMisfitModularEIT.ProximalGradientModularEIT.ProximalMapModularEIT.RegularizedObjectiveModularEIT.RelativeGaussianNoiseModularEIT.SourceMeterNoiseModularEIT.SquaredEuclideanModularEIT.StructuredGridModularEIT.SubspaceParametrizationModularEIT.TikhonovRegularizerModularEIT.TotalVariationRegularizerModularEIT.TransformedPhantomModularEIT.TruncatedGaussNewtonModularEIT.WeightedSquaredEuclideanModularEITFerrite.AdaptiveMeshModularEITFerrite.ConformalGridModularEITFerrite.FerriteDiscretizationModularEITFerrite.ImageMapModularEITFerrite.PixelParametrizationModularEITFerrite.UnitImageModularEITGridap.GridapDiscretizationLinearAlgebra.ldiv!ModularEIT.BlockCGWorkspaceModularEIT._gram!ModularEIT.add_noiseModularEIT.angular_electrodesModularEIT.apply_preconditioner!ModularEIT.assemble_weighted_stiffnessModularEIT.assemble_weighted_stiffness!ModularEIT.boundary_errorModularEIT.boundary_groundingModularEIT.conductivityModularEIT.conductivityModularEIT.corrupt_imageModularEIT.data_misfitModularEIT.dct_neumann_solveModularEIT.dct_preconditionerModularEIT.device_converterModularEIT.discrepancy_targetModularEIT.discrepancy_targetModularEIT.dorfler_markingModularEIT.electrode_anglesModularEIT.electrode_lengthModularEIT.expected_squared_errorModularEIT.fast_neumann_solveModularEIT.fe_innerModularEIT.fe_normModularEIT.forward_dirichletModularEIT.forward_neumannModularEIT.gauss_newton_hessianModularEIT.gaussian_random_fieldModularEIT.image_phantomModularEIT.interpolate_functionModularEIT.jacobian_basisModularEIT.jacobian_column_normsModularEIT.jacobian_gramModularEIT.jacobian_operatorModularEIT.jacobian_svdModularEIT.l2_projectModularEIT.levelset_phantomModularEIT.lognormal_phantomModularEIT.lumped_massModularEIT.map_derivativeModularEIT.minimizeModularEIT.n_injectModularEIT.n_residualModularEIT.ndofs_uModularEIT.ndofs_σModularEIT.objective_valueModularEIT.pair_products!ModularEIT.parameter_countModularEIT.pattern_svdModularEIT.pattern_valuesModularEIT.pbcgModularEIT.pbcg!ModularEIT.pbminresModularEIT.pbminres!ModularEIT.perturb_boundary_operatorModularEIT.perturb_contact_impedanceModularEIT.pixel_imageModularEIT.polar_preconditionerModularEIT.polar_structureModularEIT.posterior_stdModularEIT.projected_choleskyModularEIT.projected_ldlModularEIT.prox!ModularEIT.random_inclusionsModularEIT.reconstruct!ModularEIT.refactor!ModularEIT.regroundModularEIT.residualModularEIT.residual!ModularEIT.residual_and_jacobian!ModularEIT.resolution_mapModularEIT.riesz_map!ModularEIT.sensitivity_mapModularEIT.simulate_dataModularEIT.solutionModularEIT.structured_gridModularEIT.system_matrix!ModularEIT.tensor_gradient!ModularEIT.total_variationModularEIT.total_variation!ModularEIT.transfer_electrodesModularEIT.trigonometric_patternsModularEIT.truncate_patternsModularEIT.update_preconditioner!ModularEIT.value_and_gradient!ModularEIT.weighted_stiffness_values!ModularEIT.whitenModularEITFerrite.assemble_boundary_load!ModularEITFerrite.assemble_boundary_mass!ModularEITFerrite.assemble_mass!ModularEITFerrite.assemble_stiffness!ModularEITFerrite.boundary_band_basisModularEITFerrite.cell_levelsModularEITFerrite.coarsen_mesh!ModularEITFerrite.conformal_gridModularEITFerrite.current_gridModularEITFerrite.dct_basisModularEITFerrite.flux_recovery_indicatorModularEITFerrite.from_imageModularEITFerrite.from_unit_imageModularEITFerrite.goal_oriented_indicatorModularEITFerrite.is_nonconformingModularEITFerrite.jump_indicatorModularEITFerrite.max_levelModularEITFerrite.pixel_parametersModularEITFerrite.polar_gridModularEITFerrite.refine_mesh!ModularEITFerrite.residual_indicatorModularEITFerrite.to_imageModularEITFerrite.transfer_conductivityModularEITFerrite.unit_image