Artificial Neural Networks#

class invert.solvers.esinet.SolverCNN(name='CNN', **kwargs)#

Class for the Convolutional Neural Network (CNN) for EEG inverse solutions.

forward#

The mne-python Forward model instance.

Type

mne.Forward

apply_inverse_operator(mne_obj) mne.source_estimate.SourceEstimate#

Apply the inverse operator.

Parameters

mne_obj ([mne.Evoked, mne.Epochs, mne.io.Raw]) – The MNE data object.

Returns

stc – The mne Source Estimate object.

Return type

mne.SourceEstimate

apply_model(data) numpy.ndarray#

Compute the inverse solution of the M/EEG data.

Parameters

data (numpy.ndarray) – The M/EEG data matrix.

Returns

x_hat – The source esimate.

Return type

numpy.ndarray

build_model()#

Build the neural network model.

create_generator()#

Creat the data generator used for the simulations.

make_inverse_operator(forward, *args, n_filters='auto', activation_function='tanh', batch_size='auto', n_timepoints=20, batch_repetitions=5, epochs=300, learning_rate=0.001, loss='cosine_similarity', n_sources=10, n_orders=2, size_validation_set=256, epsilon=0.25, snr_range=(1, 100), patience=300, alpha='auto', **kwargs)#

Calculate inverse operator.

Parameters
  • forward (mne.Forward) – The mne-python Forward model instance.

  • n_filters (int) – Number of filters in the convolution layer.

  • activation_function (str) – The activation function of the hidden layers.

  • batch_size (["auto", int]) – The batch_size used during training. If “auto”, the batch_size defaults to the number of dipoles in the source/ forward model. Choose a smaller batch_size (e.g., 1000) if you run into memory problems (RAM or GPU memory).

  • n_timepoints (int) – The number of time points to simulate and ultimately train the neural network on.

  • batch_repetitions (int) – The number of learning repetitions on the same batch of training data until a new batch is simulated.

  • epochs (int) – The number of epochs to train.

  • learning_rate (float) – The learning rate of the optimizer that trains the neural network.

  • loss (str) – The loss function of the neural network.

  • n_sources (int) – The maximum number of sources to simulate for the training data.

  • n_orders (int) – Controls the maximum smoothness of the sources.

  • size_validation_set (int) – The size of validation data set.

  • epsilon (float) – The threshold at which to select sources as “active”. 0.25 -> select all sources that are active at least 25 % of the maximum dipoles.

  • snr_range (tuple) – The range of signal to noise ratios (SNRs) in the training data. (1, 10) -> Samples have varying SNR from 1 to 10.

  • patience (int) – Stopping criterion for the training.

  • alpha (float) – The regularization parameter.

Returns

self

Return type

object returns itself for convenience

train_model()#

Train the neural network model.

class invert.solvers.esinet.SolverCovCNN(name='Cov-CNN', **kwargs)#

Class for the Covariance-based Convolutional Neural Network (CovCNN) for EEG inverse solutions.

forward#

The mne-python Forward model instance.

Type

mne.Forward

apply_inverse_operator(mne_obj) mne.source_estimate.SourceEstimate#

Apply the inverse operator.

Parameters

mne_obj ([mne.Evoked, mne.Epochs, mne.io.Raw]) – The MNE data object.

Returns

stc – The mne Source Estimate object.

Return type

mne.SourceEstimate

apply_model(data) numpy.ndarray#

Compute the inverse solution of the M/EEG data.

Parameters

data (numpy.ndarray) – The M/EEG data matrix.

Returns

x_hat – The source esimate.

Return type

numpy.ndarray

build_model()#

Build the neural network model.

create_generator()#

Creat the data generator used for the simulations.

make_inverse_operator(forward, *args, n_filters='auto', activation_function='tanh', batch_size='auto', n_timepoints=20, batch_repetitions=10, epochs=300, learning_rate=0.001, loss='cosine_similarity', n_sources=10, n_orders=2, size_validation_set=256, epsilon=0.25, snr_range=(1, 100), patience=100, alpha='auto', **kwargs)#

Calculate inverse operator.

Parameters
  • forward (mne.Forward) – The mne-python Forward model instance.

  • n_filters (int) – Number of filters in the convolution layer.

  • activation_function (str) – The activation function of the hidden layers.

  • batch_size (["auto", int]) – The batch_size used during training. If “auto”, the batch_size defaults to the number of dipoles in the source/ forward model. Choose a smaller batch_size (e.g., 1000) if you run into memory problems (RAM or GPU memory).

  • n_timepoints (int) – The number of time points to simulate and ultimately train the neural network on.

  • batch_repetitions (int) – The number of learning repetitions on the same batch of training data until a new batch is simulated.

  • epochs (int) – The number of epochs to train.

  • learning_rate (float) – The learning rate of the optimizer that trains the neural network.

  • loss (str) – The loss function of the neural network.

  • n_sources (int) – The maximum number of sources to simulate for the training data.

  • n_orders (int) – Controls the maximum smoothness of the sources.

  • size_validation_set (int) – The size of validation data set.

  • epsilon (float) – The threshold at which to select sources as “active”. 0.25 -> select all sources that are active at least 25 % of the maximum dipoles.

  • snr_range (tuple) – The range of signal to noise ratios (SNRs) in the training data. (1, 10) -> Samples have varying SNR from 1 to 10.

  • patience (int) – Stopping criterion for the training.

  • alpha (float) – The regularization parameter.

Returns

self

Return type

object returns itself for convenience

train_model()#

Train the neural network model.

class invert.solvers.esinet.SolverFC(name='Fully-Connected', **kwargs)#
Class for the Fully-Connected Neural Network (FC) for

EEG inverse solutions.

apply_inverse_operator(mne_obj) mne.source_estimate.SourceEstimate#

Apply the inverse operator.

Parameters

mne_obj ([mne.Evoked, mne.Epochs, mne.io.Raw]) – The MNE data object.

Returns

stc – The mne Source Estimate object.

Return type

mne.SourceEstimate

apply_model(data) numpy.ndarray#

Compute the inverse solution of the M/EEG data.

Parameters

data (numpy.ndarray) – The M/EEG data matrix.

Returns

x_hat – The source esimate.

Return type

numpy.ndarray

build_model()#

Build the neural network model.

create_generator()#

Creat the data generator used for the simulations.

make_inverse_operator(forward, *args, n_dense_units=300, activation_function='tanh', batch_size='auto', n_timepoints=20, batch_repetitions=10, epochs=300, learning_rate=0.001, loss='cosine_similarity', n_sources=10, n_orders=2, size_validation_set=256, snr_range=(1, 100), patience=100, alpha='auto', verbose=0, **kwargs)#

Calculate inverse operator.

Parameters
  • forward (mne.Forward) – The mne-python Forward model instance.

  • activation_function (str) – The activation function of the hidden layers.

  • batch_size (["auto", int]) – The batch_size used during training. If “auto”, the batch_size defaults to the number of dipoles in the source/ forward model. Choose a smaller batch_size (e.g., 1000) if you run into memory problems (RAM or GPU memory).

  • n_timepoints (int) – The number of time points to simulate and ultimately train the neural network on.

  • batch_repetitions (int) – The number of learning repetitions on the same batch of training data until a new batch is simulated.

  • epochs (int) – The number of epochs to train.

  • learning_rate (float) – The learning rate of the optimizer that trains the neural network.

  • loss (str) – The loss function of the neural network.

  • n_sources (int) – The maximum number of sources to simulate for the training data.

  • n_orders (int) – Controls the maximum smoothness of the sources.

  • size_validation_set (int) – The size of validation data set.

  • snr_range (tuple) – The range of signal to noise ratios (SNRs) in the training data. (1, 10) -> Samples have varying SNR from 1 to 10.

  • patience (int) – Stopping criterion for the training.

  • alpha (float) – The regularization parameter.

Returns

self

Return type

object returns itself for convenience

train_model()#

Train the neural network model.

class invert.solvers.esinet.SolverLSTM(name='LSTM', **kwargs)#
Class for the Long-Short Term Memory Neural Network (LSTM) for

EEG inverse solutions.

forward#

The mne-python Forward model instance.

Type

mne.Forward

apply_inverse_operator(mne_obj) mne.source_estimate.SourceEstimate#

Apply the inverse operator.

Parameters

mne_obj ([mne.Evoked, mne.Epochs, mne.io.Raw]) – The MNE data object.

Returns

stc – The mne Source Estimate object.

Return type

mne.SourceEstimate

apply_model(data) numpy.ndarray#

Compute the inverse solution of the M/EEG data.

Parameters

data (numpy.ndarray) – The M/EEG data matrix.

Returns

x_hat – The source esimate.

Return type

numpy.ndarray

build_model()#

Build the neural network model.

build_model2()#

Build the neural network model.

create_generator()#

Creat the data generator used for the simulations.

make_inverse_operator(forward, *args, n_dense_units=300, n_lstm_units=75, activation_function='tanh', batch_size='auto', n_timepoints=20, batch_repetitions=10, epochs=300, learning_rate=0.001, loss='cosine_similarity', n_sources=10, n_orders=2, size_validation_set=256, snr_range=(1, 100), patience=100, alpha='auto', verbose=0, **kwargs)#

Calculate inverse operator.

Parameters
  • forward (mne.Forward) – The mne-python Forward model instance.

  • n_dense_units (int) – The number of neurons in the fully-connected hidden layers.

  • n_lstm_units (int) – The number of neurons in the LSTM hidden layers.

  • activation_function (str) – The activation function of the hidden layers.

  • batch_size (["auto", int]) – The batch_size used during training. If “auto”, the batch_size defaults to the number of dipoles in the source/ forward model. Choose a smaller batch_size (e.g., 1000) if you run into memory problems (RAM or GPU memory).

  • n_timepoints (int) – The number of time points to simulate and ultimately train the neural network on.

  • batch_repetitions (int) – The number of learning repetitions on the same batch of training data until a new batch is simulated.

  • epochs (int) – The number of epochs to train.

  • learning_rate (float) – The learning rate of the optimizer that trains the neural network.

  • loss (str) – The loss function of the neural network.

  • n_sources (int) – The maximum number of sources to simulate for the training data.

  • n_orders (int) – Controls the maximum smoothness of the sources.

  • size_validation_set (int) – The size of validation data set.

  • snr_range (tuple) – The range of signal to noise ratios (SNRs) in the training data. (1, 10) -> Samples have varying SNR from 1 to 10.

  • patience (int) – Stopping criterion for the training.

  • alpha (float) – The regularization parameter.

Returns

self

Return type

object returns itself for convenience

train_model()#

Train the neural network model.

invert.solvers.esinet.correlation_criterion(scaler, leadfield, y_est, x_true)#

Perform forward projections of a source using the leadfield. This is the objective function which is minimized in Net::solve_p().

Parameters
  • scaler (float) – scales the source y_est

  • leadfield (numpy.ndarray) – The leadfield (or sometimes called gain matrix).

  • y_est (numpy.ndarray) – Estimated/predicted source.

  • x_true (numpy.ndarray) – True, unscaled EEG.

invert.solvers.esinet.solve_p(leadfield, y_est, x_true)#
Parameters
  • y_est (numpy.ndarray) – The estimated source vector.

  • x_true (numpy.ndarray) – The original input EEG vector.

Returns

y_scaled – The scaled estimated source vector.

Return type

numpy.ndarray

invert.solvers.esinet.solve_p_wrap(leadfield, y_est, x_true)#

Wrapper for parallel (or, alternatively, serial) scaling of predicted sources.