Dynamic State Variable Model builder

Backward induction and individual-based Monte Carlo, after Mangel & Clark (1988) and Clark & Mangel (2000).

Model

Decisions are taken at t = 1 to T−1. At t = T the terminal fitness function is evaluated instead.

State variables

Each state variable is an integer on a closed range, and the model grid is every combination of their values. Tick the lethal box for a quantity whose minimum means death, such as energy reserves; leave it unticked where the minimum is only a floor, such as gut contents.

Actions (behavioural choices)

Order matters: when two actions give exactly equal fitness, the one listed first is chosen. Use the up and down buttons to set that order.

Terminal fitness φ(x)

Examples: 1 for survival to the horizon, x / 10 for fitness proportional to reserves, x > 5 ? 1 : 0 for a threshold. Dead states have fitness 0 whatever this says.

The equation being solved

This is your model, written out with your own names. It updates as you type.

Expression help

How to write parameters and expressions

Every parameter is either a plain number, such as 0.004, or an expression in your state variable names. Expressions are parsed by the tool itself; no code is executed.

What you can refer to

  • Any state variable by the name you gave it. Names are case-sensitive.
  • t, the current period, running from 1 to T−1 for decisions.
  • T, the time horizon.

t and T are reserved, so a state variable cannot be called either of them, nor share a name with one of the functions below.

Arithmetic and comparison

  • + - * / % (remainder), and ^ for powers, which groups from the right.
  • < <= > >= == != give 1 for true and 0 for false, so they can be multiplied straight into a formula.
  • and or not (also written && || !) treat any non-zero value as true.
  • condition ? a : b chooses a when the condition is non-zero, otherwise b. if(condition, a, b) means the same thing.

Functions

min(a, b, ...), max(a, b, ...), abs(a), floor(a), ceil(a), round(a), sqrt(a), exp(a), log(a) (natural), pow(a, b), if(c, a, b).

Rules the solver enforces

  • For each action, the outcome probabilities must sum to 1 at every live state and every decision time. Nothing is renormalised for you; a sum that is not 1 is reported as an error naming the state and the time.
  • Mortality risk and outcome probabilities must fall in [0, 1].
  • A change that comes out non-integer is rounded to the nearest integer, away from zero on a half, and the solve reports a warning saying which expression it was.
  • Changes are clamped to the variable's range, never wrapped or discarded.
  • Dividing by zero, taking log of a non-positive number, or sqrt of a negative number stops the solve with an error. Nothing is substituted silently.
  • Expressions are always evaluated at the current state and time, never at the state the individual moves to.

Worked examples

  • 3 - 1 — a gain of 3 units of food less a metabolic cost of 1.
  • 0.6 - 0.1 * g — a foraging success rate that falls as the gut g fills.
  • (x < 4 ? 0.03 : 0.015) * (1 + 0.5 * t / T) — predation risk higher for lean animals and rising through the season.
  • 1 - (0.6 - 0.1 * g) — the complement, so the two outcome probabilities sum to 1 everywhere.

Solve

Backward induction over every state and period. The solver checks the whole model first and stops at the first problem it finds.

Simulate

Individual-based forward Monte Carlo under the optimal policy from the solve.

Solve the model first; the simulation follows the decision matrix.