brainda.algorithms.deep_learning package¶
Submodules¶
brainda.algorithms.deep_learning.base module¶
- class brainda.algorithms.deep_learning.base.AvgPool2dWithConv(kernel_size, stride, dilation=1, padding=0)¶
Bases:
ModuleCompute average pooling using a convolution, to have the dilation parameter.
- Parameters:
kernel_size ((int,int)) – Size of the pooling region.
stride ((int,int)) – Stride of the pooling operation.
dilation (int or (int,int)) – Dilation applied to the pooling filter.
padding (int or (int,int)) – Padding applied before the pooling operation.
- 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶
- class brainda.algorithms.deep_learning.base.Ensure4d¶
Bases:
Module- 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶
- class brainda.algorithms.deep_learning.base.Expression(expression_fn)¶
Bases:
ModuleCompute given expression on forward pass.
- Parameters:
expression_fn (callable) – Should accept variable number of objects of type torch.autograd.Variable to compute its output.
- 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶
- class brainda.algorithms.deep_learning.base.MaxNormConstraintConv2d(*args, max_norm_value=1, norm_axis=2, **kwargs)¶
Bases:
Conv2d- bias: Optional[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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- groups: int¶
- in_channels: 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: Tensor¶
- class brainda.algorithms.deep_learning.base.MaxNormConstraintLinear(*args, max_norm_value=1, norm_axis=0, **kwargs)¶
Bases:
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
Moduleinstance 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: 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:
NeuralNetClassifier- fit(X, y, **fit_params)¶
See
NeuralNet.fit.In contrast to
NeuralNet.fit,yis non-optional to avoid mistakenly forgetting abouty. However,ycan be set toNonein case it is derived dynamically fromX.
- 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
Datasetthat 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))¶
- brainda.algorithms.deep_learning.base.identity(x)¶
- brainda.algorithms.deep_learning.base.np_to_th(X, requires_grad=False, dtype=None, pin_memory=False, **tensor_kwargs)¶
Convenience function to transform numpy array to torch.Tensor.
Converts X to ndarray using asarray if necessary.
- Parameters:
X (ndarray or list or number) – Input arrays
requires_grad (bool) – passed on to Variable constructor
dtype (numpy dtype, optional) –
var_kwargs – passed on to Variable constructor
- Returns:
var
- Return type:
torch.Tensor
- brainda.algorithms.deep_learning.base.squeeze_final_output(x)¶
- Removes empty dimension at end and potentially removes empty time
dimension. It does not just use squeeze as we never want to remove first dimension.
- Returns:
x – squeezed tensor
- Return type:
torch.Tensor
- brainda.algorithms.deep_learning.base.transpose_time_to_spat(x)¶
Swap time and spatial dimensions.
- Returns:
x – tensor in which last and first dimensions are swapped
- Return type:
torch.Tensor
brainda.algorithms.deep_learning.convca module¶
Conv-CA Modified from https://github.com/yaoli90/Conv-CA
brainda.algorithms.deep_learning.deepnet module¶
Deep4Net. Modified from https://github.com/braindecode/braindecode/blob/master/braindecode/models/deep4.py
-author: Xie YT -Created on: 2022-07-02 -update log: …
brainda.algorithms.deep_learning.eegnet module¶
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:
ModuleAn 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶
brainda.algorithms.deep_learning.guney_net module¶
Guney’s network proposed in A Deep Neural Network for SSVEP-based Brain-Computer Interfaces.
Modified from https://github.com/osmanberke/Deep-SSVEP-BCI.git
brainda.algorithms.deep_learning.shallownet module¶
ShallowFBCSP. Modified from https://github.com/braindecode/braindecode/blob/master/braindecode/models/shallow_fbcsp.py
- class brainda.algorithms.deep_learning.shallownet.SafeLog(eps=1e-06)¶
Bases:
Module- 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶
- class brainda.algorithms.deep_learning.shallownet.Square¶
Bases:
Module- 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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶