EEG parametric leadfield sensitivity analysisΒΆ

As for the surrogate model in the previous example, we have to build a simple model from the parametric solution generated before. Since the goal of this example is to compute the Sobol sensitivity indices, we have to produce a scalar value representing the full matrix and then build the surrogate model.

The first steps are the same as before.

[ ]:
from shamo.eeg import SolParamEEGLeadfield

solution = SolParamEEGLeadfield.load("../../derivatives/eeg_leadfield/parametric_ssp-grid/parametric_ssp-grid.json")
[ ]:
from shamo.eeg import SolEEGLeadfield

reference = SolEEGLeadfield.load("../../derivatives/eeg_leadfield/single_ssp-grid/single_ssp-grid.json")

We then define the metric function that takes both a reference matrix and another matrix to compare to. This function must return a single scalar value.

[ ]:
import numpy as np

def metric(ref, mat):
    return np.linalg.norm(ref - mat, "fro")

Next, we use the SurrEEGLeadfieldToRef class to build such model and fit it with the metric function as a parameter.

[ ]:
from shamo.eeg import SurrEEGLeadfieldToRef

surrogate = SurrEEGLeadfieldToRef.fit("eeg_param_leadfield_ssp-dist_surr-toref", "../../derivatives/eeg_leadfield/", solution, ref=reference, metric=metric)

In the end, we simply have to compute the Sobol indices for this model. They are both returned as a dictionary and stored as a JSON file in the directory of the object.

Note

This method computes the first, second and total Sobol sensitivity indices for the surrogate model with regard to all the varying parameters.

[ ]:
s_i = surrogate.gen_sobol()