- Use the profiler to find out where time is spent, so you can focus your speed-up efforts on those portions of the code.
- It sounds like 11 of your variables are fixed across all iterations. Maybe you can compute pieces of your very complex equation that use those variables just once in advance, saving yourself recomputation of those same values at each iteration.
- "randomised ...using norminv and a random p" It's probably faster to just generate a random number directly rather than generating p and then looking up the corresponding normal.
- "randomised at each iteration..." Its probably faster to generate & store vectors of 1-10k random values before starting the iteration process, and then using the stored random value for each iteration. That cuts down on function calling overhead because you only call the random function(s) once rather than 1-10k times.
Optimising Monte Carlo simulation
9 ビュー (過去 30 日間)
古いコメントを表示
I am trying to run a Monte Carlo simulation on a very complex equation (19 input variables) at about 1-10k iterations. Some of the inputs remain constant throughout the computation, while others (8 variables) are randomised at each iteration using the norminv function and a random probability. As you might imagine, this simulation becomes very expensive as the amount of iterations are increased.
Presently, I am using the parfor function on a 4-core laptop with each run needing around 5min per 1000 iterations. The 8 variable inputs are recalculated at each iteration and then passed to a function that calculates the final answer (although I previously had this in the body of the loop and it didn't make much difference).
My question is, how can I optimise this computation? I would need to run several of these simulations for my project and would like to trim down the time.
0 件のコメント
回答 (1 件)
Jeff Miller
2020 年 12 月 7 日
Some suggestions--hopefully not a waste of your time:
4 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!