R伪随机数生成在两台不同机器上使用set.seed相同的种子集发生变化
问题: 在 R 上,运行下面的函数会导致在 2 台不同的机器上生成不同的种子(以及不同的随机数集),但使用 Mersenne-Twister 算法使用相同的起始种子:
- 一个在 Docker 容器上的笔记本电脑上;一个在 Docker 容器上。
- 一个位于 docker 容器上的 aws 实例上。 R 是从 RPY2 调用
除此之外,两个环境之间的一切都是相同的:
- docker 镜像是相同的: image docker: rpy2/base-ubuntu:master-20.04
- R 版本是相同的: R版本 3.6.3 (2020-02-29)
function(seed) {
RNGkind("Mersenne-Twister")
set.seed(seed)
LogSystem(Logger, "INFO", "Seed value:")
LogSystem(Logger, "INFO", as.character(seed))
LogSystem(Logger, "INFO", ".Random.seed:")
LogSystem(Logger, "INFO", as.character(
paste(as.character(.Random.seed[1:5]), collapse = " ")
))
s <- as.integer(floor(runif(n = 100,min=1,max=2147483647)))
}
下面是 2 个环境的日志结果:
笔记本电脑:
version:
x86_64-pc-linux-gnu
x86_64
linux-gnu
x86_64, linux-gnu
3
6.3
2020
02
29
77875
R
version 3.6.3 (2020-02-29)
Holding the Windsock
Seed value:
875241372
.Random.seed:
10403 624 -571619272 -1832112935 413134534
Aws 实例
version:
x86_64-pc-linux-gnu
x86_64
linux-gnu
x86_64, linux-gnu
3
6.3
2020
02
29
77875
R
R version 3.6.3 (2020-02-29)
Holding the Windsock
Seed value:
875241372
.Random.seed:
10403 624 -169270483 -442010614 -603558397
知道什么可能导致具有相同环境的两个环境之间生成不同的种子操作系统,相同的 R 版本?
编辑:在AWS上,R是从Rpy2调用的
Issue:
On R, running the function below leads to different seeds generation (and different set of random number) on 2 different machines but with the same starting seed with Mersenne-Twister algorithm:
- one on laptop on a docker container;
- one on an aws instance on a docker container. R is called from RPY2
Apart from that, everything is the same between the 2 environments:
- docker image is the same: image docker: rpy2/base-ubuntu:master-20.04
- R version is the same: R version 3.6.3 (2020-02-29)
function(seed) {
RNGkind("Mersenne-Twister")
set.seed(seed)
LogSystem(Logger, "INFO", "Seed value:")
LogSystem(Logger, "INFO", as.character(seed))
LogSystem(Logger, "INFO", ".Random.seed:")
LogSystem(Logger, "INFO", as.character(
paste(as.character(.Random.seed[1:5]), collapse = " ")
))
s <- as.integer(floor(runif(n = 100,min=1,max=2147483647)))
}
Below the results of the logs for the 2 environments:
Laptop:
version:
x86_64-pc-linux-gnu
x86_64
linux-gnu
x86_64, linux-gnu
3
6.3
2020
02
29
77875
R
version 3.6.3 (2020-02-29)
Holding the Windsock
Seed value:
875241372
.Random.seed:
10403 624 -571619272 -1832112935 413134534
Aws instance
version:
x86_64-pc-linux-gnu
x86_64
linux-gnu
x86_64, linux-gnu
3
6.3
2020
02
29
77875
R
R version 3.6.3 (2020-02-29)
Holding the Windsock
Seed value:
875241372
.Random.seed:
10403 624 -169270483 -442010614 -603558397
Any idea what could lead to different seeds generation between two environments with the same OS, same R version ?
EDIT: On AWS, R is called from Rpy2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论