{'fraction_non_alphanumeric': 0.02522844656336909, 'fraction_numerical': 0.011372665872069924, 'mean_word_length': 4.743582430119795, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Electric Field Models of Transcranial Magnetic Stimulation Coils with Arbitrary Geometries: Reconstruction from Incomplete Magnetic Field Measurements

Background: Calculation of the electric field induced by transcranial magnetic stimulation (TMS) in the brain requires accurate models of the stimulation coils. Reconstructing models from the measured magnetic fields of coils so far worked only for flat coil geometries and required data of their full magnetic field distribution. Objective: To reconstruct models of coils with arbitrary winding geometries from spatially incomplete magnetic field measurements. Methods: Dipole approximation via minimum norm estimation with a cross validation procedure simultaneously assessing predictability and reproducibility of the field approximation. The methods were validated on both simulated and acquired magnetic flux density data. Furthermore, reconstruction of coil models from sparsely sampled data is investigated and a procedure for obtaining sparse dipole coil models based on orthogonal matching pursuit is suggested. Results: Given that measured data from regions around the coil are available, the magnetic vector potential can accurately be represented by fitted dipole models even from sparsely sampled data. Considerable sparsification of dipole models is possible while retaining accurate representation of the field also close to the coil. Conclusion: Our versatile approach removes an important hurdle for constructing coil models from measurement data and enables a flexible trade-off between the accuracy and computational efficiency of the reconstructed dipole models.


Introduction
Realistic numerical calculations of the electric field induced by TMS in the brain require accurate theoretical models of the stimulation coils [1,2]. In the past, methods and automated approaches have been developed to measure the magnetic flux density of TMS coils, with the aim to obtain good theoretical models also when relevant technical parameters such as the internal winding geometries, the cable diameters and their exact position in the coil casing are not or only partially known [3][4][5][6].
A key challenge of these approaches is the reconstruction of the magnetic vector potential from the measured magnetic flux density, as knowledge of the vector potential in the complete head volume is required for the numerical field calculations [7,8]. Our previous reconstruction method [5] achieved accurate reconstructions, but required dense measurements in an extended volume around the coil (for arbitrary winding geometries) or from one half-space (for flat coils with mirrored magnetic fields in the unmeasured half). This made the practical data acquisition demanding and unfeasible for a regular use.
Here, we describe a novel reconstruction approach that generates accurate vector potential distributions for arbitrary winding geometries and that still works when the flux density around the TMS coil is incompletely sampled. We show an example of a sparse sampling strategy that leads to accurate and robust reconstructions for flux density data measured in only a few two-dimensional planes at varying distances to the coil. Finally, by controlling the number of magnetic dipoles used for constructing the theoretical coil model, we show that the method also enables a flexible trade-off between the accuracy and computational efficiency of the coil model when used in the numerical field calculations.

Material and Methods
We consider the magnetic vector potential (A) and magnetic flux density (B) at position due to a collection of magnetic dipoles in free space indexed by at positions with the magnetic dipole moments where ∇ is the differential vector operator and × is the curl vector operator. By splitting coordinates and dipole moments into Cartesian coordinate parts we arrive at the following linear relation between the dipole moments and the magnetic flux density 4/13 This can be expressed as a linear superposition of dipole fields collected in a leadfield matrix where contains the vectorized flux density measurements at position (and direction) and is the flux density due to a unit dipole located at position (and direction) evaluated at position , as calculated by the relation above and is the dipole moment of dipole . Estimation of the dipole moments amounts to solving this linear equation system for the vectorized dipole moments . Due to noise, high colinearity between the columns of and a limited number of measurements available this problem is usually ill-posed. The solutions to these type of problems based on so-called minimum norm estimators are well-investigated in the literature dealing with source localization for EEG and MEG [9]. In the current setting we will investigate simple minimum norm estimates based on regularization with a shrinkage prior, which amounts to seeking the solutions to the problem that minimize the convex cost function C(m): where is a projection matrix often used to impose smoothness or other desired properties of the solution, and is a positive regularization parameter to be determined using cross-validation. In the current setting initial experiments indicated that it was not advantageous to impose smoothness of the solution via approaches such as low resolution electromagnetic tomography [10] and hence simply regularize using the L2 norm, e.g. = . Furthermore, we opted for split-half resampling, as a sufficiently dense sampling of the positions can easily be achieved in practice and reserving equal amounts of data for fitting and testing allows reproducibility of estimated parameters across splits to be assessed in a simple and convenient way [11]. For numerical solution of the Poisson equation

5/13
governing the electric field, we require estimation of the magnetic vector potential A rather than B. In this setting, it is straightforward to obtain the A field using a similar linear leadfield equation

= .
Due to the definition of A (eq. 2), it is defined up to addition of any curl-free field.
Varying the regularization parameter results in different trade-offs between predictability (i.e. how well m estimated from one half-split of the measured b predicts the other half-split of the data) and reproducibility (i.e. how similar the m are that are estimated from the two half-splits of b). This tradeoff is well-investigated for the type of inverse problems studied here and can visualized by predictability-reproducibility curves (figure 1c) [12]. Following standard practice, we optimized predictability and reproducibility jointly by minimizing the Manhattan distance to the point (R, P) = (1, 1). For that, we chose to measure both predictability and reproducibility as the coefficient of determination as it is naturally bounded between 0 and 1. In practice, we found that the joint optimization of predictability and reproducibility ensured smooth solutions for the calculated B and A also for non-measured positions very close to the coil surface. This improved in particular the accuracy of A in these regions that could otherwise suffer from local errors because m was optimized to fit the measured B rather than the non-measurable A.

Simulated sparse data of a titled figure-8 coil
To demonstrate the general applicability of the approach, we determined the B fields of a simulated figure-8 coil with tilted wings using closed-form formulas (see Fig. 1d for details) and investigated the influence of noise on the reconstruction results by adding multiplicative Gaussian noise at various signal-to-noise ratios. Magnetic dipoles were placed on a regular grid inside the coil casing and the above method was applied to estimate their weights in order to best fit the simulated B. We tested two situations, first for B field data sampled in three planes above the coil (z=[33.7, 73.5, 113.2] mm; Fig. 1d illustrates the B field in an example plane), and second with one additional plane at the other side of the coil (z=-34.5 mm). Both situations were aimed to mimic measurement data that is sparse along the z-direction. For evaluation, we calculated the error of the fitted model as the difference of its B and A fields to the ground truth obtained by closed-form formulas. This was done on a new, more dense sampling constricted in a sphere with radius 75 mm and centered below the coil surface at a distance of 85 mm. These choices were aimed to roughly mimic an average head size and a minimal coil-cortex distance of 10 mm as worst case scenario.

Reconstruction from physical measurements
A purpose-built setup (MagProbe, Skjøt Consulting Aps, Denmark; see [cite Maria] for details) with a three-axis Hall probe moved by stepper motors was used for measuring the magnetic flux density of a MagVenture MC-B70 coil in three dimensions. The sampled volume had a maximal area of 28x28 cm² parallel to the coil and extended ~24 cm in height. The closest point was 10 mm away from the coil. A part of the volume was V-shaped to align with the coil geometry. The sampling resolution was 8 mm in-plane and ~10 mm along the height. The field on both sides was acquired by turning the coil and repeating the measurements. The reconstruction method was applied to obtain the weights of magnetic dipoles placed on a regular grid with spacing of 5 mm covering positions inside the coil casing.

Sparsification of the coil model
Pilot tests revealed that models consisting of around 1000 dipoles placed on a regular 5 mm grid inside the coil casing approximated the field very well even in regions close to the coil. We then aimed to explore to what extent sparsification of the dipole model is feasible. We first identified a solution with many dipoles (termed full model in the following) and then attempted to represent the same A field with fewer active dipoles using a similar minimization procedure as before, but this time aiming to match both the A and B fields of the dense model. It is important to note the amount of training data is not limited in this setting as it is provided via simulations of the fields of the full dipole model. The input data consisted of simulations of the A and B fields based on the original denser dipole model in 5000 random positions sampled uniformly in a sphere of radius 80 mm located with the center at (x,y,z)=(0,0,85). In addition, 300 random points were sampled in a plane -15 mm behind the minimum z-coordinate of the dipoles of the full model. The extent of the plane in x-and y-direction was given by the coil casing.
In order to obtain approximate equal contributions of the A and B fields during sparsification of the dipole model, the simulated data and leadfields were normalized such that the linear problem to be solved was where full and full are the vectorized A and B fields simulated with the full dipole model, and ‖ full ‖ and ‖ full ‖ are the corresponding L2 norms. Leadfields and are for the A and B fields of the sparse model, and vector sparse contains the dipole moments of the sparse dipole expansions. We then used the orthogonal matching pursuit algorithm [13] with an efficient implementation via the K-SVD algorithm [14] to provide an approximation of the full L0 regularization path of sparse in the equation above. We sampled the dipole positions for the sparse solution in a denser grid (with 3 mm spacing) within the coil casing. However, in practice we found that the final solution was quite insensitive to the choice of dipole positions.

Results
Our approach successfully recovers the A and B fields of the simulated non-flat figure-8 coil even when B field data of only in a few planes was used for fitting (Fig. 1a). The average residual error falls below 0.01 once the SNR simulated ground-truth B field exceeds 10 dB. This SNR level is far lower than the SNR of the real B fields measured with our setup (where the between split residual indicates an effective SNR of 31 dB), ensuring high reconstruction accuracy for real data. However, one plane on the backside of the coil is required to obtain an accurate estimation of the A field (see results for 4 vs. 3 planes in Fig. 1a). Of note, this plane is still required when the B field is measured densely in the region in front of the coil (data not shown).
As our approach uses a dipole expansion of the coil fields, the residual increases quickly for positions very close to the coil (Fig. 1b shows results for a SNR of 20 as example). However, for 4 "measurement" planes, the A field that is used as input to the electric field simulations is sufficiently accurate already a few millimeters away from the coil (Fig. 1d shows the corresponding dipole model).

7/13
The reconstruction from measured data of a MC-B70 coil works similarly well as for the simulated test case, as evident from the predictability-reproducibility curves in Figure 1c. The corresponding B and A fields are visualized in Figs. 2a&b, and the resulting dipole model is depicted in Fig. 2c ("full" model).
When sparsifying the dipole model, a natural tradeoff occurs between the number of dipoles used to represent the coil and the minimal distance to the coil surface at which the dipole field approximation is still adequate (Fig. 2d). Here, we evaluated the relative error for a coil to cortex distance, x, as the relative error on a half-sphere located 85 mm below the coil and with a radius of 85-x mm. Ensuring a relative error of the A field of less than 0.01 for a coil to cortex distance of 5 mm or more resulted in 74 dipoles as visualized in figure 2c ("sparse" model).

Discussion
Our new method successfully reconstructs the A and B fields of TMS coils from measurements of their magnetic flux density, as demonstrated for both simulated ground truth and real measurement data. In contrast to our previous approach [5], it works for arbitrary winding geometries rather than only for flat coils and gives accurate results also for sparse input data. Here, we exemplarily tested sparsification of the input data along the z-axis, and we supply example scripts and data online that can be used to further pre-plan and optimize sparse sampling strategies that are adapted to the constraints of the specific measurement equipment.
In addition, our method allows for a post-hoc sparsification of the coil model with a flexible tradeoff between number of dipoles and the accuracy of the fields at a desired minimal distance. For the tested figure-8 coil, a model with 74 dipoles already gave a good accuracy for the A field at 5 mm distance, and a further reduction seems feasible when the aim is to guarantee accurate fields in the brain. While fast multipole methods [15,16] can be used to obtain the field from many sources in ( ) complexity, sparse dipole representation are still attractive in applications where computational efficiency is of key importance, such as updating electric field simulations in real-time [17] or for grid-search to obtain an optimal coil position [18].
Dipole expansions are attractive as they provide a compact representation and good approximation of fields distant from the source region. While the approximation will deteriorate quickly very close to the coil, this seems unproblematic for our application. The accuracy of the coil model is limited by the quality of the B field data, and hence requires a measurement setup which provides both accurate probe positions and B field measurement. Interestingly, information about the magnetic field beyond the reconstructed region was required to ensure adequate reconstruction of the A field. However, this information can be quite sparse as exemplified by adding one plane of data behind the coil in the current application. In addition to measured magnetic flux density data, the method requires the specification of a volume in which the dipoles can be placed, but no specific knowledge of the geometry of the coil windings. In practice, limiting the dipoles to a volume that approximates the coil casing worked well for us.
The code and usage examples are available at github.com/simnibs/dipole-fit under the GNU General Public License Version 3 to facilitate the adoption of our method. Figure 1 (a) Fitting of magnetic dipole models to simulated magnetic flux density data used as ground truth for varying signal-to-noise ratios (SNR). The magnetic flux density B and the corresponding magnetic vector potential A were obtained for the simulated figure-8 coil shown in subfigure d, using analytical expressions [19] for a current flow of 1 A. The signal-to-noise ratio (SNR) of B was controlled by adding multiplicative Gaussian i.i.d noise and the resulting data was provided as input to the model fitting. The data was sampled either only from 3 planes above the coil (at distances z=33.7, z=73.5 and z=113.2 mm) or additionally from a 4 th plane placed below the coil (z=-34.5 mm). The plot shows the relative sum of squares error for the reconstructed B and A fields evaluated in a sphere centered 85 mm below the coil surface (center at (x,y,z)=(0,0,85) mm) and having a radius of 75 mm. While the fit of the reconstructed B improves continuously with increasing SNR, the fit of the reconstructed A levels off at higher SNRs (3 planes above) unless information about the magnetic flux density below the coil is provided as well (4 planes). (b) Error as function of the coil to cortex distance to the coil for a SNR of 20. The latter is a conservative estimate of the lower bound of the SNR achieved in the real measurements. This relative error is measured on the surfaces of concentric half-spheres centered 85 mm below the coil surface (center at (x,y,z)=(0,0,85) mm). The radii of the half-spheres were varied to obtain the minimal distances to the origin stated on the x-axis. (c) Predictability-Reproducibility curves when varying the regularization parameter α. The blue line (3 planes above) and orange line (4 planes) correspond to fits to the simulated magnetic flux density of the figure-8 coil shown in subpanel d for a 10/13 SNR of 20dB. The green line indicates the fitting results to magnetic flux density data of a MagVenture MC-B70 coil measured densely in a 3D volume around the coil. Predictability is measured as the average coefficient of determination (R) of the reconstructed B across splits. Likewise, reproducibility of the fitted dipole moments m was assessed as the coefficient of determination of the two half-splits realizations for m. The red points denote the optimum as determined by the minimum Euclidean distance to (1,1). The blue points mark the positions of highest reproducibility. (d) Visualization of the simulated figure-8 coil with titled wings (angle ±11.5°). Each wing consisted of 10 wire loops (diameters equally spaced between 27.0 mm to 97.0 mm). The fitted magnetic dipoles obtained for data sampled from 4 planes at an SNR of 20dB are shown as blue and red arrows. The dipole positions were predefined on a regular grid inside the coil casing and the dipole moments then fitted to best explain the sampled B data. The corresponding reconstructed B for a distance of z=23.8 mm is shown in the plane above. The fitted magnetic dipoles inside the casing of the MC-B70 coil are shown as blue and red arrows. The dipole positions were predefined on a regular grid inside the casing and the dipole moments then estimated to best fit the measured B. The left panel corresponds to the full model with 1517 dipoles that was fitted without enforcing additional sparseness. The right panel corresponds to a sparse model with 74 dipoles that was fitted to obtain a relative residual error of maximally 1% (compared to the full model) for coil to cortex distances of 5 mm or more. (d) Dependence of the accuracy of the reconstructed A compared to the full model on the number of dipoles for three different coil to cortex distances (blue 5 mm, orange 10 mm and green 20 mm). The former corresponds to a coil model that gives accurate electric field estimates already at positions very close to the coil (e.g. inside the scalp), while the latter corresponds to a coil model with good accuracy for positions in the brain.