23 个版本 (12 个重大更新)

0.14.2 2024年7月14日
0.14.1 2023年8月8日
0.14.0 2023年6月16日
0.13.1 2023年3月1日
0.1.0 2019年8月8日

#144机器学习

Download history 4/week @ 2024-05-12 74/week @ 2024-05-19 70/week @ 2024-05-26 312/week @ 2024-06-02 1/week @ 2024-06-09 705/week @ 2024-06-16 605/week @ 2024-06-23 154/week @ 2024-06-30 38/week @ 2024-07-07 471/week @ 2024-07-14 357/week @ 2024-07-28 18/week @ 2024-08-04

847 每月下载量
用于 augurs-changepoint

MIT 许可证

1MB
1K SLoC

changepoint - Rust 的变化点检测库

Changepoint 是一个用于对数据流进行变化点检测的库。

Crates.io docs.rs

有关 Python 绑定的更多信息,请参阅此处

算法

包括以下变化点检测算法

  • Bocpd -- 在线贝叶斯变化点检测 参考
  • BocpdTruncated -- 与 Bocpd 相同,但在那些长度不太可能时截断运行长度分布。
  • Argpcp -- 高斯过程变化点检测器 参考

示例

//! A demo of the online Bayesian change point detection on
//! the 3-month Treasury Bill Secondary Market Rate from
//!
//! After this example is run, the file `trasury_bill.ipynb` can be run to generate
//! plots for this dataset.
//!
//! > Board of Governors of the Federal Reserve System (US), 3-Month Treasury Bill: Secondary
//! > Market Rate [TB3MS], retrieved from FRED, Federal Reserve Bank of St. Louis;
//! > https://fred.stlouisfed.org/series/TB3MS, August 5, 2019.

use changepoint::{utils::*, BocpdTruncated, BocpdLike};
use rv::prelude::*;
use std::io;
use std::path::PathBuf;
use std::fs::read_to_string;

fn main() -> io::Result<()> {
    // Parse the data from the TB3MS dataset
    let mut csv_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    csv_path.push("resources/TB3MS.csv");
    let data: String = read_to_string(&csv_path)?;
    let (dates, pct_change): (Vec<&str>, Vec<f64>) = data
        .lines()
        .skip(1)
        .map(|line| {
            let split: Vec<&str> = line.splitn(2, ',').collect();
            let date = split[0];
            let raw_pct = split[1];
            (date, raw_pct.parse::<f64>().unwrap())
        })
        .unzip();

    // Create the Bocpd processor
    let mut cpd = BocpdTruncated::new(
        250.0,
        NormalGamma::new_unchecked(0.0, 1.0, 1.0, 1.0),
    );

    // Feed data into change point detector and generate a sequence of run-length distributions
    let rs: Vec<Vec<f64>> = pct_change
        .iter()
        .map(|d| cpd.step(d).into())
        .collect();

    // Determine most likely change points
    let change_points: Vec<usize> = map_changepoints(&rs);
    let change_dates: Vec<&str> =
        change_points.iter().map(|&i| dates[i]).collect();

    // Write output for processing my `trasury_bill.ipynb`.
    write_data_and_r(
        "treasury_bill_output",
        &pct_change,
        &rs,
        &change_points,
    )?;

    println!("Most likely dates of changes = {:#?}", change_dates);

    Ok(())
}

要运行此示例,从源根目录运行 cargo run --example treasury_bill。配套笔记本可用于生成以下图表

Treasury Bill Plots

依赖项

~13MB
~245K SLoC