2.4 Iterations and accumulators

Create models that change in time, accumulate values, track changes with time-series charts.

In [1]:
var iframer = require('./iframer')

In previous posts we examined two basic types of StatSim blocks. Data and Expressions. They alone are quite powerful elements that make it possible to create sophisticated models. However real-life processes are often time-dependent and it's just impossible to simplify them to the input > expression > output model. If something changes in time, accumulates values and you need to track such changes use accumulators and iterations.

Iterations

Before creating the accumulator block, it's better to set number of iterations first. Think about the smallest time step in your future model and then set Iterations field to the total number of such time steps. It could be number of minutes, days, months or else. By default, the number of iterations a model makes is set to 1. You can find the Iterations input field on bottom of the screen or in the parameter sidebar.

When the iteration value is larger than 1, an extra hidden variable _i is added to the model. Underscore shows that it's a hidden, not user-created value. It's possible to use this variable in time-dependent expression.

Tracking history

In evolving models it's useful to track changes in time, not just get the final value. To track changes of an expression value select Track history checkbox.

Accumulators

Accumulator blocks do just one simple thing, they accumulate a value with each iteration. The main difference between accumulator and expression is that expressions are evaluated with each step and ignore previous values. Accumulators also evaluate their formulas, but add the result to a previous value. They also have initial value fields and min/max fields. Accumulators by default return only the final value for the last iteration, but you can examine all the steps by activating 'Track history' checkbox

Example: 3 years of home renting

Let's create a simplified model of home renting with

By Anton Zemlyansky in