Skill Tracer
Skills › Scientific Agent Skills › aeon › segmentation.md

segmentation.md

178 lines · skills/aeon/references/segmentation.md at 5f2bc03

Open on GitHub
1# Time Series Segmentation
2
3Aeon provides algorithms to partition time series into regions with distinct characteristics, identifying change points and boundaries.
4

Time Series Segmentation

Aeon provides algorithms to partition time series into regions with distinct characteristics, identifying change points and boundaries.

Raw lines 1 to 4
5## Segmentation Algorithms
6

Segmentation Algorithms

Raw lines 5 to 6
7### Binary Segmentation
8- `BinSegmenter` - Recursive binary segmentation
9 - Iteratively splits series at most significant change points
10 - Parameters: `n_cps`, `model`, `min_size`, `jump` (requires ruptures)
11 - **Use when**: Known number of segments, hierarchical structure

Binary Segmentation

  • BinSegmenter - Recursive binary segmentation
  • Iteratively splits series at most significant change points
  • Parameters: n_cps, model, min_size, jump (requires ruptures)
  • Use when: Known number of segments, hierarchical structure
Raw lines 7 to 12
13### Classification-Based
14- `ClaSPSegmenter` - Classification Score Profile
15 - Uses classification performance to identify boundaries
16 - Discovers segments where classification distinguishes neighbors
17 - **Use when**: Segments have different temporal patterns

Classification-Based

  • ClaSPSegmenter - Classification Score Profile
  • Uses classification performance to identify boundaries
  • Discovers segments where classification distinguishes neighbors
  • Use when: Segments have different temporal patterns
Raw lines 13 to 18
19### Fast Pattern-Based
20- `FLUSSSegmenter` - Fast Low-cost Unipotent Semantic Segmentation
21 - Efficient semantic segmentation using arc crossings
22 - Based on matrix profile
23 - **Use when**: Large time series, need speed and pattern discovery

Fast Pattern-Based

  • FLUSSSegmenter - Fast Low-cost Unipotent Semantic Segmentation
  • Efficient semantic segmentation using arc crossings
  • Based on matrix profile
  • Use when: Large time series, need speed and pattern discovery
Raw lines 19 to 24
25### Information Theory
26- `InformationGainSegmenter` - Information gain maximization
27 - Finds boundaries maximizing information gain
28 - **Use when**: Statistical differences between segments

Information Theory

  • InformationGainSegmenter - Information gain maximization
  • Finds boundaries maximizing information gain
  • Use when: Statistical differences between segments
Raw lines 25 to 29
30### Gaussian Modeling
31- `GreedyGaussianSegmenter` - Greedy Gaussian approximation
32 - Models segments as Gaussian distributions
33 - Incrementally adds change points
34 - **Use when**: Segments follow Gaussian distributions

Gaussian Modeling

  • GreedyGaussianSegmenter - Greedy Gaussian approximation
  • Models segments as Gaussian distributions
  • Incrementally adds change points
  • Use when: Segments follow Gaussian distributions
Raw lines 30 to 35
36### Hierarchical Agglomerative
37- `EAggloSegmenter` - Bottom-up merging approach
38 - Estimates change points via agglomeration
39 - **Use when**: Want hierarchical segmentation structure

Hierarchical Agglomerative

  • EAggloSegmenter - Bottom-up merging approach
  • Estimates change points via agglomeration
  • Use when: Want hierarchical segmentation structure
Raw lines 36 to 40
41### Hidden Markov Models
42- `HMMSegmenter` - HMM with Viterbi decoding
43 - Probabilistic state-based segmentation
44 - **Use when**: Segments represent hidden states

Hidden Markov Models

  • HMMSegmenter - HMM with Viterbi decoding
  • Probabilistic state-based segmentation
  • Use when: Segments represent hidden states
Raw lines 41 to 45
46### Dimensionality-Based
47- `HidalgoSegmenter` - Heterogeneous Intrinsic Dimensionality Algorithm
48 - Detects changes in local dimensionality
49 - **Use when**: Dimensionality shifts between segments

Dimensionality-Based

  • HidalgoSegmenter - Heterogeneous Intrinsic Dimensionality Algorithm
  • Detects changes in local dimensionality
  • Use when: Dimensionality shifts between segments
Raw lines 46 to 50
51### Baseline
52- `RandomSegmenter` - Random change point generation
53 - **Use when**: Need null hypothesis baseline

Baseline

  • RandomSegmenter - Random change point generation
  • Use when: Need null hypothesis baseline
Raw lines 51 to 54
55## Quick Start
57```python
58from aeon.segmentation import ClaSPSegmenter
59import numpy as np
61# Create time series with regime changes
62y = np.concatenate([
63 np.sin(np.linspace(0, 10, 100)), # Segment 1
64 np.cos(np.linspace(0, 10, 100)), # Segment 2
65 np.sin(2 * np.linspace(0, 10, 100)) # Segment 3
66])
68# Segment the series
69segmenter = ClaSPSegmenter(period_length=20, n_cps=2)
70change_points = segmenter.fit_predict(y)
72print(f"Detected change points: {change_points}")
73```

Quick Start

from aeon.segmentation import ClaSPSegmenter
import numpy as np

# Create time series with regime changes
y = np.concatenate([
    np.sin(np.linspace(0, 10, 100)),      # Segment 1
    np.cos(np.linspace(0, 10, 100)),      # Segment 2
    np.sin(2 * np.linspace(0, 10, 100))   # Segment 3
])

# Segment the series
segmenter = ClaSPSegmenter(period_length=20, n_cps=2)
change_points = segmenter.fit_predict(y)

print(f"Detected change points: {change_points}")
Raw lines 55 to 74
75## Output Format
77Output depends on the estimator. ClaSPSegmenter and BinSegmenter return change-point locations; HMMSegmenter and InformationGainSegmenter return a dense state/segment label per timepoint. In this API `returns_dense=True` denotes boundary locations and `False` denotes per-timepoint labels. Check the concrete estimator and convert label changes before calling boundary metrics:
79```python
80# Dense labels to boundaries (when labels is a label per timepoint):
81change_points = np.flatnonzero(np.diff(labels) != 0) + 1
82# e.g. change_points = [100, 200]
83# This divides series into: [0:100], [100:200], [200:end]
84```

Output Format

Output depends on the estimator. ClaSPSegmenter and BinSegmenter return change-point locations; HMMSegmenter and InformationGainSegmenter return a dense state/segment label per timepoint. In this API returns_dense=True denotes boundary locations and False denotes per-timepoint labels. Check the concrete estimator and convert label changes before calling boundary metrics:

# Dense labels to boundaries (when labels is a label per timepoint):
change_points = np.flatnonzero(np.diff(labels) != 0) + 1
# e.g. change_points = [100, 200]
# This divides series into: [0:100], [100:200], [200:end]
Raw lines 75 to 85
86## Algorithm Selection
88- **Speed priority**: FLUSSSegmenter, BinSegmenter
89- **Accuracy priority**: ClaSPSegmenter, HMMSegmenter
90- **Known segment count**: BinSegmenter(n_cps=number_of_segments - 1)
91- **Chosen boundary budget**: ClaSPSegmenter uses n_cps; InformationGainSegmenter uses k_max. Defaults do not infer an unconstrained number of regimes
92- **Pattern changes**: FLUSSSegmenter, ClaSPSegmenter
93- **Statistical changes**: InformationGainSegmenter, GreedyGaussianSegmenter
94- **State transitions**: HMMSegmenter
96The snippets using domain variables are illustrative templates; the synthetic ClaSP, information-gain, and HMM examples were exercised on aeon 1.6.

Algorithm Selection

  • Speed priority: FLUSSSegmenter, BinSegmenter
  • Accuracy priority: ClaSPSegmenter, HMMSegmenter
  • Known segment count: BinSegmenter(n_cps=number_of_segments - 1)
  • Chosen boundary budget: ClaSPSegmenter uses n_cps; InformationGainSegmenter uses k_max. Defaults do not infer an unconstrained number of regimes
  • Pattern changes: FLUSSSegmenter, ClaSPSegmenter
  • Statistical changes: InformationGainSegmenter, GreedyGaussianSegmenter
  • State transitions: HMMSegmenter

The snippets using domain variables are illustrative templates; the synthetic ClaSP, information-gain, and HMM examples were exercised on aeon 1.6.

Raw lines 86 to 97
98## Common Use Cases

Common Use Cases

Raw lines 98 to 99
100### Regime Change Detection
101Identify when time series behavior fundamentally changes:
103```python
104from aeon.segmentation import InformationGainSegmenter
106segmenter = InformationGainSegmenter(k_max=3)
107# Positive multivariate channels; single-channel entropy is uninformative.
108sensor_channels = np.random.default_rng(42).uniform(0.1, 1, (2, 100))
109labels = segmenter.fit_predict(sensor_channels, axis=1)
110change_points = np.flatnonzero(np.diff(labels) != 0) + 1
111```

Regime Change Detection

Identify when time series behavior fundamentally changes:

from aeon.segmentation import InformationGainSegmenter

segmenter = InformationGainSegmenter(k_max=3)
# Positive multivariate channels; single-channel entropy is uninformative.
sensor_channels = np.random.default_rng(42).uniform(0.1, 1, (2, 100))
labels = segmenter.fit_predict(sensor_channels, axis=1)
change_points = np.flatnonzero(np.diff(labels) != 0) + 1
Raw lines 100 to 112
113### Activity Segmentation
114Segment sensor data into activities:
116```python
117from aeon.segmentation import ClaSPSegmenter
119segmenter = ClaSPSegmenter(period_length=20, n_cps=2)
120boundaries = segmenter.fit_predict(sensor_magnitude) # one univariate series
121```

Activity Segmentation

Segment sensor data into activities:

from aeon.segmentation import ClaSPSegmenter

segmenter = ClaSPSegmenter(period_length=20, n_cps=2)
boundaries = segmenter.fit_predict(sensor_magnitude)  # one univariate series
Raw lines 113 to 122
123### Seasonal Boundary Detection
124Decode a two-state example with known emission and transition probabilities. HMMSegmenter does not learn those parameters from observations:
126```python
127from aeon.segmentation import HMMSegmenter
128from scipy.stats import norm
130segmenter = HMMSegmenter(
131 emission_funcs=[(norm.pdf, {"loc": 0, "scale": 0.5}),
132 (norm.pdf, {"loc": 5, "scale": 0.5})],
133 transition_prob_mat=np.array([[0.95, 0.05], [0.05, 0.95]]),
135observations = np.array([0.1, -0.1, 0.2, 4.9, 5.1, 5.0])
136segments = segmenter.fit_predict(observations)
137```

Seasonal Boundary Detection

Decode a two-state example with known emission and transition probabilities. HMMSegmenter does not learn those parameters from observations:

from aeon.segmentation import HMMSegmenter
from scipy.stats import norm

segmenter = HMMSegmenter(
    emission_funcs=[(norm.pdf, {"loc": 0, "scale": 0.5}),
                    (norm.pdf, {"loc": 5, "scale": 0.5})],
    transition_prob_mat=np.array([[0.95, 0.05], [0.05, 0.95]]),
)
observations = np.array([0.1, -0.1, 0.2, 4.9, 5.1, 5.0])
segments = segmenter.fit_predict(observations)
Raw lines 123 to 138
139## Evaluation Metrics
141Use segmentation quality metrics:
143```python
144from aeon.benchmarking.metrics.segmentation import (
145 count_error,
146 hausdorff_error
149# Count error: difference in number of change points
150count_err = count_error(y_true, y_pred)
152# Hausdorff: maximum distance between predicted and true points
153hausdorff_err = hausdorff_error(y_true, y_pred)
154```

Evaluation Metrics

Use segmentation quality metrics:

from aeon.benchmarking.metrics.segmentation import (
    count_error,
    hausdorff_error
)

# Count error: difference in number of change points
count_err = count_error(y_true, y_pred)

# Hausdorff: maximum distance between predicted and true points
hausdorff_err = hausdorff_error(y_true, y_pred)
Raw lines 139 to 155
156## Best Practices
1581. **Normalize data**: Ensures change detection not dominated by scale
1592. **Choose appropriate metric**: Different algorithms optimize different criteria
1603. **Validate segments**: Visualize to verify meaningful boundaries
1614. **Handle noise**: Consider smoothing before segmentation
1625. **Domain knowledge**: Use expected segment count if known
1636. **Parameter tuning**: Adjust sensitivity parameters (thresholds, penalties)

Best Practices

  1. Normalize data: Ensures change detection not dominated by scale
  2. Choose appropriate metric: Different algorithms optimize different criteria
  3. Validate segments: Visualize to verify meaningful boundaries
  4. Handle noise: Consider smoothing before segmentation
  5. Domain knowledge: Use expected segment count if known
  6. Parameter tuning: Adjust sensitivity parameters (thresholds, penalties)
Raw lines 156 to 164
165## Visualization
167```python
168import matplotlib.pyplot as plt
170plt.figure(figsize=(12, 4))
171plt.plot(y, label='Time Series')
172for cp in change_points:
173 plt.axvline(cp, color='r', linestyle='--', label='Change Point')
174plt.legend()
175plt.show()
176```
178Sources: [segmentation API](https://www.aeon-toolkit.org/en/stable/api_reference/segmentation.html), [release source](https://github.com/aeon-toolkit/aeon/tree/v1.6.0/aeon/segmentation).

Visualization

import matplotlib.pyplot as plt

plt.figure(figsize=(12, 4))
plt.plot(y, label='Time Series')
for cp in change_points:
    plt.axvline(cp, color='r', linestyle='--', label='Change Point')
plt.legend()
plt.show()

Sources: segmentation API, release source.

Raw lines 165 to 178