EEG parametric leadfield surrogate model¶
Starting from one of the previously generated parametric solutions, we can create a surrogate model to generate any new leadfield matrix for a set of electrical conductivities.
The computation of this surrogate model for a large leadfield matrix requires a large amount of memory. You should only perform this time consuming task if you are sure the output can fit in the RAM of your computer.
First, we load the parametric solution.
from shamo.eeg import SolParamEEGLeadfield solution = SolParamEEGLeadfield.load("../../derivatives/eeg_leadfield/parametric_ssp-dist/parametric_ssp-dist.json")
Next, as always, we load the class corresponding to the object we want to build. Here, it is the
The surrogate model is built with the
fit() function. To speedup the process, we can set the n_proc parameter.
from shamo.eeg import SurrEEGLeadfield surrogate = SurrEEGLeadfield.fit("eeg_param_leadfield_ssp-dist_surr-mat", "../../derivatives/eeg_leadfield/", solution, n_proc=8)
The resulting object can be used to generate a bunch of leadfield matrices with the
import numpy as np sols = surrogate.predict_sol("predict", surrogate.path, np.array([[0.5, 0.5, 0.5]]))