Save results

Normally when you restart a model or change an input, Analytica must recompute any result you ask to view. When a result takes a long time to compute, it is sometimes useful to save the result in the model, so that

  • you can see the result when you restart the model without having to wait to recompute it,
  • you can compare a new result against the original version after you change inputs

It's also sometimes helpful to save data imported from a CSV file or a spreadsheet into a model so that you don't have to reimport it whenever you start the model. And when you share the model with someone else, you don't need to remember to send them the data files too.

Here's how to save a result, say Variable X, in the model:

  1. Create a place to store the result, say Variable Saved_X.
  2. Create a button with title "Save X" and set its OnClick Attribute to:
Saved_X := X

Whenever you want to, just click button "Save X". It will compute X if needed and save a copy into Variable Saved_X.

Influence diagram from Analytica model to Save and compare results

You can download this example model to explore: media:Save and compare results.ana

If you want to save the [[Evaluation mode|prob value] (rather than the mid value), set the OnClick Attribute of Save prob X" to:

Saved_Prob_X := Sample(X)

Note that Saved_X will contain only the Mid value and Saved_prob_X contains only the Prob value in this second example. There's no simple way to give it both Mid and Prob values.

If you change an index used by a saved result, it may affect that result. For example, suppose Samplesize = 1000 when you click "Save prob X", and then increase Samplesize = 2000. This changes the length of the Run Index from 1000 to 2000, and the second 1000 elements of Saved_prob_X will be Null, untill you click button "Save prob X" again.

If you want to save an array result and make sure it doesn't get affected by future changes to its indexes, you can save the indexes at the same time that you save the array. Suppose X is a probabilistic array indexed by I and Run, you can set the OnClick Attribute of "Save prob X" to save copies of indexes I and Run as Saved_I and Saved_run, and then save X reindexed by the Saved_I and Saved_run, thus:

Saved_I := CopyIndex(I)

Saved_Run := CopyIndex(Run)

Saved_Prob_X := Sample(x)[Run = Saved_Run, I = Saved_I]

If you want to compare the current value x withsaved values, in this case, Saved X and Saved_prob_X, you can create variable Compare current and saved X. Note that you need to reindex the saved variables back to their original indexes,

Compare_current_and_saved_X := [X, Saved_X, Saved_prob_X[Saved_Run=Run, Saved_I=Index_I]]

You are not allowed to post comments.