簡體   English   中英

如何使用 future.callr 抑制隨機數生成警告?

[英]How do I suppress a random number generation warning with future.callr?

我正在使用future.callr ,它會在每次請求未來時創建一個新線程(?),因此它是單獨計算的,主要的 R 腳本可以繼續前進。

當我的期貨回來時,我收到以下警告:

    Warning message:
UNRELIABLE VALUE: Future (‘<none>’) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".

在我運行的實際代碼中,它只是加載一些數據,我不知道為什么(或關心編輯:我關心,見下面的評論)它生成隨機數。 如何阻止顯示該警告(修復 rng 生成或忽略它)?

我有很多關於期貨的行,所以我希望能夠以某種方式在開始時設置選項,而不必將它添加到每一行。

這是一個例子,我試圖忽略警告。

library(future.callr)

set.seed(1234567)
future.seed = TRUE

#normal random number - no problem
a<-runif(1)
print(a)

#random number in future, using callr plan
plan(callr, future.rng.onMisuse = 'ignore')

b %<-% runif(1)
print(b)

請參閱help("%seed%", package = "future")

您可以像下面這樣使用%seed%

b %<-% runif(1) %seed% TRUE # seed is set by future pkg
print(b)

# or
b %<-% runif(1) %seed% 1234567 # your seed
print(b)

或者禁用檢查

options(future.rng.onMisuse = "ignore")
b %<-% runif(1)
print(b)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM