pyntbci.stopping.DistributionStopping

class pyntbci.stopping.DistributionStopping(estimator: ClassifierMixin, segment_time: float, fs: int, trained: bool = False, distribution: str = 'beta', target_p: float = 0.95, max_time: float = None, min_time: float = None)[source]

Distribution dynamic stopping. Fits a distribution to non-target / non-maximum scores, and tests the probability of the target / maximum score to be an outlier of that distribution [2].

Parameters:
  • estimator (ClassifierMixin) – The classifier object that performs the classification.

  • segment_time (float) – The size of a segment of data at which classification is performed ins seconds.

  • fs (int) – The sampling frequency of the EEG data in Hz. Required for max_time.

  • trained (bool (default: False)) – Whether to calibrate the beta distributions on training data.

  • distribution (str (default: "beta")) – The distribution to use for the non-target / non-maximum distribution. Either beta or norm.

  • target_p (float (default: 0.95)) – The targeted probability of correct classification.

  • max_time (float (default: None)) – The maximum time in seconds at which to force a stop, i.e., a classification. Trials will not be longer than this maximum time. If None, the algorithm will always emit -1 if it cannot stop.

  • min_time (float (default: None)) – The minimum time in seconds at which a stop is possible, i.e., a classification. Before the minimum time, the algorithm will always emit -1. If None, the algorithm allows a stop already after the first segment of data.

distributions_

A list of dictionaries containing the parameters of the distribution for each data segment. Only used if trained=True.

Type:

list[dict]

References

fit(X: ndarray[tuple[Any, ...], dtype[_ScalarT]], y: ndarray[tuple[Any, ...], dtype[_ScalarT]]) ClassifierMixin[source]

The training procedure to fit the dynamic procedure on supervised EEG data.

Parameters:
  • X (NDArray) – The matrix of EEG data of shape (n_trials, n_channels, n_samples).

  • y (NDArray) – The vector of ground-truth labels of the trials in X of shape (n_trials).

Returns:

self – Returns the instance itself.

Return type:

ClassifierMixin

predict(X: ndarray[tuple[Any, ...], dtype[_ScalarT]]) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]

The testing procedure to apply the estimator to novel EEG data using dynamic stopping.

Parameters:

X (NDArray) – The matrix of EEG data of shape (n_trials, n_channels, n_samples).

Returns:

y – The vector of predicted labels of the trials in X of shape (n_trials). Note, the value equals -1 if the trial cannot yet be stopped.

Return type:

NDArray

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') DistributionStopping

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for sample_weight parameter in score.

Returns:

self – The updated object.

Return type:

object