Skip to main content

Pelt

Struct Pelt 

Source
pub struct Pelt { /* private fields */ }
Expand description

PELT changepoint detector.

Implements the Pruned Exact Linear Time algorithm for detecting multiple changepoints in a univariate time series.

§Examples

use u_analytics::detection::{Pelt, CostFunction, Penalty};

// Data with a mean shift at index 50
let mut data: Vec<f64> = vec![0.0; 50];
data.extend(vec![5.0; 50]);

let pelt = Pelt::new(CostFunction::L2, Penalty::Bic).unwrap();
let result = pelt.detect(&data);
assert!(!result.changepoints.is_empty());
// The detected changepoint should be near index 50
assert!((result.changepoints[0] as i64 - 50).unsigned_abs() <= 2);

§References

Killick, R., Fearnhead, P., & Eckley, I.A. (2012). “Optimal Detection of Changepoints with a Linear Computational Cost”, JASA 107(500), pp. 1590-1598.

Implementations§

Source§

impl Pelt

Source

pub fn new(cost: CostFunction, penalty: Penalty) -> Option<Self>

Creates a new PELT detector with the given cost function and penalty.

Uses a default minimum segment length of 2.

§Returns

None if a custom penalty is not positive or not finite.

§Reference

Killick et al. (2012), §2.2: penalty must be positive to avoid trivial solutions (changepoint at every observation).

Source

pub fn with_min_segment_len( cost: CostFunction, penalty: Penalty, min_segment_len: usize, ) -> Option<Self>

Creates a PELT detector with a custom minimum segment length.

§Parameters
  • cost: Cost function for segment evaluation
  • penalty: Penalty per changepoint
  • min_segment_len: Minimum number of observations per segment. Must be >= 2 (needed for variance estimation in Normal cost).
§Returns

None if parameters are invalid.

Source

pub fn detect(&self, data: &[f64]) -> PeltResult

Detects changepoints in the given data.

Returns a PeltResult containing the detected changepoint indices. If the data is too short (fewer than 2 * min_segment_len observations), no changepoints can be detected and an empty result is returned.

Non-finite values (NaN, Infinity) are not supported in the input. The data should be pre-cleaned; non-finite values will lead to incorrect cost computations.

§Examples
use u_analytics::detection::{Pelt, CostFunction, Penalty};

// Two changepoints: shift up at 30, shift down at 70
let mut data = vec![0.0; 30];
data.extend(vec![3.0; 40]);
data.extend(vec![0.0; 30]);

let pelt = Pelt::new(CostFunction::L2, Penalty::Bic).unwrap();
let result = pelt.detect(&data);
assert_eq!(result.changepoints.len(), 2);
§Complexity

Expected O(n), worst case O(n^2).

Source

pub fn detect_multi(&self, signals: &[&[f64]]) -> Option<MultiPeltResult>

Detects changepoints in multivariate (multi-signal) data.

Each inner slice represents one signal channel. All channels must have the same length. The cost function is applied independently to each channel and summed — a single set of changepoints is returned that applies to all channels simultaneously.

The penalty scales with the number of channels: penalty * n_channels.

§Parameters
  • signals: slice of signal channels, each of length n
§Returns

None if channels have inconsistent lengths. Otherwise returns Some(MultiPeltResult).

§Examples
use u_analytics::detection::{Pelt, CostFunction, Penalty};

let signal_a: Vec<f64> = [vec![0.0; 50], vec![5.0; 50]].concat();
let signal_b: Vec<f64> = [vec![0.0; 50], vec![3.0; 50]].concat();

let pelt = Pelt::new(CostFunction::L2, Penalty::Bic).unwrap();
let result = pelt.detect_multi(&[&signal_a, &signal_b]).unwrap();
assert!(!result.changepoints.is_empty());
§Reference

Killick, R. & Eckley, I.A. (2014). “changepoint: An R Package for Changepoint Analysis”, Journal of Statistical Software 58(3).

§Complexity

Expected O(n * k), worst case O(n^2 * k) where k = number of channels.

Auto Trait Implementations§

§

impl Freeze for Pelt

§

impl RefUnwindSafe for Pelt

§

impl Send for Pelt

§

impl Sync for Pelt

§

impl Unpin for Pelt

§

impl UnsafeUnpin for Pelt

§

impl UnwindSafe for Pelt

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V