pyntbci.stopping.CriterionStopping
- class pyntbci.stopping.CriterionStopping(estimator: ClassifierMixin, segment_time: float, fs: int, criterion: str = 'accuracy', optimization: str = 'max', n_folds: int = 4, target: float = None, smooth_width: float = None, max_time: float = None, min_time: float = None)[source]
Criterion static stopping. Fits an optimal stopping time given some criterion to optimize.
- 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 in seconds.
fs (int) – The sampling frequency of the EEG data in Hz.
criterion (str (default: "accuracy")) – The criterion to use: accuracy, itr.
optimization (str (default: "max")) – The optimization to use: max, target.
n_folds (int (default: 4)) – The number of folds to evaluate the optimization.
target (float (default: None)) – The targeted value for the criterion to optimize for. Only used if optimization=”target”.
smooth_width (float (default: None)) – The width of the smoothing applied in seconds. If None, the values of the criterion are not smoothened.
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.
- classes_
The classes that can be predicted, taken from the wrapped estimator’s classes_ after fitting (i.e., after the internal cross-validation, fit on the last fold, matching what predict() uses). Note, predict() may additionally return -1 to indicate a trial has not yet been stopped, which is not itself a class.
- Type:
NDArray
- stop_time_
The trained static stopping time.
- Type:
float
- fit(X: NDArray, y: NDArray) ClassifierMixin[source]
The training procedure to fit the static 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, running: bool = False, reset: bool = False) NDArray[source]
The testing procedure to apply the estimator to novel EEG data using criterion static stopping.
- Parameters:
X (NDArray) – The matrix of EEG data of shape (n_trials, n_channels, n_samples). If running=True, this is only the newly observed samples since the previous call (not the full trial so far), see running below.
running (bool (default: False)) – Whether to use running (incremental) scoring. If False (default), predict() behaves exactly as without this parameter: X is the complete trial data seen so far, and everything is recomputed from scratch (safe to call in any order, e.g. repeatedly with the same or a shorter X). If True, X is only the newly observed samples since the previous call, and a running state (kept internally, not a fitted attribute) is reused and updated; if the wrapped estimator supports running scoring itself (an eCCA or rCCA with ensemble=False), each call only does O(n_new_samples) work instead of reprocessing the whole trial, otherwise the raw data is buffered here and recomputed from scratch each call (still correct, just not faster). Use reset=True on the first call of a new running sequence (e.g. for a new trial or a new batch of trials); the running state is otherwise unaffected by (and does not affect) running=False calls, and is cleared by fit().
reset (bool (default: False)) – Whether to discard any existing running state before processing this call. Only relevant if running=True; a never-yet-used instance already starts fresh without it, so it only needs to be set explicitly to start a new sequence before the previous one naturally ended.
- 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_predict_request(*, reset: bool | None | str = '$UNCHANGED$', running: bool | None | str = '$UNCHANGED$') CriterionStopping
Configure whether metadata should be requested to be passed to the
predictmethod.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(seesklearn.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 topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.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:
reset (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
resetparameter inpredict.running (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
runningparameter inpredict.
- Returns:
self – The updated object.
- Return type:
object
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') CriterionStopping
Configure whether metadata should be requested to be passed to the
scoremethod.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(seesklearn.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 toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.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_weightparameter inscore.- Returns:
self – The updated object.
- Return type:
object