Introduction

This article introduces the ZeffiroFootnote 1 interface (ZI) version 2.2 for electromagnetic brain imaging and investigations. ZI aims to provide an accessible and multi-modal open-source platform for finite element method (FEM) (Braess 2001) based forward and inverse computations in the Matlab (TheMathWorks Inc.) environment. The FEM is widely applied for modeling electromagnetic fields in a bounded domain, such as the brain and the head (de Munck et al. 2012; Monk 2003). It allows one to discretize realistic three-dimensional tissue parameter distributions in an accurate way, including advanced features such as complex internal boundary layers and anisotropic tissues such as the fibrous white matter of the brain (Rullmann et al. 2009). The FEM can be applied to model an electromagnetic source within the brain (Pursiainen et al. 2016b; Miinalainen et al. 2019) and, thereby, to construct a lead field (LF) matrix to localize brain activity in electro-/magnetoencephalography (EEG/MEG) (Hämäläinen et al. 1993; Niedermeyer and da Silva 2004).

The same quasi-static set of Maxwell’s equations that predicts the electric potential field of a neural source can be applied also to model the effect of current injections, where either direct or alternating currents applied through electrodes act as the source of the electromagnetic field. Such an approach is used, for example, in the electrical impedance tomography (EIT) (Cheney et al. 1999) in which the goal is to map the conductivity distribution or its perturbations within a given domain. EIT constitutes a non-linear inverse problem which can be linearized with respect to a given background conductivity distribution to obtain a LF matrix, i.e., a linearized forward model. The FEM is a powerful tool in EIT (Vauhkonen 1997), since it does not set any major restrictions for the conductivity distribution. In contrast, the boundary element method (BEM) (He et al. 1987), which is the predominating method in EEG/MEG, sets the conductivity to be a compartment-wise constant parameter, limiting its practical usage in EIT.

Until recently, the FEM has been considered as computationally heavy for discretizing the complex geometry of the brain. To tackle this issue, ZI uses graphics processing unit (GPU) acceleration. It includes forward solvers for EEG/MEG and linearized EIT as well as a set of inverse solvers based on the hierarchical Bayesian model (HBM) which was introduced for EEG/MEG in Calvetti et al. (2009). The ZI platform and function library has been designed to be easily expandable and to allow implementing virtually any FEM based forward model which can be formulated as a product between a LF matrix and a candidate solution vector.

In this paper, we briefly review the mathematics behind ZI, describe the principal operations and usage, and introduce some central points for the developer perspective. We report the results obtained in EEG and EIT inversion tests performed with real and syntetic data, respectively, and demonstrate numerically how the inversion parameters affect the EEG inversion outcome in HBM.

Methodology

The electric potential field u in the head model Ω is assumed to satisfy the elliptic partial differential equation (PDE) of the form ∇⋅ (σu) = ∇⋅Jp, where σ is the conductivity distribution of the head and Jp is the primary current density of the neural activity. This equation follows from the current preservation condition ∇⋅Jt = 0 for the total current density Jt = Jpσu, that is, the sum of Jp and the volume current density − σu. The electromagnetic field within Ω can be evoked either by Jp acting as the source, which is the case in EEG/MEG, or by an external source, e.g., a current pattern injected through contact electrodes in EIT. The dependence between the measurements y and the unknown of the inverse problem x in question, e.g., a source localization problem, is here assumed be of the following linear form

$$ \mathbf{L} \mathbf{x} = \mathbf{y} + \mathbf{n}, $$
(1)

where L is the LF matrix and n is the noise vector. The LF matrices for EEG and linearized EIT inverse problem can be formed as shown in Appendix A.1.

Primary Current Model

ZI utilizes the H(div) source model (Pursiainen et al. 2016b) in which both linear and quadratic basis functions constitute the primary current density Jp. In Miinalainen et al. (2019); Pursiainen et al. (2016b), this model was shown to surpass the accuracy of the classical direct source modeling approaches based on the partial integration and St. Venant’s principle and to be especially advantageous for thin cortices as well as for inverting data.

A Cartesian set of source orientations can be obtained from a mesh-based set using the Position Based Optimization (PBO) method (Bauer et al. 2015) with an adaptive (Miinalainen and Pursiainen 2017) 10-source stencil in which 4 face and 6 edge functions are applied for each element containing a source (Pursiainen et al. 2016b). Alternatively, the Whitney model (Bauer et al. 2015), i.e., the 4-source stencil (4 face functions), can be used. Moreover, a set of Whitney functions can be applied without interpolation. That is, the LF matrix can be formed directly using the mesh-based set of basis functions as suggested in Miinalainen and Pursiainen (2017). In each active tissue compartment, the sources can either be normally constrained or unconstrained with respect to the surface of the compartment (Creutzfeldt et al. 1962; Hari et al. 2018). The source positions are randomly (uniformly) distributed in each case.

Conductivity Distribution

The current FE meshing strategy employed in ZI treats the conductivity as an isotropic piecewise (element-wise) constant distribution, i.e., a single scalar value is associated with each element in the FE mesh. However, when evaluating an LF matrix, ZI allows the conductivity distribution σ to be anisotropic, i.e., tensor-valued: the -th row of the form (σ11,σ22,σ33,σ12,σ13,σ23) within a multi-row array is associated with the symmetric conductivity tensor σij, i = 1,2,3, j = 1,2,3 (σij = σji) in the -th element.

HBM

The inverse tools of ZI are based on the HBM (Calvetti et al. 2009; O’Hagan and Forster 2004) which enables finding a reconstrution for the unknown x as either the posterior maximizer, i.e., maximum a posteriori (MAP) or the conditional mean (CM) of the posterior probability density. In HBM, the posterior probability for x is defined via choosing the standard deviation of a Gaussian likelihood density, the hypermodel, i.e., the gamma (G) or inverse gamma (IG) hyperprior determining the actual prior, and the shape and scale parameter β and 𝜃0 for the hyperprior. For a given measurement vector y, the Bayes formula (O’Hagan and Forster 2004) for the posterior is of the form

$$ p (\mathbf{x} \mid \mathbf{y}) = \frac{p(\mathbf{x}) p(\mathbf{y} \mid \mathbf{x})} {p(\mathbf{y})} \propto {p(\mathbf{x}) p(\mathbf{y} \mid \mathbf{x})}, $$
(2)

where p(x) is the prior density and p(yx) the likelihood function (Schmidt et al. 1999). Here, the noise term n, which together with the forward model (1) implies the likelihood p(yx), is assumed to be a Gaussian zero-mean random vector with independent entries.

In HBM, the prior can be expressed in the following hierarchical form p(x,h) ∝ p(𝜃)p(x𝜃), where 𝜃 is the primary hyperparameter of the model. The conditional part p(x𝜃) of the prior is a zero-mean Gaussian density, whose diagonal covariance matrix is predicted by the hyperprior p(𝜃). The hyperprior is assumed to have a long-tailed density, implying that x is likely to be a sparse vector corresponding to a well-localized (focal) volumetric distribution. In ZI, it is either G or IG density (Calvetti et al. 2009), which are controlled by the shape and scale parameter β and 𝜃0. The G and IG hyperprior can be coupled into a single model in a straightforward way, since the reciprocal 𝜃− 1 of a G-distributed random variable 𝜃 with respect to β and 𝜃0 is IG-distributed w.r.t. β and \(\theta _{0}^{-1}\).

A description of the IAS algorithm applied in ZI can be found in Appendix B. ZI’s CM estimation technique is based on the Gibbs sampler algorithm (Spitzer 1971; Murphy 2012) according to (Calvetti et al. 2009).

Hardware Requirements

ZI is principally designed to be used with a workstation or a high-end desktop computer with tens of gigabytes of RAM, a multi-core CPU and one or more GPUs. When generating the FE mesh and the LF matrix ZI is likely to allocate several gigabytes of RAM. A one-millimeter FE mesh resolution might lead to 64 GB of motherboard RAM and 2–4 GB of GPU RAM allocation during the forward computations. The resulting FE mesh will consist of 3-4 M nodes and 20-30 M elements, and the eventual project size, when stored on a hard disk, will be 0.5–1 GB.

GPU Function

ZI utilizes a GPU to accelerate the FE mesh generation process, forward and inverse computations, source interpolation and decompositions, as well as to speed up 3D visualizations. This is vital in order to achieve a convenient, around one hour computing time for a one-millimeter FE mesh resolution which has been shown to be essential in order to obtain physiologically accurate inverse estimates (Rullmann et al. 2009). A GPU is a parallel processing unit which has somewhat limited RAM compared to the motherboard. It can handle computation intensive operations very effectively, while memory intensive operations should be avoided. The operations related to forward and inverse computations can be accelerated due to the fast processing of matrix-vector products in a GPU. The other GPU operations are mainly based on the acceleration of find and sort routines, evaluating those as blocks rather than individual entries.

Forward Simulation

In the Matlab environment, the most essential speed-up gain is related to the sparse FE matrix-vector products which need to be evaluated iteratively in the forward simulation phase. The GPU-parallelization of the forward simulation is especially important, because Matlab currently handles the sparse matrix products in a single processor thread. To evaluate the lead field matrix as described in Appendix A, ZI uses the preconditioned conjugate gradient (PCG) (Golub and van Loan 1989) method with a lumped diagonal preconditioner (LDP) in which each diagonal entry is obtained as the row sum of the absolute entry values. LDP is an advantageous preconditioner regarding the limited GPU memory. While LDP is not optimal with respect to minimizing the iteration steps needed for convergence, it enables establishing a fast forward solver due to the high parallel processing performance provided by a GPU.

IAS Iteration

In the IAS iteration (Appendix B), the most time consuming step is the third one, Eq. 7, in which the size of the matrix to be inverted is determined by the length of the data vector. If a high number of time steps will need to be processed, the fastest processing is obtained by evaluating the matrix-vector product of Eq. 7 in a GPU.

Interface Structure and Function

When started, ZI creates a single data structure (struct) zef in Matlab’s base workspace. All the parameters and variables, such as the lead field matrix, measurement data and reconstruction, can be accessed via the zef structure. The basic workflow consists of three phases illustrated in Fig. 1. In this section, we briefly review the workflow and introduce the most important fields of zef for each phase.

Fig. 1
figure 1

The basic three-phase workflow in ZI. In phase 1, the head model is first defined using the segmentation tool, after which, in phase 2, the three-dimensional FE mesh and the LF matrix are generated with the mesh tool. Finally, in phase 3, the inverse tools can be applied to reconstruct and analyze parameter distributions, e.g., the primary current density of the brain activity. The parcellation tool can be applied in each of the phases 1–3 to assist decomposing the brain into a finite set of ROIs

Segmentation Tool

In the first phase, a surface segmentation describing different tissue structures and properties within Ω is defined using the segmentation tool (Fig. 2). A triangular surface mesh for each tissue type is imported in ZI as an ASCII file. In the current version, a single head model can contain up to 27 different tissue compartments. Moreover, several surface meshes (sub-meshes) can be merged together into a single compartment, e.g., the left and right hemisphere of the cerebral cortex. A multi-compartment segmentation can be defined in a single initialization (.INI) file which allows importing a complete head segmentation at once. The nodes and points of each surface mesh can be stored either in two separate .DAT files or in a single .ASC file exported from the FreeSurferFootnote 2 Software Suite (Fischl 2012).

The default set of compartments includes white matter, grey matter, cerebrospinal fluid (CSF), skull, and scalp, whose default conductivity values are 0.14, 0.33, 0.0064, and 0.43 S/m, respectively, according to Dannhauer et al. (2011); Vorwerk et al. (2014). Each compartment can be defined as active or inactive. The set of active compartments contains the DOFs of x. In EEG/MEG, the activity can be either constrained or unconstrained. In the former case, it is restricted into the direction of the surface normal, and in the latter case, it can have any orientation.

Mesh Tool

Fig. 2
figure 2

A screenshot of ZI with figure, mesh, parcellation, and option tool opened

Fig. 3
figure 3

Top row: Surface and volume visualizations of the head model in ZI. Bottom row: FreeSurfer-based cortical parcellation with 36 Desikan-Killiany labels

In the second phase of the workflow, a uniform tetrahedral mesh is generated based on the surface segmentation. The meshing parameters can be defined in the mesh tool. The meshing process proceeds from the innermost (detail) compartment to the outermost one. It allows the tissue boundaries to intersect each other which is necessary with a real segmentation obtained from magnetic resonance imaging (MRI) data. Each compartment can be given a priority which is referred to if a tetrahedron has nodes in two or more compartments. The priority parameter allows fine-tuning the width of the thin tissue layers, e.g., the skull: the lower the value the higher the priority. The FE mesh can be also smoothed using the Bi-Laplacian smoothing flow (Ohtake et al. 2001; Pursiainen 2012). After generating the mesh, the LF matrix can be computed for a selected imaging modality and a given number of the degrees of freedom (DOFs). Finally, an interpolation process connecting the DOFs and the FE mesh nodes needs to be performed, to enable inversion of measurement data.

Together with the figure tool, the mesh tool allows one to visualize both the surface segmentation and the volumetric FE mesh, or any surface or volumetric distribution (reconstruction) defined on those. The visibility of a compartment can be selected in the Segmentation tool. The options tool includes additional options which control, e.g., the colormap, scale, vector component, and the index of the sub-mesh for the visualized distribution, e.g., that of the left or right hemisphere (see Section “Segmentation Tool”). An example of a multi-layer surface segmentation and the resulting volumetric mesh created with ZI are shown in Fig. 3. For further code development, the most important fields of zef are the following:

  1. 1.

    zef.nodes and zef.tetra store the nodes and tetrahedra of the FE mesh, respectively;

  2. 2.

    zef.L is the lead field matrix;

  3. 3.

    zef.source_positions stores the source positions corresponding to the columns of zef.L in the respective order. This array contains the DOF positions also if they do not represent neural sources, which is the case in EIT.

  4. 4.

    zef.source_directions contains the source orientations. If Cartesian orientations are used, this field is empty, and the source orientation for the columns of zef.L is given by the following regular pattern: position 1, xyz; position 2, xyz; position 3, xyz, etc.;

  5. 5.

    zef.source_interpolation_ind stores the indices that connect the finite element mesh with the DOFs;

  6. 6.

    zef.h_axes1 stores the axes handle of the figure tool.

Inverse Tools

In the third phase, the measurement data are imported and, after that, a reconstruction for x can be obtained using one of the inverse tools. A MAP estimate can be obtained via the IAS method using one of the following tools:

  1. 1.

    IAS MAP estimation which finds a MAP estimate for the whole domain;

  2. 2.

    IAS MAP estimation ROI which focuses on a ROI;

  3. 3.

    IAS MAP multiresolution which explores multiple different resolutions.

A CM estimate can be obtained for a ROI using the Hierarchical Bayesian sampler tool. For external inverse procedure development, the most important fields are the following:

  1. 1.

    zef.measurements is the set of measurements to be inverted; this field can be a matrix or a cell array with the number of rows and columns equal to that of zef.L and the time steps in the dataset, respectively;

  2. 2.

    zef.reconstruction is the reconstruction of x corresponding to the set of source positions and orientations.

Parcellation Tool

The parcellation tool (Fig. 2) allows importing a parcellation created with the FreeSurfer Software Suite. A single parcellation consists of a file containing a colortable (.MAT) and another one including the points/labels (.ASC). After importing, an interpolation process will need to be performed to connect the points with the DOFs. The parcellation can be used as a priori information in the reconstruction or visualization stage. After obtaining a reconstruction, one can evaluate a time series of the activity for each region present in the parcellation. The time series can represent, e.g., the maximal or median activity within a region. The purpose of the time series is to enable the analysis of different statistical properties and connectivity of the activity over a time interval. In the current version, e.g., the amplitude, standard deviation, correlation, covariance, and dynamic time warping (DTW) (Sakoe and Chiba 1978) measure can be evaluated. The most important fields w.r.t. the parcellation tool are the following:

  1. 1.

    zef.parcellation_colortable and zef.parcellation_points store the colortable and points of the parcellation;

  2. 2.

    zef.parcellation_interp_ind contains the indices connecting the parccellated brain regions and the DOFs;

  3. 3.

    zef.parcellation_time_series stores the time series obtained for the brain regions after reconstructing the brain activity.

Plugin Utility

ZI can be extended via the plugin utility. The list of plugins is defined in the zeffiro_plugins.ini file which is located in ZI’s root folder. A menu item will be created for each listed plugin. The Hierarchical Bayesian sampler tool (Spitzer 1971; Murphy 2012) is included in the code package as an example plugin (HBSampler).

Numerical Experiments

In the numerical experiments, we demonstrate the practical performance of ZI and the IAS MAP estimation technique via numerical experiments in which EEG and EIT inversion is tested with real and synthetic data, respectively. We also analyze the effect of hyperprior and scale parameter on the source localization in EEG using simulated measurements.

EEG Inversion Test

Fig. 4
figure 4

A butterfly plot of EEG inversion test (Section “EEG Inversion Test”) data which were obtained by averaging 58 epileptiform discharges between -5 and 5 s. The vertical axis shows the measured voltage in microvolts, and the horizontal axis the measurement time in seconds. The reconstruction was found for the zero time point 0 s which is indicated by the vertical dashed line

To enable comparability of the results to an existing solver, in this case that of the BrainstormFootnote 3 software (Tadel et al. 2011), EEG source localization accuracy was examined by inverting Brainstorm’s EEG and epilepsy tutorial datasetFootnote 4 which was used with the consent of Prof. A. Schulze-Bonhage, Epilepsy Centre, University Hospital Freiburg, Germany. The dataset was obtained for a patient who had suffered from focal epilepsy with focal sensory, dyscognitive and secondarily generalized seizures since the age of eight years. It consists of 58 epileptiform discharges (spikes) which were recorded at 256 Hz frequency and detected using Brainstorm by the epileptologists in Freiburg. An invasive EEG study concentrating on the same subject can be found in Dümpelmann et al. (2012).

Following the tutorial, the measurement data to be inverted, depicted in Fig. 4, were obtained for 29 electrodes applying an epoching time interval between -5 and 5 s w.r.t. the time point of the inverted data. All the non-EEG channels have been removed from the measured data. The brain activity was reconstructed via two steps of the IAS MAP estimation algorithm with low-cut and high-cut frequency of 0.5 Hz and 80 Hz, assuming that the likelihood standard deviation is 3 % of the maximum entry in the data, and selecting the shape and scale parameters as β = 1.5 and 𝜃0 = 1E-12. The head model linked to the dataset consists of the surface meshes of the scalp, skull, CSF, grey matter, and white matter. ZI’s default conductivity values were used. The LF matrix was generated for 100000 sources using 1 mm mesh resolution. The reconstructions were obtained with ZI’s IAS MAP estimation inverse tool.

EIT Inversion Test

EIT inversion was examined numerically using the population head modelFootnote 5 which includes a scalp, skull, CSF, ventricle, grey matter, and white matter compartment (Lee et al. 2016). The default conductivity values were applied, associating the condutivity of the ventricles with that of the CSF. A total of 72 ring electrodes with an assumed 1 kOhm impedance and an outer and inner diameter of 10 and 7.5 mm, respectively, were modeled through the complete electrode model (CEM) described in Appendix A.

The head model was discretized using 1 mm mesh resolution. The FE mesh is shown in Fig. 6. A LF matrix was evaluated for a total number of 5000 DOFs using the approach presented in Appendix A and the original piecewise constant conductivity as the background distribution, i.e., the point of the linearization. The DOFs were distributed in the CSF, white matter and grey matter compartment.

The synthetic data were generated by perturbing the conductivity inside the brain within a spherical 30 mm diameter sub-domain representing an intracerebral hemorrhage (Broderick et al. 1993). Following, e.g., Li et al. (2017); Tang et al. (2010), the magnitude of the perturbation was set to be + 0.73 S/m and the signal-to-noise ratio was assumed to be 60 dB. The measurement errors consisted of additive Gaussian zero-mean white noise.

The likelihood standard deviation was set to be 12 % conciding approximately with the level following from the noise model. The IG hyperprior was employed selecting the shape and scale parameters as β = 1.5 and 𝜃0 = 0.001. To reconstruct the deep-lying anomaly, the total set of DOFs was decomposed into randomized 300 subsets which were formed w.r.t. an equal number of randomly (uniformly) distributed center points via the nearest point interpolation technique. The MAP estimate was found by performing two steps of IAS iteration for altogether 100 such randomized decompositions. A serial approach was adopted: the estimate obtained for one decomposition was set as the initial guess for the next one. The final reconstruction was produced as the mean of the resulting 100 MAP estimates.

The motivation to use averaging was to reduce the effect of decomposition-related artifacts which we assumed to be identically distributed for each separate decomposition and, thus, converge towards an expectation of an asymptotical Gaussian distribution based on the law of random numbers and the central limit theorem (O’Hagan and Forster 2004). The averaged reconstruction was obtained using the IAS MAP multiresolution inverse tool which allows averaging the reconstruction over one or more resolution levels and multiple randomized decompositions. The resolution is determined by the number of subsets within a single decomposition which is here 300 in each.

Hypermodel and Parameter Selection

The HBM approach requires selecting the hypermodel together with an appropriate value for the shape and scale parameter β and 𝜃. To investigate the effect of the parameter selection on the IAS MAP estimation process, we compared the localization of a simultaneously active pair of synthetic deep and superficial 10 nAm source in the case of EEG. The reconstruction was found as the center of mass of the primary current distribution within two 30 mm ROIs centered at the actual source locations. The accuracy was measured by evaluating the position (mm) and orientation (degree) difference with respect to the exact sources. As the computation domain we used a six-compartment (white matter, grey matter, CSF, compact skull, spongious skull, scalp) head model corresponding to a 49-year old male subject with ZI’s default conductivity values. For the spongious part of the skull 0.028 S/m was selected (Vorwerk et al. 2014). The EEG LF matrix was formed for a cap of 72 electrodes. The effects of choosing the hyperprior h and scale parameter 𝜃0 were examined for the following four pars: (i) h = G,𝜃0 = 1E − 5, (ii) h = IG,𝜃0 = 1E − 5, (iii) h = G,𝜃0 = 1E − 9, and (iv) h = IG,𝜃0 = 1E − 9, respectively. The shape parameter β was set to be β = 1.5 in each case. Gaussian white noise with 2 % relative standard deviation was added in the data. Each reconstruction was evaluated for 50 different realizations of the noise vector. The inverse tool applied in the experiment was ZI’s IAS MAP estimation ROI.

Fig. 5
figure 5

A surface and volume visualization of reconstructed brain activity (amplitude) obtained in the EEG inversion test (Section “EEG Inversion Test”). The left and right images correspond to G and IG hyperprior, respectively. Top row: An axial projection of the reconstructions interpolated on the surface of the grey matter compartment. Bottom row: The volumetric reconstructions cut by a coronal plane at the location of the maximal activity. The reconstructions have been normalized to one

Fig. 6
figure 6

Left: An illustration of the synthetic hemorrhage (grey sphere) which was applied to generate the data of the EIT inversion tests. The diameter of the sphere was 30 mm and its conductivity was set to be 0.73 S/m higher compared to its surroundings. The unperturbed background conductivity distribution was assumed to be constant in each tissue compartment including white matter (white), grey matter (grey), CSF (green and blue), skull (khaki), and scalp (brown). The CEM electrodes (Appendix A.1) are shown as surface patches (black rings): Center: An averaged reconstruction of the synthetic hemorrhage found using the IAS MAP multiresolution inverse tool. The final distribution was produced as an average of altogether 100 different MAP estimates corresponding to different randomized decompositions of 300 DOFs as explained in Section “EIT Inversion Test”. Right: A reconstruction (an unaveraged MAP estimate) found for a single decomposition of 300 DOFs. The reconsructions have been normalized to one

Fig. 7
figure 7

Top row: Examples of the center of mass (red pin) found for the deep and superficial source (1 and 2, respectively) in the cases (i)–(iv) with synthetic EEG data and the noise level of 2 %. The exact position of each source is also depicted (cyan pin). Bottom row: Box-plots showing the distributions (i)–(iv) of the position (millimeter) and angle error (degree) found for sources 1 and 2 and 50 different realizations of the noise vector

Results

ZI’s forward simulation performance was evaluated w.r.t. the computing time for the head model described in Section “Hypermodel and Parameter Selection”. The mesh generation, LF matrix evaluation and interpolation processes took 21, 39 and 3.5 minutes, respectively, using NVIDIAFootnote 6 Quadro P6000 GPU. GPU acceleration was also found to be necessary to obtain a reasonable computing time as it sped up these routines by more than a factor of ten.

EEG Inversion Test

The results of the EEG inversion test can be found in Fig. 5 which displays the reconstructed brain activity for the surface of the cortex and a volume cut corresponding to the location of the maximal activity. The reconstruction obtained with the IG hyperprior was observed to be more focal than the one corresponding to G. The surface visualizations obtained for the G and IG hyperprior confirm similar active area as illustrated in Brainstorm’s EEG and epilepsy tutorial, especially, compared to the outcome of the Brainstorm’s maximum of entropy on the mean (MEM) framework solution. The volume cuts show the depth of the reconstructed activity.

EIT Inversion Test

In the EIT inversion test, the averaged reconstruction found for the synthetic hemorrhage matched well with its exact location, which is shown in Fig. 6. A visual comparison between the averaged and unaveraged and reconstruction (Fig. 6) suggests that the averaging process was beneficial w.r.t. the localization accuracy. The resolution (level of detail) of the averaged reconstruction seems to be refined compared to that of the unaveraged one. Moreover, using a comparatively low number of DOFs (here 300) in each randomized decomposition was found to be necessary for detecting the hemorrhage.

Hypermodel and Parameter Selection

Figure 7 illustrates the source localization results obtained in the hypermodel and parameter selection test. G was observed to perform comparably well for the superficial ROI and IG for the deep one. This is reflected by the cases (i) and (iv) in which the utmost position accuracy was obtained in these ROIs, respectively. Moreover, for G, the larger scale parameter value seemed preferable to the smaller one, while, for IG, the situation was the opposite. Regardless of the hyperprior, selecting a smaller scale parameter seemed beneficial for localizing the deep source until a certain level, where noise effects started to affect the reconstruction.

Discussion

This article introduced Zeffiro interface (ZI) version 2.2, a GPU accelerated Matlab tool for multi-modal FEM-based modeling of electromagnetic fields in brain imaging and investigations (Braess 2001; de Munck et al. 1988; Monk 2003). It was shown that, when aided by a state-of-the-art GPU, ZI allows one to invert a given set of EEG data for a physiologically accurate (Rullmann et al. 2009) one-millimeter volumetric multi-compartment head model within a reasonable one hour’s time. GPU acceleration is needed, specifically, in the forward simulation phase, that is, in the generation of the FE mesh and the LF matrix as well as in the interpolation process connecting the DOFs of the unknown with the nodes of the FE mesh. Since Matlab does not currently parallelize the sparse matrix operations in a CPU, the performance difference between CPU and GPU computations, both applicable in ZI, is particularly pronounced.

As the mutual performance of GPU- and CPU-based codes is strongly system-specific and depends on various factors in addition to the processors themselves, ZI was not directly compared to the alternative tools. These include, for instance, DuneuroFootnote 7 (Nüßing et al. 2019) and SimBioFootnote 8 (Fingberg et al. 2003) which are open source FEM libraries for EEG/MEG with similar functions as Zeffiro but utilizing C++ language. BrainstormFootnote 9 (Tadel et al. 2011) and FieldtripFootnote 10 (Oostenveld et al. 2011) are alternative packages for the Matlab platform. The core forward modeling approach of Brainstorm is the BEM (He et al. 1987). Fieldtrip does not have an advanced forward and inverse modeling functions. None of these are currently capable of advanced FEM or GPU computations. The MNE-PythonFootnote 11 toolbox (Gramfort et al. 2013) is the leading option for Python. It allows utilizing a GPU, but is, nevertheless, limited to a BEM-based forward simulation.

The present results suggest that ZI enables robust inversion of multi-modal data. Firstly, the reconstructions obtained for Brainstrom’s EEG and epilepsy tutorial dataset show that ZI’s forward and inversion methods can be applied to detect brain activity. Secondly, based on the numerical results obtained in the EIT inversion test, it seems that ZI can also be extended for non-linear problems and inversion of scalar-valued fields. The IAS MAP estimation technique was found to be applicable for EIT via averaging MAP estimates obtained for a randomized set of low-resolution domain decompositions. This technique might be usable also for other imaging modalities, for example, to localize deep brain activity. Furthermore, the present EIT solver might be adapted for other applications involving current injections, such as transcranial electric stimulation (Herrmann et al. 2013) in which the brain activity is evoked through external stimuli.

Based on the hyperprior and scale parameter selection experiment, IG seems to be an advantageous choice for the sub-cortical areas, whereas G seems preferable for the cerebral cortex. The scale parameter applied in the former case should be generally lower than in the latter one. This baseline is in parallel with the previous findings (Calvetti et al. 2009) and might be optimized later on. We also emphasize that the parameter selection is generally a complicated issue which is not covered completely in this study. For example, the effect of the shape parameter, which partially overlaps with that of the scale parameter, is omitted here.

Compared to the BEM, the FEM has at least two major advantages when applied in EEG/MEG. Firstly, while a BEM solver slows down if the surface mesh resolution or the number of surfaces grows, the computational performance of the FEM is virtually independent of these factors. ZI’s current design takes this aspect into account, as altogether 27 tissue compartments, each one composed of sub-entities if needed, can be included in a single head model. The uniform mesh generator is well-suited for multi-compartment meshing, since unlike many widely used software, e.g., TetGenFootnote 12 (Si 2015) and NetgenFootnote 13 (Schöberl 1997), it allows the tissue boundaries to intersect each other without collapsing. This is essential in practice, since the segmentation routines utilizing MRI data do not always render the surfaces smoothly. Moreover, ZI performs appropriately with a high surface resolution, thereby, allowing one to directly use the detailed surfaces exported from the FreeSurferFootnote 14 Software Suite (Fischl 2012).

The second major benefit of the FEM is that the conductivity distribution can be anisotropic (Güllmar et al. 2010; Rullmann et al. 2009). ZI’s forward simulation routines are currently capable of handling anisotropicity. The current meshing routine, however, generates an isotropic conductivity distribution. Generating or importing an anisotropic distribution, e.g., from diffusion-weighted MRI data, constitutes a potential topic for the future work.

Another potential direction is to develop the inversion methodology: one might apply the HBM for sub-cortical areas (Seeber et al. 2019), with non-diagonal prior covariance structures and/or with sampling-based posterior exploration techniques, e.g., the Gibbs sampler (Spitzer 1971; Murphy 2012). From the practical viewpoint, there is also an obvious need to develop tools for various purposes including epochs, the covariance of the measurements, and connectivity, e.g., phase-locking (Lachaux et al. 1999). Clinical studies would be needed to validate ZI for different applications and measurement situations. Providing command line executable scripts for performing the main operations without the graphical user interface, e.g., in a computing cluster, is also a potential option.