scientific-skills/aeon/references/segmentation.md
Aeon provides algorithms to partition time series into regions with distinct characteristics, identifying change points and boundaries.
BinSegmenter - Recursive binary segmentation
n_segments, cost_functionClaSPSegmenter - Classification Score Profile
FLUSSSegmenter - Fast Low-cost Unipotent Semantic Segmentation
InformationGainSegmenter - Information gain maximization
GreedyGaussianSegmenter - Greedy Gaussian approximation
EAggloSegmenter - Bottom-up merging approach
HMMSegmenter - HMM with Viterbi decoding
HidalgoSegmenter - Heterogeneous Intrinsic Dimensionality Algorithm
RandomSegmenter - Random change point generation
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()
change_points = segmenter.fit_predict(y)
print(f"Detected change points: {change_points}")
Segmenters return change point indices:
# change_points = [100, 200] # Boundaries between segments
# This divides series into: [0:100], [100:200], [200:end]
Identify when time series behavior fundamentally changes:
from aeon.segmentation import InformationGainSegmenter
segmenter = InformationGainSegmenter(k=3) # Up to 3 change points
change_points = segmenter.fit_predict(stock_prices)
Segment sensor data into activities:
from aeon.segmentation import ClaSPSegmenter
segmenter = ClaSPSegmenter()
boundaries = segmenter.fit_predict(accelerometer_data)
Find season transitions in time series:
from aeon.segmentation import HMMSegmenter
segmenter = HMMSegmenter(n_states=4) # 4 seasons
segments = segmenter.fit_predict(temperature_data)
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)
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()