coco_pipe.dim_reduction.evaluation.result#

Results Container.

Classes#

TrajectoryResult

Unified Container for Trajectory Geometry Results.

EmbeddingQualityResult

Unified Container for Embedding Quality Metrics.

VelocityResult

Unified Container for Velocity Dynamics Results.

Module Contents#

class coco_pipe.dim_reduction.evaluation.result.TrajectoryResult(trajectories, times, subjects, conditions)#

Unified Container for Trajectory Geometry Results.

Provides tidy data views for easier analysis, visualization, and statistical assessment of trajectory dynamics across subjects and conditions.

Condition labels are kept as given, names such as "fast-easy-right" or integers, and every method that chooses conditions takes those labels.

Summaries propagate NaN as the geometry functions do: a trajectory with a missing time point reports NaN for every metric that depends on it.

Parameters:
trajectories#
times#
subjects#
conditions#
classmethod from_grid(trajectories, times, subjects, conditions)#

Build the container from trajectories on a (subject, condition) grid.

Parameters:
  • trajectories (np.ndarray) – Shape (n_subjects, n_conditions, n_times, n_dims), such as one condition-mean trajectory per subject and condition.

  • times (np.ndarray) – Shape (n_times,). Time coordinates.

  • subjects (Sequence) – Length n_subjects. Label of each row of the grid.

  • conditions (Sequence) – Length n_conditions. Label of each column of the grid.

Returns:

One trajectory per grid cell, subject-major: row i * n_conditions + j holds subject i in condition j.

Return type:

TrajectoryResult

Raises:

ValueError – If trajectories is not 4-D, the labels do not match its first two axes, or times does not match its third.

Examples

>>> import numpy as np
>>> grid = np.zeros((3, 2, 50, 4))
>>> res = TrajectoryResult.from_grid(
...     grid, np.arange(50), ["s1", "s2", "s3"], ["easy", "hard"]
... )
>>> res.trajectories.shape
(6, 50, 4)
>>> res.subjects.tolist()[:3], res.conditions.tolist()[:3]
(['s1', 's1', 's2'], ['easy', 'hard', 'easy'])
get_per_trial_scalars()#

Compute per-trial scalar metrics in long format.

Returns:

Columns: subject, condition, trial, metric, value.

Return type:

pd.DataFrame

get_per_condition_scalars()#

Compute within-condition spread metrics (cohesion, intra_spread).

Returns:

Columns: subject, condition, metric, value.

Return type:

pd.DataFrame

get_separation_pair_scalars(methods=('centroid', 'mahalanobis'))#

Per-subject, per-condition-pair separation peak / peak-time / AUC.

For each method in methods, calls trajectory_separation on the trials for one subject and extracts scalar summaries per condition pair.

Returns:

Columns: subject, method, pair (string "A_vs_B"), label_a, label_b, metric, value. Metric values: peak_separation, peak_separation_time, auc_separation; all three are NaN for a curve with a missing time point.

Return type:

pd.DataFrame

Parameters:

methods (collections.abc.Sequence[str])

get_separation_timecourses(methods=('centroid', 'mahalanobis'))#

Pooled-across-subjects separation timecourses per condition pair.

Returns:

{method: {(a, b): timecourse_array}} with a and b the condition labels. Use the result directly with coco_pipe.viz.interactive.plot_trajectory_separation.

Return type:

dict

Parameters:

methods (collections.abc.Sequence[str])

slice_time(tmin, tmax)#

Return a new TrajectoryResult restricted to a time window.

Parameters:
Return type:

TrajectoryResult

filter(subjects=None, conditions=None)#

Return a new TrajectoryResult containing only specified subjects/conditions.

Raises:

ValueError – If a condition is not one of the labels, or no trajectory is left.

Parameters:
Return type:

TrajectoryResult

get_kinematic_timecourses(metrics)#

Compute and return continuous kinematic timecourses.

Per-trial metrics yield one curve per trial. Group-level metrics (dispersion) are only defined over a set of trials, so they are computed per condition and repeated across that condition’s trials.

Returns:

Columns: subject, condition, trial, time, metric, value.

Return type:

pd.DataFrame

Parameters:

metrics (collections.abc.Sequence[str])

save(path)#

Save the TrajectoryResult object to disk.

Parameters:

path (str | pathlib.Path)

classmethod load(path)#

Load a TrajectoryResult object from disk.

Parameters:

path (str | pathlib.Path)

Return type:

TrajectoryResult

class coco_pipe.dim_reduction.evaluation.result.EmbeddingQualityResult(X, Z)#

Unified Container for Embedding Quality Metrics.

Provides tidy data views for rank-based dimensionality reduction quality criteria (Trustworthiness, Continuity, LCMC, MRRE).

Parameters:
X#
Z#
property Q: numpy.ndarray#

The co-ranking matrix, computed lazily.

Return type:

numpy.ndarray

get_trustworthiness(k_values)#

Compute trustworthiness for various neighborhood sizes.

Parameters:

k_values (collections.abc.Sequence[int])

Return type:

pandas.DataFrame

get_continuity(k_values)#

Compute continuity for various neighborhood sizes.

Parameters:

k_values (collections.abc.Sequence[int])

Return type:

pandas.DataFrame

get_lcmc(k_values)#

Compute LCMC for various neighborhood sizes.

Parameters:

k_values (collections.abc.Sequence[int])

Return type:

pandas.DataFrame

get_mrre(k_values)#

Compute MRRE (intrusion and extrusion) for various neighborhood sizes.

Parameters:

k_values (collections.abc.Sequence[int])

Return type:

pandas.DataFrame

summary(k_values)#

Compute all quality metrics across all provided k values.

Parameters:

k_values (collections.abc.Sequence[int])

Return type:

pandas.DataFrame

get_shepard_diagram_data(sample_size=1000, random_state=None)#

Return (d_orig, d_emb) sampled pairwise distances.

Parameters:
  • sample_size (int)

  • random_state (int | None)

Return type:

tuple[numpy.ndarray, numpy.ndarray]

save(path)#

Save the EmbeddingQualityResult object to disk.

Parameters:

path (str | pathlib.Path)

classmethod load(path)#

Load an EmbeddingQualityResult object from disk.

Parameters:

path (str | pathlib.Path)

Return type:

EmbeddingQualityResult

class coco_pipe.dim_reduction.evaluation.result.VelocityResult(X, Z, times=None, groups=None)#

Unified Container for Velocity Dynamics Results.

Parameters:
X#
Z#
times = None#
groups = None#
get_velocity_fields(delta_t=1, n_neighbors=30, sigma=0.1)#

Compute and return the velocity vectors in the embedding space.

Parameters:
Return type:

numpy.ndarray

save(path)#

Save the VelocityResult object to disk.

Parameters:

path (str | pathlib.Path)

classmethod load(path)#

Load a VelocityResult object from disk.

Parameters:

path (str | pathlib.Path)

Return type:

VelocityResult