Deep Learning Methods

EEGNet

EEGNet. Modified from https://github.com/vlawhern/arl-eegmodels/blob/master/EEGModels.py

class brainda.algorithms.deep_learning.eegnet.SeparableConv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, bias=True, padding_mode='zeros', D=1)

Bases: torch.nn.modules.module.Module

An equally SeparableConv2d in Keras. A depthwise conv followed by a pointwise conv.

forward(X)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool

Utils

class brainda.algorithms.deep_learning.base.MaxNormConstraintConv2d(*args, max_norm_value=1, norm_axis=2, **kwargs)

Bases: torch.nn.modules.conv.Conv2d

bias: Optional[torch.Tensor]
dilation: Tuple[int, ...]
forward(input)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

groups: int
kernel_size: Tuple[int, ...]
out_channels: int
output_padding: Tuple[int, ...]
padding: Union[str, Tuple[int, ...]]
padding_mode: str
stride: Tuple[int, ...]
transposed: bool
weight: torch.Tensor
class brainda.algorithms.deep_learning.base.MaxNormConstraintLinear(*args, max_norm_value=1, norm_axis=0, **kwargs)

Bases: torch.nn.modules.linear.Linear

forward(input)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

in_features: int
out_features: int
weight: torch.Tensor
class brainda.algorithms.deep_learning.base.NeuralNetClassifierNoLog(module, *args, criterion=<class 'torch.nn.modules.loss.NLLLoss'>, train_split=<skorch.dataset.ValidSplit object>, classes=None, **kwargs)

Bases: skorch.classifier.NeuralNetClassifier

fit(X, y, **fit_params)

See NeuralNet.fit.

In contrast to NeuralNet.fit, y is non-optional to avoid mistakenly forgetting about y. However, y can be set to None in case it is derived dynamically from X.

get_loss(y_pred, y_true, *args, **kwargs)

Return the loss for this batch.

Parameters
  • y_pred (torch tensor) – Predicted target values

  • y_true (torch tensor) – True target values.

  • X (input data, compatible with skorch.dataset.Dataset) –

    By default, you should be able to pass:

    • numpy arrays

    • torch tensors

    • pandas DataFrame or Series

    • scipy sparse CSR matrices

    • a dictionary of the former three

    • a list/tuple of the former three

    • a Dataset

    If this doesn’t work with your data, you have to pass a Dataset that can deal with the data.

  • training (bool (default=False)) – Whether train mode should be used or not.

class brainda.algorithms.deep_learning.base.SkorchNet(module)

Bases: object

brainda.algorithms.deep_learning.base.adaptive_batch_norm(model, use_global=False)
brainda.algorithms.deep_learning.base.compute_out_size(input_size: int, kernel_size: int, stride: int = 1, padding: int = 0, dilation: int = 1)
brainda.algorithms.deep_learning.base.compute_same_pad1d(input_size, kernel_size, stride=1, dilation=1)
brainda.algorithms.deep_learning.base.compute_same_pad2d(input_size, kernel_size, stride=(1, 1), dilation=(1, 1))