coco_pipe.transforms.TemporalProcrustesAlignment#

class coco_pipe.transforms.TemporalProcrustesAlignment(n_components=30, *, adaptation='transductive', rotate=True, use_shared_basis=False, augment=(), augment_only=False, trajectory_metrics=None, random_state=42)#

Bases: BaseEstimator, TransformerMixin

Align participant-specific PCA trajectories to a training template.

fit learns a shared PCA template and participant mappings from the training fold. transform reuses stored mappings for known participants and estimates a label-free PCA/rotation from the transform batch for unseen participants. The latter is explicit transductive adaptation.

Two options turn this into its own controls. rotate=False keeps the per-participant PCA but drops the Procrustes step, which isolates whether a participant-specific basis alone transfers (it does not) or whether the rotation is what does the work. adaptation="calibration" estimates an unseen participant’s PCA and rotation from one random half of their trials and applies it to the other half (and vice versa), so no trial ever contributes to its own mapping — a non-transductive variant that still returns every row.

use_shared_basis=True is a third control: every participant is projected through the pooled training template directly (the same shared_pca_ fit fit() already uses as the rotation target), ignoring per-participant identity and rotate entirely. This is the continuous, temporally-stable analogue of a single spatial filter shared by everyone — as opposed to coco_pipe.decoding’s ReducerConfig PCA, which is fold-local but refit independently at every sliding-window latency.

augment concatenates extra channels derived from each component’s own trajectory onto the raw scores, still computed fold-locally inside transform so nothing about a held-out participant leaks into them: "envelope" (Hilbert amplitude), "velocity" (index-based first derivative — only rank-invariant reparametrizations of time reach the classifier, and any downstream StandardScaler absorbs a fixed sampling-rate scale factor, so the true sampling interval isn’t needed), and "scalar" (each component’s peak amplitude, index-based peak latency, mean power, and signed AUC over the whole supplied window, broadcast as constant channels across time). Requesting n of these turns n_components raw channels into n_components * (1 + n).

augment_only=True drops the raw per-component scores channels entirely, leaving only whatever augment requests (e.g. just the ~10 "trajectory" geometry channels, independent of n_components - for analyses where the raw PC scores aren’t wanted as features at all, only derived channels computed from the embedding they define). trajectory_metrics restricts "trajectory" to a chosen subset of its ~10 metrics (by name, e.g. ("speed",)) instead of computing and returning all of them - None (default) means all.

Parameters:
  • n_components (int)

  • adaptation (str)

  • rotate (bool)

  • use_shared_basis (bool)

  • augment (tuple[str, ...])

  • augment_only (bool)

  • trajectory_metrics (tuple[str, ...] | None)

  • random_state (int | None)

fold_local = True#
fit(X, y=None, groups=None)#

Fit the training-fold template and participant mappings.

Parameters:
transform(X, groups=None)#

Project and align known or unseen participant trajectories.

Parameters:
Return type:

ndarray

fit_transform(X, y=None, groups=None, **fit_params)#

Fit and align one training fold.

Parameters:
Return type:

ndarray

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)#

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

set_fit_request(*, groups='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the fit 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 fit 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 fit.

  • 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:
  • groups (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for groups parameter in fit.

  • self (TemporalProcrustesAlignment)

Returns:

self – The updated object.

Return type:

object

set_output(*, transform=None)#

Set output container.

Refer to the user guide for more details and Introducing the set_output API for an example on how to use the API.

Parameters:

transform ({"default", "pandas", "polars"}, default=None) –

Configure output of transform and fit_transform.

  • ”default”: Default output format of a transformer

  • ”pandas”: DataFrame output

  • ”polars”: Polars output

  • None: Transform configuration is unchanged

Added in version 1.4: “polars” option was added.

Returns:

self – Estimator instance.

Return type:

estimator instance

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance

set_transform_request(*, groups='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the transform 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 transform 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 transform.

  • 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:
  • groups (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for groups parameter in transform.

  • self (TemporalProcrustesAlignment)

Returns:

self – The updated object.

Return type:

object