# Monte Carlo Simulation Update

**URL:** <https://forum.mimiframework.org/t/monte-carlo-simulation-update/23>\
**Category:** Uncategorized\
**Created:** [March 1, 2019, 8:03pm UTC](https://forum.mimiframework.org/t/monte-carlo-simulation-update/23 "2019-03-01T20:03:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [March 1, 2019, 8:03pm UTC](https://forum.mimiframework.org/t/monte-carlo-simulation-update/23/1 "2019-03-01T20:03:55Z")

</div>

@jrising @ckingdon95 @hbenveniste you three are our current `MCS` functionality users so I wanted to quickly flag something for you. We are quickly moving towards getting stability in function names etc. for this, but since it’s a new and evolving functionality there are bound to be a few little changes going forward. The most recent, which is reflected in the docs, is that you now **must** use `set_models!(mcs, model)`, and `run_mcs` no longer can add models to the `mcs` run within its signature. This was for clarity and simplicity. Hence, you will do the following if `m` is your `Model` and `mcs` is your `MCS` instance.

```auto
# Set the model
set_models!(mcs, m)
# Run trials 1:4, and save results to the indicated directory, one CSV file per RV
run_mcs(mcs,1:4, output_dir=output_dir)

```

The next release will also feature the new `@defsim` macro, which generalizes `@defmcs` to include other methods, first of which is Sobol Analysis. We will plan to maintain the backwards compatibility of `@defmcs` for now though.

---

<div class="post-metadata">

**Author:** ![jrising](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/jrising/32/7_2.png) [@jrising](https://forum.mimiframework.org/u/jrising)\
**Post date:** [March 2, 2019, 11:35pm UTC](https://forum.mimiframework.org/t/monte-carlo-simulation-update/23/2 "2019-03-02T23:35:48Z")

</div>

Thanks for the heads-up. This seems fine.

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [March 9, 2019, 1:31am UTC](https://forum.mimiframework.org/t/monte-carlo-simulation-update/23/3 "2019-03-09T01:31:42Z")

</div>

@ckingdon95 @hbenveniste @jrising Hi all, apologies for the continuous updates on this, we are moving towards stability! We are adding to the mcs functionality, and generalizing it to sensitivity analysis (sa) functionality, encompassing Monte Carlo and others. The goal is to make the package even more useful for you!

BUT the next Mimi release will break your mcs code a bit. All documentation will be updated too, but your changes should be minimal:

1. `@defmcs` to `@defsim`
2. `@run_mcs` to `@run_sim`

These are simple, since we consider random sampling with mcs to be our default. See the docs and examples and don’t hesitate to ask if you have any questions at all!

---

<div class="post-metadata">

**Author:** ![jrising](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/jrising/32/7_2.png) [@jrising](https://forum.mimiframework.org/u/jrising)\
**Post date:** [May 3, 2019, 1:45pm UTC](https://forum.mimiframework.org/t/monte-carlo-simulation-update/23/4 "2019-05-03T13:45:15Z")

</div>

I noticed that in MimiPAGE2009, you wrapped all the `@defsim` code in a function. What’s the purpose of that? It seems like this would allow us to create the MC structure multiple times, but since it’s all descriptive, why would we want to do that?

Thanks.

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [May 3, 2019, 7:18pm UTC](https://forum.mimiframework.org/t/monte-carlo-simulation-update/23/5 "2019-05-03T19:18:03Z")

</div>

Hi James. I think this was a design decision by Cora so that she can import and use the function as part of the PAGE2009 API instead of calling `include` on a file with the `def_sim` in it, not so that she can create the structure multiple times, is that right @ckingdon95?

---

<div class="post-metadata">

**Author:** ![ckingdon95](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/ckingdon95/32/15_2.png) [@ckingdon95](https://forum.mimiframework.org/u/ckingdon95)\
**Post date:** [May 3, 2019, 7:23pm UTC](https://forum.mimiframework.org/t/monte-carlo-simulation-update/23/6 "2019-05-03T19:23:23Z")

</div>

I actually don’t use this directly, so this can be changed if desired. But the intention was in line with what Lisa said-- if someone wants to use this, it might be better to be able to call a function that returns a copy of the Simulation object to work with, rather than having there be only one Simulation object defined in the module. This is similar to how we have a `getpage()` function that returns a new/clean version of the model, rather than only defining one copy of the model.

---

<div class="post-metadata">

**Author:** ![ckingdon95](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/ckingdon95/32/15_2.png) [@ckingdon95](https://forum.mimiframework.org/u/ckingdon95)\
**Post date:** [May 3, 2019, 7:26pm UTC](https://forum.mimiframework.org/t/monte-carlo-simulation-update/23/7 "2019-05-03T19:26:51Z")

</div>

Maybe another important clarification: the Simulation object isn’t just purely descriptive. When we use the object (by calling `set_models!` and `generate_trials!` and `run_sim`), the object is modified, which is why it might be useful to have the function that returns a new/unused copy of it

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [May 3, 2019, 7:32pm UTC](https://forum.mimiframework.org/t/monte-carlo-simulation-update/23/8 "2019-05-03T19:32:48Z")

</div>

That’s a good point, the object does get modified. I am continuing to work on performing sensitivity analysis with the Sobol method, which includes an `analyze` function and has revealed some pros and cons of our current design … I’ll keep everyone updated but if I make changes will be trying not to break any existing functionality!
