Implemented models

LFCNN

class mneflow.models.LFCNN(meta, dataset=None)

Bases: BaseModel

LF-CNN. Includes basic parameter interpretation options.

For details see [1]. .. rubric:: References

[1] I. Zubarev, et al., Adaptive neural network classifier for decoding MEG signals. Neuroimage. (2019) May 4;197:425-434

__init__(meta, dataset=None)
Parameters:
  • Dataset (mneflow.Dataset) –

  • specs (dict) – dictionary of model hyperparameters {

  • n_latent (int) – Number of latent components. Defaults to 32.

  • nonlin (callable) – Activation function of the temporal convolution layer. Defaults to tf.nn.relu

  • filter_length (int) – Length of spatio-temporal kernels in the temporal convolution layer. Defaults to 7.

  • pooling (int) – Pooling factor of the max pooling layer. Defaults to 2

  • pool_type (str {'avg', 'max'}) – Type of pooling operation. Defaults to ‘max’.

  • padding (str {'SAME', 'FULL', 'VALID'}) – Convolution padding. Defaults to ‘SAME’.}

  • stride (int) –

  • 1. (Stride of the max pooling layer. Defaults to) –

backprop_covxy(X, Hx, Sx, w)
backprop_fc(X, y_hat, y, w)

X - [i,…,m] y - [i,…,j] w - [k,…,j] Sx - [k,…,mj]

build_encoder()

Build computational graph for an interpretable Generator

Returns:

y_pred – Output of the forward pass of the computational graph. Prediction of the target variable.

Return type:

tf.Tensor

build_graph()

Build computational graph using defined placeholder self.X as input.

Returns:

y_pred – Output of the forward pass of the computational graph. Prediction of the target variable.

Return type:

tf.Tensor

collect_patterns(fold=0, n_folds=1, n_comp=1, methods=['weight', 'compwise_loss', 'l2', 'abs_weight', 'output_corr'])

Compute and store patterns during cross-validation.

compute_componentwise_loss(X, y, weights)

Compute component relevances by recursive elimination

compute_enc_patterns(inputs=None)
compute_patterns(data_path=None)

Computes spatial patterns from filter weights. Required for visualization.

Parameters:
  • data_path (str or list of str) – Path to TFRecord files on which the patterns are estimated.

  • output (str {'patterns, 'filters', 'full_patterns'}) –

    String specifying the output.

    ’filters’ - extracts weights of the spatial filters

    ’patterns’ - extracts activation patterns, obtained by left-multipying the spatial filter weights by the (spatial) data covariance.

    ’full-patterns’ - additionally multiplies activation patterns by the precision (inverse covariance) of the latent sources

Returns:

  • self.patterns – spatial filters or activation patterns, depending on the value of ‘output’ parameter.

  • self.lat_tcs – time courses of latent sourses.

  • self.filters – temporal convolutional filter coefficients.

  • self.out_weights – weights of the output layer.

  • self.rfocs – feature relevances for the output layer. (See self.get_output_correlations)

  • Raises

  • ——- – AttributeError: If data_path is not specified.

explore_components(patterns_struct, sorting='output_corr', integrate='max', info=None, sensor_layout='Vectorview-mag', class_names=None)

Plots the weights of the output layer.

Parameters:
  • pat (int [0, self.specs['n_latent'])) – Index of the latent component to higlight

  • t (int [0, self.h_params['n_t'])) – Index of timepoint to highlight

Returns:

Imshow [n_latent, y_shape]

Return type:

figure

get_config()
get_output_correlations(activations)

Computes a similarity metric between each of the extracted features and the target variable.

The metric is a Manhattan distance for dicrete targets, and Spearman correlation for continuous targets.

get_spectra(weights, activations, nfft=128)
get_weights()
make_fake_evoked(topos, sensor_layout)
patterns_cov_xx(y, weights, activations, dcov)

X - [i,…,m] y - [i,…,j] - used for cov[y] w - [k,…,j] Sx - [k,…,mj]

patterns_cov_xy_hat(X, y, activations, weights)
patterns_pinv_w(y, weights, activations, dcov)
patterns_wfc_mean(y, weights, activations, dcov)
plot_combined_pattern(method='combined', sensor_layout=None, names=None, n_comp=1, plot_true_evoked=False)
plot_evoked_peaks(data=None, t=None, class_subset=None, sensor_layout='Vectorview-mag')

Plot one spatial topography of class-conditional average of the input. If timepoint is not specified it is picked as a maximum RMS for each class.

Parameters:
  • topos (np.array) – [n_ch, n_t, n_classes]

  • sensor_layout (TYPE, optional) – DESCRIPTION. The default is ‘Vectorview-mag’.

plot_topos(topos, sensor_layout='Vectorview-mag', class_subset=None)

Plot any spatial distribution in the sensor space. TODO: Interpolation??

Parameters:
  • topos (np.array) – [n_ch, n_classes, …]

  • sensor_layout (TYPE, optional) – DESCRIPTION. The default is ‘Vectorview-mag’.

  • class_subset (np.array, optional) –

Return type:

None.

plot_waveforms(patterns_struct, sorting='compwise_loss', tmin=0, class_names=None, bp_filter=False, tlim=None, apply_kernels=False)

Plots timecourses of latent components.

Parameters:

tmin (float) – Beginning of the MEG epoch with regard to reference event. Defaults to 0.

sortingstr

heuristic for selecting relevant components. See LFCNN._sorting

single_component_pattern(patterns_struct, sorting='compwise_loss', n_comp=1)
train_encoder(n_epochs, eval_step=None, min_delta=1e-06, early_stopping=3, collect_patterns=False)

VARCNN

class mneflow.models.VARCNN(meta, dataset=None)

Bases: BaseModel

VAR-CNN.

For details see [1].

References

[1] I. Zubarev, et al., Adaptive neural network classifier for decoding MEG signals. Neuroimage. (2019) May 4;197:425-434

__init__(meta, dataset=None)
Parameters:
  • Dataset (mneflow.Dataset) –

  • specs (dict) – dictionary of model hyperparameters {

  • n_latent (int) – Number of latent components. Defaults to 32.

  • nonlin (callable) – Activation function of the temporal convolution layer. Defaults to tf.nn.relu

  • filter_length (int) – Length of spatio-temporal kernels in the temporal convolution layer. Defaults to 7.

  • pooling (int) – Pooling factor of the max pooling layer. Defaults to 2

  • pool_type (str {'avg', 'max'}) – Type of pooling operation. Defaults to ‘max’.

  • padding (str {'SAME', 'FULL', 'VALID'}) – Convolution padding. Defaults to ‘SAME’.}

build_graph()

Build computational graph using defined placeholder self.X as input.

Returns:

y_pred – Output of the forward pass of the computational graph. Prediction of the target variable.

Return type:

tf.Tensor

EEGNet

class mneflow.models.EEGNet(meta, dataset=None)

Bases: BaseModel

EEGNet.

Parameters:

specs (dict) –

n_latentint

Number of (temporal) convolution kernrels in the first layer. Defaults to 8

filter_lengthint

Length of temporal filters in the first layer. Defaults to 32

strideint

Stride of the average polling layers. Defaults to 4.

poolingint

Pooling factor of the average polling layers. Defaults to 4.

dropoutfloat

Dropout coefficient.

References

[3] V.J. Lawhern, et al., EEGNet: A compact convolutional neural network for EEG-based brain–computer interfaces 10 J. Neural Eng., 15 (5) (2018), p. 056013

[4] Original EEGNet implementation by the authors can be found at https://github.com/vlawhern/arl-eegmodels

__init__(meta, dataset=None)
Parameters:
  • Dataset (mneflow.Dataset) – Dataset object.

  • specs (dict) – Dictionary of model-specific hyperparameters. Must include at least model_path - path for saving a trained model See Model subclass definitions for details. Unless otherwise specified uses default hyperparameters for each implemented model.

build_graph()

Build computational graph using defined placeholder self.X as input.

Can be overriden in a sub-class for customized architecture.

Returns:

y_pred – Output of the forward pass of the computational graph. Prediction of the target variable.

Return type:

tf.Tensor

FBCSP_ShallowNet

class mneflow.models.FBCSP_ShallowNet(meta, dataset=None)

Bases: BaseModel

Shallow ConvNet model from [2a]. .. rubric:: References

[2a]

Schirrmeister, R. T., Springenberg, J. T., Fiederer, L. D. J., Glasstetter, M., Eggensperger, K., Tangermann, M., Hutter, F. & Ball, T. (2017). Deep learning with convolutional neural networks for EEG decoding and visualization. Human Brain Mapping , Aug. 2017. Online: http://dx.doi.org/10.1002/hbm.23730

__init__(meta, dataset=None)
Parameters:
  • Dataset (mneflow.Dataset) – Dataset object.

  • specs (dict) – Dictionary of model-specific hyperparameters. Must include at least model_path - path for saving a trained model See Model subclass definitions for details. Unless otherwise specified uses default hyperparameters for each implemented model.

build_graph()

Temporal conv_1 25 10x1 kernels

Deep4

class mneflow.models.Deep4(meta, dataset=None)

Bases: BaseModel

Deep ConvNet model from [2b]. .. rubric:: References

[2b]

Schirrmeister, R. T., Springenberg, J. T., Fiederer, L. D. J., Glasstetter, M., Eggensperger, K., Tangermann, M., Hutter, F. & Ball, T. (2017). Deep learning with convolutional neural networks for EEG decoding and visualization. Human Brain Mapping , Aug. 2017. Online: http://dx.doi.org/10.1002/hbm.23730

__init__(meta, dataset=None)
Parameters:
  • Dataset (mneflow.Dataset) – Dataset object.

  • specs (dict) – Dictionary of model-specific hyperparameters. Must include at least model_path - path for saving a trained model See Model subclass definitions for details. Unless otherwise specified uses default hyperparameters for each implemented model.

build_graph()

Build computational graph using defined placeholder self.X as input.

Can be overriden in a sub-class for customized architecture.

Returns:

y_pred – Output of the forward pass of the computational graph. Prediction of the target variable.

Return type:

tf.Tensor