{ "cells": [ { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "EEG parametric leadfield surrogate model\n", "========================================\n", "\n", "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.\n", "\n", ".. warning::\n", "\n", " 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.\n", "\n", "First, we load the parametric solution." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from shamo.eeg import SolParamEEGLeadfield\n", "\n", "solution = SolParamEEGLeadfield.load(\"../../derivatives/eeg_leadfield/parametric_ssp-dist/parametric_ssp-dist.json\")" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Next, as always, we load the class corresponding to the object we want to build. Here, it is the :py:class:`~shamo.eeg.leadfield.surrogate.SurrEEGLeadfield` class.\n", "\n", "The surrogate model is built with the :py:func:`~shamo.eeg.leadfield.surrogate.SurrEEGLeadfield.fit` function. To speedup the process, we can set the `n_proc` parameter." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from shamo.eeg import SurrEEGLeadfield\n", "\n", "surrogate = SurrEEGLeadfield.fit(\"eeg_param_leadfield_ssp-dist_surr-mat\", \"../../derivatives/eeg_leadfield/\", solution, n_proc=8)" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "The resulting object can be used to generate a bunch of leadfield matrices with the :py:func:`~shamo.eeg.leadfield.surrogate.SurrEEGLeadfield.predict` and :py:func:`~shamo.eeg.leadfield.surrogate.SurrEEGLeadfield.predict_sol` methods." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "sols = surrogate.predict_sol(\"predict\", surrogate.path, np.array([[0.5, 0.5, 0.5]]))" ] } ], "metadata": { "kernelspec": { "display_name": "shamo", "language": "python", "name": "shamo" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }