(self, X, y)
return self
Extract spatial filters and templates from the given calibration data.

        Parameters
        ----------
        X : ndarray of shape (n_trials, n_channels, n_samples)
            Training data. Trials are grouped by class, divided in n_fbands bands by
            the filterbank approach and then used to calculate weight vectors and
            templates for each class and band.

        y : ndarray of shape (n_trials,)
            Label vector in respect to X.

        Returns
        -------
        self: CCA object
            Instance of classifier.
Extract spatial filters and templates from the given calibration data.
Extract spatial filters and templates from the given calibration data .
def fit(self, X, y):
        """Extract spatial filters and templates from the given calibration data.

        Parameters
        ----------
        X : ndarray of shape (n_trials, n_channels, n_samples)
            Training data. Trials are grouped by class, divided in n_fbands bands by
            the filterbank approach and then used to calculate weight vectors and
            templates for each class and band.

        y : ndarray of shape (n_trials,)
            Label vector in respect to X.

        Returns
        -------
        self: CCA object
            Instance of classifier.
        """
        # Downsample data
        X = X[:, :, :: self.downsample]

        # Get shape of X and labels
        n_trials, n_channels, n_samples = X.shape

        self.sfreq = int(n_samples / self.slen)
        self.sfreq = self.sfreq / self.downsample

        self.classes_ = np.unique(y)
        self.n_classes = len(self.classes_)

        # Initialize the final arrays
        self.templates_ = np.zeros((self.n_classes, self.n_fbands, n_channels, n_samples))
        self.weights_ = np.zeros((self.n_fbands, self.n_classes, n_channels))

        for class_idx in self.classes_:
            X_cal = X[y == class_idx]  # Select data with a specific label
            # Filterbank approach
            for band_n in range(self.n_fbands):
                # Filter the data and compute TRCA
                X_filter = filterbank(X_cal, self.sfreq, band_n, self.peaks)
                w_best, _ = self._compute_trca(X_filter)

                # Get template by averaging trials and take the best filter for this band
                self.templates_[class_idx, band_n, :, :] = np.mean(X_filter, axis=0)
                self.weights_[band_n, class_idx, :] = w_best

        return self
def fit ( self , X , y ) : # Downsample data X = X [ : , : , : : self . downsample ] # Get shape of X and labels n_trials , n_channels , n_samples = X . shape self . sfreq = int ( n_samples / self . slen ) self . sfreq = self . sfreq / self . downsample self . classes_ = np . unique ( y ) self . n_classes = len ( self . classes_ ) # Initialize the final arrays self . templates_ = np . zeros ( ( self . n_classes , self . n_fbands , n_channels , n_samples ) ) self . weights_ = np . zeros ( ( self . n_fbands , self . n_classes , n_channels ) ) for class_idx in self . classes_ : X_cal = X [ y == class_idx ] # Select data with a specific label # Filterbank approach for band_n in range ( self . n_fbands ) : # Filter the data and compute TRCA X_filter = filterbank ( X_cal , self . sfreq , band_n , self . peaks ) w_best , _ = self . _compute_trca ( X_filter ) # Get template by averaging trials and take the best filter for this band self . templates_ [ class_idx , band_n , : , : ] = np . mean ( X_filter , axis = 0 ) self . weights_ [ band_n , class_idx , : ] = w_best return self