重現 bootstrap
你在一家線上證券商工作。公司正在開發一款 Android App,提供公司所販售股票的一般價格區間。有一個抽樣函式 boot_price() 可供你計算每月的價格範圍。
為了測試此函式在平行環境下的可重現性,你決定把它套用到清單 ls_micro 的每個元素。這個清單中的每個元素,都是某個月份微軟股票平均每日價格的向量。
已經為你載入 parallel 套件。
本練習屬於課程
R 平行程式設計
練習說明
- 為叢集
cl1設定種子值321,進行第一次執行。 - 為叢集
cl2設定相同的種子值,進行第二次執行。 - 測試輸出
result1與result2是否相同。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
cl1 <- makeCluster(4)
# Set 321 as the seed value for the first run
___(___, ___)
result1 <- parLapply(cl1, ls_micro, boot_price)
stopCluster(cl1)
cl2 <- makeCluster(4)
# Set the same seed value for the second run
___(___, ___)
result2 <- parLapply(cl2, ls_micro, boot_price)
stopCluster(cl2)
# Test if outputs are the same
___(___, ___)