tanat.metric.trajectory package#
Subpackages#
Submodules#
tanat.metric.trajectory.base module#
TrajectoryMetric ABC: base class for all trajectory-level distance metrics.
- class tanat.metric.trajectory.base.TrajectoryMetric(settings=None, storage: StorageOptions | dict | None = None)[source]#
Bases:
SettingsMixin,Registrable,DisplayMixin,ABCAbstract base for trajectory-level distance metrics.
Computes a scalar distance between two
Trajectoryobjects and a full pairwiseDistanceMatrixover aTrajectoryPool.- MEMMAP_SUPPORT: bool = False[source]#
Set to
Truein subclasses that implement disk-backed (memmap) computation.
- __init__(settings=None, storage: StorageOptions | dict | None = None) None[source]#
- compute_cross_matrix(pool_rows: TrajectoryPool, pool_cols: TrajectoryPool) ndarray[source]#
Compute an asymmetric (n × k) distance matrix between two pools.
Row
i↔ trajectoryiin pool_rows; columnj↔ trajectoryjin pool_cols.Validates both pools, then delegates to
_compute_cross_matrix_impl(). Subclasses override_compute_cross_matrix_impl()to use optimised kernels.- Parameters:
pool_rows – Pool whose trajectories form the rows (n items).
pool_cols – Pool whose trajectories form the columns (k items).
- Returns:
float32 numpy array of shape
(n, k).
- compute_matrix(pool: TrajectoryPool, *, store_path: str | Path | None = None, chunk_size: int = 500, resume: bool = True, dtype: str = 'float32') DistanceMatrix[source]#
Compute full pairwise trajectory distance matrix.
Storage kwargs are forwarded to
StorageOptions.- Parameters:
pool – A
TrajectoryPool.store_path – Storage directory (
None→ in-memory).chunk_size – Rows per flush chunk (default 500).
resume – Skip already-computed chunks (default
True).dtype – Numpy dtype for the matrix (default
"float32").
- Returns:
Module contents#
Trajectory metric sub-package.
- class tanat.metric.trajectory.AggregationSettings(*, default_metric: SequenceMetric = 'linearpairwise', sequence_metrics: dict[str, SequenceMetric] | None = None, agg_fun: str = 'mean', weights: dict[str, float] | None = None)[source]#
Bases:
objectSettings for
AggregationTrajectoryMetric.agg_funandweightsare orthogonal:"mean"+ weights computes a weighted mean,"sum"+ weights a weighted sum. Aliases absent fromweightsdefault to1.0.- default_metric: SequenceMetric = 'linearpairwise'[source]#
- model_dump(*, mode='python', **dump_kwargs)[source]#
Dump settings to a dict via Pydantic serialization.
- sequence_metrics: dict[str, SequenceMetric] | None = None[source]#
- class tanat.metric.trajectory.AggregationTrajectoryMetric(default_metric: SequenceMetric | str = 'linearpairwise', sequence_metrics: dict[str, SequenceMetric | str] | None = None, agg_fun: str = 'mean', weights: dict[str, float] | None = None, *, store_path: str | Path | None = None, chunk_size: int = 500, resume: bool = True, dtype: str = 'float32')[source]#
Bases:
TrajectoryMetricTrajectory distance by per-alias sequence distances, then weighted aggregation.
For each store alias visible on both trajectories, computes the sequence-level distance using the configured
SequenceMetric. The resulting per-alias distances are aggregated (weighted mean/sum) into a scalar trajectory distance.Example:
hamming = HammingEntityMetric(entity_feature="status") lp = LinearPairwiseSequenceMetric(entity_metric=hamming) agg = AggregationTrajectoryMetric( default_metric=lp, agg_fun="mean", weights={"events": 1.0, "states": 0.5}, ) dist = agg(traj_a, traj_b) dm = agg.compute_matrix(traj_pool)
- MEMMAP_SUPPORT: bool = True[source]#
Set to
Truein subclasses that implement disk-backed (memmap) computation.
- SETTINGS_CLASS[source]#
alias of
AggregationSettings
- __init__(default_metric: SequenceMetric | str = 'linearpairwise', sequence_metrics: dict[str, SequenceMetric | str] | None = None, agg_fun: str = 'mean', weights: dict[str, float] | None = None, *, store_path: str | Path | None = None, chunk_size: int = 500, resume: bool = True, dtype: str = 'float32') None[source]#
- class tanat.metric.trajectory.TrajectoryMetric(settings=None, storage: StorageOptions | dict | None = None)[source]#
Bases:
SettingsMixin,Registrable,DisplayMixin,ABCAbstract base for trajectory-level distance metrics.
Computes a scalar distance between two
Trajectoryobjects and a full pairwiseDistanceMatrixover aTrajectoryPool.- MEMMAP_SUPPORT: bool = False[source]#
Set to
Truein subclasses that implement disk-backed (memmap) computation.
- __init__(settings=None, storage: StorageOptions | dict | None = None) None[source]#
- compute_cross_matrix(pool_rows: TrajectoryPool, pool_cols: TrajectoryPool) ndarray[source]#
Compute an asymmetric (n × k) distance matrix between two pools.
Row
i↔ trajectoryiin pool_rows; columnj↔ trajectoryjin pool_cols.Validates both pools, then delegates to
_compute_cross_matrix_impl(). Subclasses override_compute_cross_matrix_impl()to use optimised kernels.- Parameters:
pool_rows – Pool whose trajectories form the rows (n items).
pool_cols – Pool whose trajectories form the columns (k items).
- Returns:
float32 numpy array of shape
(n, k).
- compute_matrix(pool: TrajectoryPool, *, store_path: str | Path | None = None, chunk_size: int = 500, resume: bool = True, dtype: str = 'float32') DistanceMatrix[source]#
Compute full pairwise trajectory distance matrix.
Storage kwargs are forwarded to
StorageOptions.- Parameters:
pool – A
TrajectoryPool.store_path – Storage directory (
None→ in-memory).chunk_size – Rows per flush chunk (default 500).
resume – Skip already-computed chunks (default
True).dtype – Numpy dtype for the matrix (default
"float32").
- Returns: