[閒聊] 替RandomVariate提供提取seed的功能
最近在用MMA跑Monte Carlo,覺得MMA不能提取seed實在是很不方便,所以就做了一個可以
提取seed的RandomVariate
Module[{seed, store = {}, temp = 1, Storing},
RandomMemory[1, opt___] := RandomMemory[temp, opt];
RandomMemory[in__] := (Storing[in]; RandomVariate[in]);
Storing[dist_, opt___] :=
AppendTo[
store, {Evaluate[If[dist === temp, 1, temp = dist]], opt}];
SetSeed[InSeed_, InStore_: {}] := (store = {}; temp = 1;
SeedRandom[seed = InSeed]; (RandomMemory[##];) & @@@ InStore;);
ExtractSeed[] := {seed, store}; SetSeed[0];];
這個設計在跑custom distribution的時候蠻好用的, 不過AppendTo會是瓶頸
目前只有想到hash, 不過有新distribution還是得重建table
不知道有沒有更漂亮的寫法?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.4.208
※ 文章網址: https://www.ptt.cc/bbs/Mathematica/M.1476160101.A.361.html
→
10/11 21:30, , 1F
10/11 21:30, 1F
推
10/11 21:31, , 2F
10/11 21:31, 2F
推
10/12 03:29, , 3F
10/12 03:29, 3F
→
10/12 03:34, , 4F
10/12 03:34, 4F
→
10/12 03:36, , 5F
10/12 03:36, 5F
→
10/12 03:36, , 6F
10/12 03:36, 6F
→
10/12 03:38, , 7F
10/12 03:38, 7F
→
10/12 09:57, , 8F
10/12 09:57, 8F
→
10/12 09:58, , 9F
10/12 09:58, 9F
→
10/12 09:59, , 10F
10/12 09:59, 10F
→
10/12 10:02, , 11F
10/12 10:02, 11F
→
10/12 10:03, , 12F
10/12 10:03, 12F
→
10/12 10:07, , 13F
10/12 10:07, 13F
→
10/12 10:09, , 14F
10/12 10:09, 14F
→
10/12 10:09, , 15F
10/12 10:09, 15F
→
10/12 10:16, , 16F
10/12 10:16, 16F
→
10/12 10:17, , 17F
10/12 10:17, 17F
→
10/12 18:31, , 18F
10/12 18:31, 18F
Mathematica 近期熱門文章
PTT數位生活區 即時熱門文章