Skip to main content

Solve the M/EEG inverse problem using artificial neural networks with Python 3 and the MNE library.

Project description

ESINet: Electric source imaging using artificial neural networks (ANNs)

ESINet let's you solve the EEG inverse problem using ANNs.

ESINet Neural network design was created here



Dependencies:


Installation from PyPi

Use pip to install ESINet and all its dependencies from PyPi:

pip install ESINet

First steps

Check out one of the tutorials to learn how to use the package:

  • Base tutorial: Simulate data and train a ANN to predict some sources. Shows the most important functions of this package and serves as the easiest entry point.

  • Brainstorm Auditory example: This tutorial shows you how to use ESINet to predict the sources in word processing data. Code was partially used from the MNE tutorials



Workflow

ESINet is a lightweight package that provides all building blocks to use an ANN to solve the EEG inverse problem. It relies on mne) to handle all tasks related to EEG and Tensorflow to create, train and predict with the ANN.


The forward model

Knowing how cerebral currents will project to the scalp electrodes requires solving the forward problem. Fortunately, this problem has a unique solution! We provide a function to quickly create a forward model which supplies all assets required for the following processing steps:

pth_fwd = 'forward_models/ico3/'
sampling = 'ico3'
create_forward_model(pth_fwd, sampling=sampling, info=epochs.info)

The sampling defines the number of dipoles in your source model and thereby the resolution of your inverse solution. If you don't have powerful hardware we encourage to leave the sampling at 'ico3'.


Simulating EEG data

ANNs that find solutions to the inverse problem need to be trained to infer the dipole moments of your source model given the EEG.

You can create a set of sources using our high-level function:

sources_sim = run_simulations(pth_fwd, durOfTrial=0)

To simulate the corresponding EEG data with added noise you can use our function:

eeg_sim = create_eeg(sources_sim, pth_fwd)

You can visualize the simulated data with this code block:

%matplotlib qt
sample = 0  # index of the simulation
title = f'Simulation {sample}'
# Topographic plot
eeg_sim[sample].average().plot_topomap([0.5])
# Source plot
sources_sim.plot(hemi='both', initial_time=sample, surface='white', colormap='inferno', title=title, time_viewer=False)

Training

Now we want to train an ANN to infer sources given EEG data. Since we have simulated all the required data already we just have to load and train a ANN model.

To load our basic model:

# Find out input and output dimensions based on the shape of the leadfield 
input_dim, output_dim = load_leadfield(pth_fwd).shape
# Initialize the artificial neural network model
model = get_model(input_dim, output_dim)

Next, we train the model:

model, history = train_model(model, sources_sim, eeg_sim)

You have now trained your neural network - congratulations!

Testing the ANN

Let's see how your ANN performs! First, we have to simulate some data for evaluation:

# Simulate source
sources_eval = run_simulations(pth_fwd, 1, durOfTrial=0)
# Simulate corresponding EEG
eeg_eval = create_eeg(sources_eval, pth_fwd)

Next, we use the trained ANN model to predict the source given the EEG.

# Predict
source_predicted = predict(model, eeg_eval, pth_fwd)

Now let's visualize the result:

# Plot ground truth source...
title = f'Ground Truth'
sources_eval.plot(hemi='both', initial_time=0.5, surface='white', colormap='inferno', title=title, time_viewer=False)

# Plot the simulated EEG
title = f'Simulated EEG'
eeg_eval[0].average().plot_topomap([0], title=title)

# Plot the predicted source
title = f'ConvDip Prediction'
source_predicted.plot(hemi='both', initial_time=0.5, surface='white', colormap='inferno', title=title, time_viewer=False)


Feedback

Leave your feedback and bug reports at lukas_hecker@web.de.


Literature

Cite us using our preprint (publication is in review):

Hecker, L., Rupprecht, R., van Elst, L. T., & Kornmeier, J. (2020). ConvDip: A convolutional neural network for better M/EEG Source Imaging. bioRxiv.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ESINet-0.0.10.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ESINet-0.0.10-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file ESINet-0.0.10.tar.gz.

File metadata

  • Download URL: ESINet-0.0.10.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for ESINet-0.0.10.tar.gz
Algorithm Hash digest
SHA256 f868a60b5f3fa8750ce6b4b2c5a8648afe527b36345348197185ce171dd1b237
MD5 937db336d6920b58fbd9fb5d17d8c085
BLAKE2b-256 7f4487fb9d8f172894ac1102b829bde2dfaa8189bf5f7b155d97833c54f2f655

See more details on using hashes here.

File details

Details for the file ESINet-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: ESINet-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for ESINet-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 e4e7647b92e2d27721307dc99f13c76b8458fb6595db771ccb5031f35937ee2f
MD5 60d5d524191ce60c7b26f070c981d33b
BLAKE2b-256 236e42b918bd76fb57f6248259ba726179603d257b5db4f00998c7a5f75eea70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page