pub struct SampleEntropy { /* private fields */ }Expand description
Sample Entropy (SampEn) — Richman & Moorman’s measure of how regular (i.e.
predictable) a series is: the negative log conditional probability that two
sub-sequences similar for m points stay similar at the next point.
tol = r_factor · stddev(window)
B = # template pairs of length m within tol (i < j)
A = # template pairs of length m+1 within tol (i < j)
`SampEn` = − ln(A / B)Low SampEn means the window is regular — patterns of length m reliably
extend to length m + 1, the fingerprint of a trending or cyclic market. High
SampEn means the series is irregular — knowing the last m points tells
you little about the next, the fingerprint of noise. Unlike the older
approximate entropy (ApEn), SampEn excludes self-matches, so it is far less
biased on short windows.
The tolerance is r_factor times the window’s standard deviation, so the
measure self-scales. A perfectly flat window (stddev == 0) is maximally
regular and returns 0. If no length-m pairs match, the entropy is
undefined and 0 is returned; if length-m pairs match but none extend, the
estimator falls back to treating the unseen count as one (−ln(1/B) = ln(B)).
The first value lands after period inputs; each update is O(period²).
§Example
use wickra_core::{Indicator, SampleEntropy};
let mut indicator = SampleEntropy::new(50, 2, 0.2).unwrap();
let mut last = None;
for i in 0..80 {
last = indicator.update((f64::from(i) * 0.3).sin() * 5.0);
}
assert!(last.is_some());Implementations§
Source§impl SampleEntropy
impl SampleEntropy
Sourcepub fn new(period: usize, m: usize, r_factor: f64) -> Result<Self>
pub fn new(period: usize, m: usize, r_factor: f64) -> Result<Self>
Construct a Sample Entropy over period values with embedding dimension
m and tolerance factor r_factor.
§Errors
Returns Error::PeriodZero if period or m is 0,
Error::InvalidPeriod if period < m + 2 (no length-m+1 template
pairs otherwise), and Error::InvalidParameter if r_factor is not
finite and positive.
Trait Implementations§
Source§impl Clone for SampleEntropy
impl Clone for SampleEntropy
Source§fn clone(&self) -> SampleEntropy
fn clone(&self) -> SampleEntropy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SampleEntropy
impl Debug for SampleEntropy
Source§impl Indicator for SampleEntropy
impl Indicator for SampleEntropy
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: f64) -> Option<f64>
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
None output can be produced.Auto Trait Implementations§
impl Freeze for SampleEntropy
impl RefUnwindSafe for SampleEntropy
impl Send for SampleEntropy
impl Sync for SampleEntropy
impl Unpin for SampleEntropy
impl UnsafeUnpin for SampleEntropy
impl UnwindSafe for SampleEntropy
Blanket Implementations§
Source§impl<T> BatchExt for Twhere
T: Indicator,
impl<T> BatchExt for Twhere
T: Indicator,
Source§fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
None during warmup) per input.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