Objective Function Equations for Magnetic Field Shimming Optimization
This document describes the mathematical objective functions used in optimization algorithms for magnetic field shimming.
Magnetic field shimming aims to reduce spatial inhomogeneities in a measured magnetic field map by adjusting the currents in a set of shim coils. Each optimization method minimizes a residual (a numerical measure of the remaining inhomogeneity) according to a specific objective function.
The variables and notation used in the equations will first be defined, then the residual formulations for each optimization method (pseudo-inverse, quadratic programming, least squares, BFGS, etc.) will be detailed.
Definitions of symbols
The main variables used throughout this document are:
\(A\) – Coil profile matrix of size (
masked_values,nb_channels), wheremasked_values(noted \(v\)) is the number of voxels in the region of interest (ROI) andnb_channelsis the number of shim coil channels. Each column corresponds to the spatial magnetic field profile (per unit current) for a particular coil channel, evaluated at all voxels in the ROI.\(u\) – Unshimmed field vector of size (
masked_values). Contains the measured values of the magnetic field map before shimming, at each voxel in the ROI.\(m\) – Mask/weight vector of size (
masked_values). Contains non-zero values for voxels included in the optimization, weighting their contribution to the objective function.\(x\) – Solution vector of size (
nb_channels). Contains the coil currents to be induced in each channel.\(r\) – Residual (objective function value) to be minimized. This scalar value represents the inhomogeneity after applying the coil currents.
\(f\) – Stability factor used to scale the residual term for numerical stability.
\(\lambda\) – Regularization vector of size (
nb_channels). Used to penalize large current amplitudes (L2 regularization). Its diagonalized matrix form is \(\Lambda\), of size (nb_channels,nb_channels).\(m_e\) – Eroded mask used in gradient-based signal recovery methods.
\(w_i\) – Weighting factor for gradient optimization in direction \(i \in \{x, y, z\}\), used in signal recovery.
\(\delta\) – Threshold parameter in the pseudo-Huber loss function, controlling transition between quadratic and linear penalty.
Problem formulation
The goal is to find \(x\) that minimizes inhomogeneities in the measured field given by the following linear system : \(m^{T}Ax = -m^{T}u\). This represents the requirement that the contribution from the coils \(Ax\) exactly cancels the inhomogeneities present in the field \(-u\).
Optimization methods and their objective functions
Pseudo-inverse method – No explicit objective function; direct linear algebra solution.
Quadprog method – Mean squared error (MSE) objective with quadratic programming.
- Least squares and BFGS methods – Several possible objective functions:
Mean absolute error (MAE)
Mean squared error (MSE)
MSE with signal recovery
Root mean squared error (RMSE)
RMSE with signal recovery
Mean pseudo-Huber (MPSH)
1. Pseudo-inverse
This method solves the system directly:
Where \(A^+\) is the pseudo-inverse of \(A\) and \(\sqrt{m}\) is the element-wise square root of \(m\).
2. Quadprog
The objective function is the following :
The first term is the weighted MSE, scaled by the stability factor \(f\), and the second term penalizes large currents. The resulting residual is passed to the quadprog package to obtain the currents.
3. Least squares and BFGS
These methods share the same objective function formulations, solved using:
3.1. Mean absolute error (MAE)
The objective function is the following :
3.2. Mean squared error (MSE)
A different formulation is used with this objective function to accelerate the compute time. The objective function is the following :
where:
3.3. MSE with signal recovery
To enhance signal recovery with slice-wise shimming, it is possible to consider the gradients (x-wise, y-wise and z-wise) in the optimization process. The objective function uses the fast quadratic formulation:
where:
The quadratic terms \(a_0\), \(b_0\), and \(c_0\) are the same as in the standard MSE objective:
For each gradient direction \(i \in \{x, y, z\}\), the additional terms \(a_i\), \(b_i\), and \(c_i\) are:
Here:
\(A_i\) is the coil matrix derived for the field gradient in direction \(i\),
\(u_i\) is the unshimmed field gradient in direction \(i\),
3.4. Root mean squared error (RMSE)
The RMSE objective function measures the square root of the weighted MSE, plus a regularization term:
3.5. RMSE with signal recovery
This variant extends the RMSE objective by incorporating an additional RMSE term for the through-slice (z-direction) gradient :
Here:
\(w_z\) controls the contribution from the z-gradient recovery term,
\(A_z\) and \(u_z\) are the z-gradient coil matrix and unshimmed field gradient, respectively.
3.6. Mean pseudo-Huber (MPSH)
In this method, a parameter \(\delta\) determines the threshold between quadratic and linear loss. The objective function behaves quadratically for residuals smaller than \(\delta\) and linearly otherwise, resulting in the following expression :