metabci.brainda.algorithms.deep_learning.base module¶
- class metabci.brainda.algorithms.deep_learning.base.AvgPool2dWithConv(kernel_size, stride, dilation=1, padding=0)[source]¶
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)[source]¶
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 metabci.brainda.algorithms.deep_learning.base.Ensure4d(*args, **kwargs)[source]¶
Bases:
Module- forward(x)[source]¶
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 metabci.brainda.algorithms.deep_learning.base.Expression(expression_fn)[source]¶
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)[source]¶
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 metabci.brainda.algorithms.deep_learning.base.MaxNormConstraintConv2d(*args, max_norm_value=1, norm_axis=2, **kwargs)[source]¶
Bases:
Conv2d- bias: Tensor | None¶
- dilation: Tuple[int, ...]¶
- forward(input)[source]¶
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: str | Tuple[int, ...]¶
- padding_mode: str¶
- stride: Tuple[int, ...]¶
- transposed: bool¶
- weight: Tensor¶
- class metabci.brainda.algorithms.deep_learning.base.MaxNormConstraintLinear(*args, max_norm_value=1, norm_axis=0, **kwargs)[source]¶
Bases:
Linear- forward(input)[source]¶
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 metabci.brainda.algorithms.deep_learning.base.NeuralNetClassifierNoLog(module, *args, criterion=<class 'torch.nn.modules.loss.NLLLoss'>, train_split=<skorch.dataset.ValidSplit object>, classes=None, **kwargs)[source]¶
Bases:
NeuralNetClassifier- fit(X, y, **fit_params)[source]¶
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)[source]¶
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.
- metabci.brainda.algorithms.deep_learning.base.compute_out_size(input_size: int, kernel_size: int, stride: int = 1, padding: int = 0, dilation: int = 1)[source]¶
- metabci.brainda.algorithms.deep_learning.base.compute_same_pad1d(input_size, kernel_size, stride=1, dilation=1)[source]¶
- metabci.brainda.algorithms.deep_learning.base.compute_same_pad2d(input_size, kernel_size, stride=(1, 1), dilation=(1, 1))[source]¶
- metabci.brainda.algorithms.deep_learning.base.np_to_th(X, requires_grad=False, dtype=None, pin_memory=False, **tensor_kwargs)[source]¶
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