来自 multivariate-normal-js 的确定性样本

deterministic samples from multivariate-normal-js

我正在使用 multivariate-normal-js,它是 NumPy 的 random.multivariate_normal 的端口。但是,我需要能够产生确定性的结果。有什么办法吗?

multivariate-normal-js 使用逆变换方法从标准正态分布生成样本,并使用 Math.random() 生成逆变换的均匀分布随机输入。因此,为了能够重现(伪)随机序列,您需要能够为 Math.random() 设置随机种子。根据the documentation for Math.random(),这是不可能的。

所以简短的回答是否定的,你做不到。但是请参阅 Seeding the random number generator in Javascript and Seedable JavaScript random number generator (and maybe search for more recent discussions) if you want to try to work around that limitation of Math.random(). If you did that, you would have to replace the call to Math.random() at line 22 of distribution.js 并适当调用 "seedable" 随机数生成器以从 [0, 1] 上的均匀分布生成随机值。