10个版本 (2个稳定版)

1.0.1 2024年3月12日
0.7.0 2023年10月12日
0.6.0 2023年9月22日
0.5.0 2023年6月3日
0.1.1 2023年5月19日

#268 in 数学

Download history 3/week @ 2024-05-20 7/week @ 2024-06-03 5/week @ 2024-06-10 2/week @ 2024-06-24 5/week @ 2024-07-01 5/week @ 2024-07-15 93/week @ 2024-07-29

每月103次下载
用于 csta_derive

GPL-3.0-or-later

64KB
1.5K SLoC

CSTA

一个支持蒙特卡洛的个人统计库。

使用方法

csta 添加到 Cargo.toml。

[dependencies]
csta = "1.0.0"
csta_derive = version = "1.0.0"
rand = "0.8.5"

直方图

let mut hist = Hist::with_buckets(0.0, 6.0, 6);
let mut rng = thread_rng();

for _ in 0..1000 {
    let x = rng.gen_range(0.0..6.0);
    hist.add(&x);
}

println!("avg: {}, sd: {}", hist.average(), hist.variance().sqrt());

为了保存直方图,结构体包含一个保存函数。

hist.save("./histogram");

作为一个便利函数,存在 save numpy,这使得使用matplotlib进行绘图更容易。

hist.save_numpy("./histogram");
import matplotlib.pyplot as plt
import numpy as np

[counts, bins] = np.loadtxt("histogram", delimiter=",")
# the first count is a filler, so we remove it
counts = counts[1:]
plt.stairs(counts, bins, fill=True)
plt.show()

更完整的例子在文件中。Python绘图器的代码在这里

可随机化和蒙特卡洛

可随机化是一个可派生的特性,用于生成具有随机值的结构体。

#[derive(Debug, Randomizable)]
struct Dice<const N: usize>(#[rng(range(1..=N))] usize);

任何可随机化都可以用于蒙特卡洛迭代器。

MonteCarlo::default()
    .into_iter()
    .take(10)
    .for_each(|dice: Dice<6> /* type anotations needed */| {
        println!("dice: {:?}", dice);
    });

任何可随机化的元组都是可随机化的,f64是可随机化的。要了解更多关于可随机化派生和蒙特卡洛的信息,请参阅文件。

索引

提供索引实用工具,用于ising系统。

马尔可夫

马尔可夫链系统。在ising粒子中的Lennard-Jones中使用。

预定义

为方便使用库而常用的类型。

依赖

~245–420KB