pyntbci.stopping.BayesStopping

class pyntbci.stopping.BayesStopping(estimator: ClassifierMixin, segment_time: float, fs: int, method: str = 'bds0', cr: float = 1.0, target_pf: float = 0.05, target_pd: float = 0.8, max_time: float | None = None)[source]

Bayesian dynamic stopping. Fits Gaussian distributions for target and non-target responses, and calculates a stopping threshold using these and a cost criterion [1].

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.

  • method (str (default: "bds0")) – The method to use for Bayesian dynamic stopping: bds0, bds1, bds2.

  • cr (float (default: 1.0)) – The cost ratio.

  • target_pf (float (default: 0.05)) – The targeted probability for error.

  • target_pd (float (default: 0.80)) – The targeted probability for detection.

  • max_time (float (default: None)) – The maximum time at which to force a stop, i.e., a classification. If None, the algorithm will always emit -1 if it cannot stop, otherwise it will emit a classification regardless of the certainty after that maximum time.

alpha_

The scaling parameter between observed and predicted responses.

Type:

float

sigma_

The standard deviation of the noise.

Type:

float

b0_

The mean of the non-target Gaussian distribution of shape (n_segments).

Type:

NDArray

b1_

The mean of the target Gaussian distribution of shape (n_segments).

Type:

NDArray

s0_

The standard deviation of the non-target Gaussian distribution of shape (n_segments).

Type:

NDArray

s1_

The standard deviation of the target Gaussian distribution of shape (n_segments).

Type:

NDArray

eta_

The decision boundary of shape (n_segments).

Type:

NDArray

pf_

The predicted probability of a false detection of shape (n_segments).

Type:

NDArray

pm_

The predicted probability of a miss of shape (n_segments).

Type:

NDArray

References

fit(X: ndarray[Any, dtype[_ScalarType_co]], y: ndarray[Any, dtype[_ScalarType_co]]) 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[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]

The testing procedure to apply the estimator to novel EEG data using Bayesian 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$') BayesStopping

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see 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.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

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