switch to inherit to classifier again for trial decoding to work
import numpy as np
from skorch.utils import to_numpy
from skorch.classifier import NeuralNet
+from skorch.classifier import NeuralNetClassifier
-class BraindecodeClassifier(NeuralNet):
- def predict(self, X):
- """Where applicable, return class labels for samples in X.
- If the module's forward method returns multiple outputs as a
- tuple, it is assumed that the first output contains the
- relevant information and the other values are ignored. If all
- values are relevant, consider using
- :func:`~skorch.NeuralNet.forward` instead.
+class EEGClassifier(NeuralNetClassifier):
+ """Classifier that does not assume softmax activation.
+ Calls loss function directly without applying log or anything.
+ """
+ # pylint: disable=arguments-differ
+ def get_loss(self, y_pred, y_true, *args, **kwargs):
+ """Return the loss for this batch by calling NeuralNet get_loss.
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
@@ -24,13 +28,8 @@ class BraindecodeClassifier(NeuralNet):
* a Dataset
If this doesn't work with your data, you have to pass a
``Dataset`` that can deal with the data.
- Returns
- -------
- y_pred : numpy ndarray
+ training : bool (default=False)
+ Whether train mode should be used or not.
+
"""
- y_preds = []
- for yp in self.forward_iter(X, training=False):
- yp = yp[0] if isinstance(yp, tuple) else yp
- y_preds.append(to_numpy(yp.max(-1)[-1]))
- y_pred = np.concatenate(y_preds, 0)
- return y_pred
+ return NeuralNet.get_loss(self, y_pred, y_true, *args, **kwargs)
