#骰子摇骰器 #加载 #随机 #生成器 # #抽样 #离散

fast_loaded_dice_roller

Rust实现的创新快速加载骰子摇骰器算法(https://arxiv.org/pdf/2003.03830.pdf)

7个版本

0.1.6 2023年8月9日
0.1.5 2023年8月6日

#751算法

每月 25 次下载

MIT 协议

18KB
109

fast_loaded_dice_roller

关于项目

这是一个Rust库和示例程序,旨在推广新型快速加载骰子摇骰器*离散抽样算法的使用。它设计时考虑到通用性、低依赖性和效率。此外,它易于使用,提供可选的默认实现所需的FairCoin特质,并为好奇者提供了FLDR算法的详细文档。

使用方法

可以使用cargo add fast_loaded_dice_roller将库添加到现有的项目中。您可以通过启用rand功能(例如,cargo add fast_loaded_dice_roller --features="rand")包含可选的模板rand::RngCoin<R>实现FairCoin特质,该实现依赖于rand包。

示例程序

可以使用cargo b --example generator --features="rand"构建示例程序。示例程序可以使用默认值运行,cargo r --example generator --features="rand",但它还有以下用法

Rust implementation of the novel Fast Loaded Dice Roller algorithm (https://arxiv.org/pdf/2003.03830.pdf)

Usage: generator [OPTIONS]

Options:
  -r, --roll-count <ROLL_COUNT>                        [default: 100000]
  -v, --verbose
  -p, --print-histogram
  -d, --distribution <DISTRIBUTION> <DISTRIBUTION>...
  -h, --help                                           Print help
  -V, --version                                        Print version

该功能的用法示例为:cargo r --example generator --features="rand" -- -d 1 2 3 -r 6000

引用

我既没有创建也没有发现FLDR算法。这个软件包只是该算法的一个实现。

* Fast Loaded Dice Roller算法的引用

@inproceedings{saad2020fldr,
title           = {The Fast Loaded Dice Roller: A Near-optimal Exact Sampler for Discrete Probability Distributions},
author          = {Saad, Feras A. and Freer, Cameron E. and Rinard, Martin C. and Mansinghka, Vikash K.},
booktitle       = {AISTATS 2020: Proceedings of the 23rd International Conference on Artificial Intelligence and Statistics},
volume          = 108,
series          = {Proceedings of Machine Learning Research},
address         = {Palermo, Sicily, Italy},
publisher       = {PMLR},
year            = 2020,
keywords        = {random variate generation, sampling, discrete random variables},
abstract        = {This paper introduces a new algorithm for the fundamental problem of generating a random integer from a discrete probability distribution using a source of independent and unbiased random coin flips. This algorithm, which we call the Fast Loaded Dice Roller (FLDR), has efficient complexity properties in space and time: the size of the sampler is guaranteed to be linear in the number of bits needed to encode the target distribution and the sampler consumes (in expectation) at most 6.5 bits of entropy more than the information-theoretically minimal rate, independently of the values or size of the target distribution. We present an easy-to-implement, linear-time preprocessing algorithm and a fast implementation of the FLDR using unsigned integer arithmetic. Empirical evaluations establish that the FLDR is 2x--10x faster than multiple baseline algorithms for exact sampling, including the widely-used alias and interval samplers. It also uses up to 10000x less space than the information-theoretically optimal sampler, at the expense of a less than 1.5x runtime overhead.},
}

依赖项

~72KB