Crates.io | smoothed_z_score |
lib.rs | smoothed_z_score |
version | 0.1.3 |
source | src |
created_at | 2017-11-10 21:48:46.329029 |
updated_at | 2017-11-10 21:48:46.329029 |
description | Smoothed z-score algo (very robust thresholding algorithm) |
homepage | https://github.com/swizard0/smoothed_z_score |
repository | https://github.com/swizard0/smoothed_z_score |
max_upload_size | |
id | 38919 |
size | 6,787 |
Rust implementation for Smoothed z-score algorithm.
Add this to your Cargo.toml
:
[dependencies]
smoothed_z_score = "0.1"
and this to your crate root:
extern crate smoothed_z_score;
Consider this dataset (from the original stackoverflow reply):
use smoothed_z_score::{Peak, PeaksDetector, PeaksFilter};
fn main() {
let input = vec![
1.0, 1.0, 1.1, 1.0, 0.9, 1.0, 1.0, 1.1, 1.0, 0.9, 1.0, 1.1, 1.0, 1.0, 0.9, 1.0, 1.0, 1.1, 1.0,
1.0, 1.0, 1.0, 1.1, 0.9, 1.0, 1.1, 1.0, 1.0, 0.9, 1.0, 1.1, 1.0, 1.0, 1.1, 1.0, 0.8, 0.9, 1.0,
1.2, 0.9, 1.0, 1.0, 1.1, 1.2, 1.0, 1.5, 1.0, 3.0, 2.0, 5.0, 3.0, 2.0, 1.0, 1.0, 1.0, 0.9, 1.0,
1.0, 3.0, 2.6, 4.0, 3.0, 3.2, 2.0, 1.0, 1.0, 0.8, 4.0, 4.0, 2.0, 2.5, 1.0, 1.0, 1.0
];
let output: Vec<_> = input
.into_iter()
.enumerate()
.peaks(PeaksDetector::new(30, 5.0, 0.0), |e| e.1)
.map(|((i, _), p)| (i, p))
.collect();
assert_eq!(output, vec![
(45, Peak::High), (47, Peak::High), (48, Peak::High), (49, Peak::High),
(50, Peak::High), (51, Peak::High), (58, Peak::High), (59, Peak::High),
(60, Peak::High), (61, Peak::High), (62, Peak::High), (63, Peak::High),
(67, Peak::High), (68, Peak::High), (69, Peak::High), (70, Peak::High),
]);
}