pub struct MatrixProfile { /* private fields */ }Expand description
Computed matrix profile for a fixed (series, window) pair.
The profile array is always in 1-to-1 correspondence with the
n − m + 1 candidate subsequences; profile[i] is the nearest
non-trivial-neighbour distance for subsequence T[i..i+m], and
index[i] is that neighbour’s starting offset.
§Examples
use anomstream_core::MatrixProfile;
// Synthetic: smooth cosine with one injected spike near i=48.
let mut series: Vec<f64> = (0..128)
.map(|i| (f64::from(i as i32) * 0.3).cos())
.collect();
for v in &mut series[48..56] {
*v += 5.0;
}
let mp = MatrixProfile::compute(&series, 8, None).expect("mp");
let (pos, _score) = mp.discord();
assert!((40..=56).contains(&pos));Implementations§
Source§impl MatrixProfile
impl MatrixProfile
Sourcepub fn compute(
series: &[f64],
window: usize,
exclusion_zone: Option<usize>,
) -> RcfResult<Self>
pub fn compute( series: &[f64], window: usize, exclusion_zone: Option<usize>, ) -> RcfResult<Self>
Run STOMP over series with subsequence length window.
exclusion_zone is the half-width of the trivial-match
band around each query (|i − j| < exclusion_zone is
skipped). Pass None for the conventional ceil(window / 4)
default (Keogh / Mueen matrix-profile tutorials).
§Complexity
Time: O(n²) over the series length n, with an extra
O(n · m) one-time cost on the first-column seed (where
m = window). Practical wall-clock: ~3 ms at
(n = 1 024, m = 32), ~49 ms at (n = 4 096, m = 128)
on a modern core. Budget aggressively — doubling n
quadruples the cost. Do not call on hot-path streams;
reserve for forensic windows captured by the online
crate::ShingledForest or triage batch jobs.
Memory: O(n) for the profile + O(n) for the scratch
dot-product column.
§Errors
Returns RcfError::InvalidConfig when
window < MIN_WINDOW, window > MAX_WINDOW, when the
series is too short (series.len() < 2 · window), when
series contains a non-finite value, or when
exclusion_zone would leave zero valid neighbours.
Sourcepub fn exclusion_zone(&self) -> usize
pub fn exclusion_zone(&self) -> usize
Exclusion-zone half-width used when computing this profile.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
true when the profile holds zero subsequences — never
returned by Self::compute, provided as a total accessor.
Sourcepub fn profile_index(&self) -> &[usize]
pub fn profile_index(&self) -> &[usize]
Per-subsequence nearest-neighbour index vector.
Sourcepub fn discord(&self) -> (usize, f64)
pub fn discord(&self) -> (usize, f64)
Discord — subsequence whose nearest neighbour is farthest.
Returns (start_index, distance).
Sourcepub fn discord_topk(&self, k: usize) -> Vec<(usize, f64)>
pub fn discord_topk(&self, k: usize) -> Vec<(usize, f64)>
Top-k discords ranked by descending distance. k is
clamped to Self::len. Uses a greedy suppression pass
that skips any candidate within the exclusion zone of an
already-emitted discord — prevents the top-k from
clustering inside a single anomalous region.
Trait Implementations§
Source§impl Clone for MatrixProfile
impl Clone for MatrixProfile
Source§fn clone(&self) -> MatrixProfile
fn clone(&self) -> MatrixProfile
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MatrixProfile
impl Debug for MatrixProfile
Source§impl<'de> Deserialize<'de> for MatrixProfile
impl<'de> Deserialize<'de> for MatrixProfile
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for MatrixProfile
impl RefUnwindSafe for MatrixProfile
impl Send for MatrixProfile
impl Sync for MatrixProfile
impl Unpin for MatrixProfile
impl UnsafeUnpin for MatrixProfile
impl UnwindSafe for MatrixProfile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more