Looping over a model
When you want to evaluate your model over many input scenarios, Analytica's array abstraction mechanism is very convenient. You simple add indexes to your inputs and array abstraction does the rest automatically, propagating those indexes to all downstream results. However, at some point you may find yourself limited by the amount of usable memory, since all those intermediate results, for all scenarios, are cached and consuming memory.
To get around this, you may consider looping over your model (or a subset of your model), and collecting the results for all scenarios only for a selected output variable. By doing so, the intermediate steps in your model consume only the memory required for a single scenario. This technique can sometimes enable a large scale analysis that would otherwise not be possible.
This technique of looping over your model is only possible when your model does not operate over the index you are looping over. If any variable in your model operates over the index, such as the way Sum(...,I) operates over index I, or SDeviation(X)' operates over the Run index, then looping is not a viable option.
The basic technique is demonstrated by the following example. Suppose your model has an input X, indexed only by I, and an output Y, and that the intermediate steps to no operate over the index I. Then we can compute Y by looping as follows:
Variable Y_by_looping := For xi[ ] := X do WhatIf(Y,X,xi)
The same technique can be used for large-scale Monte Carlo sampling. Suppose we have a single uncertain scalar input, U, and a result Z. We can compute the result for Z one-sample at a time using:
Variable Z_by_looping := For ui[ ] := U do WhatIf(Z,U,ui)
With this technique you need to be careful to ensure that your model does not use any statistical functions, since these operate over the Run index. You must also be careful not to switch evaluation mode. In other words, Sample(Z) must not depend on Mid(U), and Mid(Z) must not depend on Sample(Z).
Enable comment auto-refresher