2个版本
0.1.1 | 2022年1月31日 |
---|---|
0.1.0 | 2020年11月22日 |
#287 in 科学
9KB
102 行
typescript中的Benford定律领先数字模拟器
遵循Benford定律的领先数字数据集模拟器。用Rust构建。
安装与构建
git clone https://github.com/drconopoima/benford-law-simulator-rust.git
cd benford-law-simulator-rust
cargo build --release
运行
您可以通过手动指定范围的上限 --max
(-m
) 和下限 --min
(-n
) 来进行模拟
cargo run --release -- --max 12345 --lead-digits 1 \
--samplecount 1000 --min 1
您还可以使用coreutils库中的shuf或其他任何随机数生成器生成范围内的随机数。
cargo run --release -- --lead-digits 1 --sample-size 10000 \
--min 1 --max $(shuf -i 10-100000 -n 1|tee >&2|cat)
预期的输出如下所示
50547
Finished release [optimized] target(s) in 0.02s
Running `target/release/benford-law-simulator-rust --lead-digits 1
--sample-size 10000 --min 1 --max 50547`
Lead digits counts:
[(1.0, 2214.0), (2.0, 1848.0), (3.0, 1632.0), (4.0, 1490.0), (5.0, 1313.0),
(6.0, 797.0), (7.0, 249.0), (8.0, 226.0), (9.0, 231.0)]
⡇⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⡁ 2214.0
⠧⠤⠤⠤⠤⠤⠤⢤ ⠄
⠂ ⠒⠒⠒⠒⠒⠒⠒⡆ ⠂
⡁ ⠉⠉⠉⠉⠉⢹⣀⣀⣀⣀⣀⣀⣀ ⡁
⠄ ⡇ ⠄
⠂ ⣇⣀⣀⣀⣀⣀⣀ ⠂
⡁ ⢸ ⡁
⠄ ⢸ ⠄
⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉ 226.0
1.0 9.0
如上输出所示,生成的数据的上限设置为50547。
您还可以直接通过其路径运行二进制发布构建
$ ./target/release/benford-law-simulator-rust -s 10 --min 1 \
-m 307212 --lead-digits 1
Lead digits counts:
[(1.0, 3.0), (2.0, 2.0), (3.0, 1.0), (4.0, 1.0), (7.0, 1.0),
(8.0, 2.0)]
⡇⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⠁⠈ ⡁ 3.0
⡇ ⠄
⡇ ⠂
⡇ ⡁
⠍⠉⠉⠉⠉⠉⢹ ⡏⠉⠉⠉⠉⠉⠉⠉ ⠄
⠂ ⢸ ⡇ ⠂
⡁ ⢸ ⡇ ⡁
⠄ ⢸ ⡇ ⠄
⠁⠈ ⠁⠈ ⠁⠈⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁⠈ ⠁⠈ ⠁⠈ 1.0
1.0 9.0
如果您想获取生成的样本,可以传递可选的 --debug (-d)
标志
$ benford-law-simulator-rust --sample-size 10 -n 1 \
--max 307212 -l 1
Simulated sample data:
[86461, 37359, 202275, 81769, 71067, 43553, 294327, 128148,
136278, 17016]
Lead digits:
[8, 3, 2, 8, 7, 4, 2, 1, 1, 1]
...
您还可以使用选项 --lead-digits (-l)
生成领先数字对或任何领先数字计数的输出
cargo run --release -- --lead-digits 2 -m 10000 -n 10 -s 1000
依赖项
~3–14MB
~116K SLoC