Agent-Based Models (Part 14)

Azimuth 2024-08-01

I’ve been explaining our software for agent-based models based on stochastic C-set rewriting systems. But my only example so far has been the Game of Life, which is not what most people would call stochastic: it’s a deterministic model!

In fact, a deterministic model is just a stochastic model where all the probabilities for events to happen are 0 or 1. So we can call the Game of Life stochastic if we want. But that’s not very satisfying! So let’s tweak the Game of Life to make it more random.

It’s very easy to do! We only need to change one line of code—in fact, just one word in one line of code. We can just change this:

TickRule(name, I_L, I_R; ac) = ABMRule(name, Rule(I_L, I_R; ac), DiscreteHazard(1));

to this:

TickRule(name, I_L, I_R; ac) = ABMRule(name, Rule(I_L, I_R; ac), ContinuousHazard(1));

Recall from Part 9 that in a stochastic C-set rewriting system, all changes to the state of our model arise from ‘rewrite rules’, and attached to every rewrite rule there is a ‘timer’. The timer says the probability the rewrite will happen, as a function of time (if nothing else happens first that prevents it).

DiscreteHazard(1) and ContinuousHazard(1) are examples of such timers. In what follows, let’s arbitrarily measure time in seconds.

DiscreteHazard(1) means that the rewrite happens 1 second after it’s first able to happen, with probability 100% (if nothing else happens first that prevents this rewrite from happening). In the Game of Life, all rewrite rules have this timer attached to them.

ContinuousHazard(1) means that the rewrite happens stochastically, and the probability that it still hasn’t happened after t seconds decays exponentially like this:

exp(-t)

(if nothing else happens first that prevents this rewrite from happening).

If all our rewrite rules contain DiscreteHazard(1), as they do in the Game of Life, everything in our model occurs in equally spaced time steps, each one second after the next. If we take the Game of Life and replace this timer with ContinuousHazard(1), we get a funny variant where cells are born and die at random times.

You can see more details and an example here:

Conway’s Game of Life. Bonus: stochastic Game of Life.

But what does this line of code mean in the first place, one might ask:

TickRule(name, I_L, I_R; ac) = ABMRule(name, Rule(I_L, I_R; ac), DiscreteHazard(1));

Here is what’s going on:

1) We want to give each rewrite rule a name.

2) The rewrite rule itself is a little diagram of C-sets like this:

L \stackrel{I_L}{\hookleftarrow} I \stackrel{I_R}{\to} R

To apply this rewrite rule to a C-set S, we find inside that C-set an instance of the pattern L, called a ‘match’, and replace it with the pattern R. The C-set I can be thought of as the common part of L and I. The maps IL and IR tell us how this common part fits into L and R.

Since the convention in AlgebraicJulia (and elsewhere) is that a morphism knows its source and target, to specify the rewrite rule it’s enough to give the maps IL and IR. That’s what I_L and I_R stand for.

3) In addition, we can also give our rule ‘application conditions’:

positive application conditions say a rule can only be applied if some condition holds, • negative application conditions say a rule can never be applied if some condition holds.

I gave examples taken from the Game of Life Part 11.

4) We must also give our rule a timer.

All four steps are accomplished in an expression of the form

ABMRule(name, Rule(I_L, I_R; ac), DiscreteHazard(1))

where of course the I_L and I_R and ac need to be filled in with specifics.

But we may get sick of typing the timer every time. So, we can define a shorter command TickRule thus:

TickRule(name, I_L, I_R; ac) = ABMRule(name, Rule(I_L, I_R; ac), DiscreteHazard(1));

That’s all!


Part 1: The challenge of developing a unified mathematical framework for agent-based models, and designing software that implements this framework.

Part 2: Our project to develop software for agent-based models at the International Centre for Mathematical Sciences, May 1 – June 12 2024.

Part 3: Coalgebras for describing diverse forms of dynamics.

Part 4: The Para construction and its dual, for dealing with agents that are affected by, or affect, the external environment.

Part 5: A proposal for research on modular agent-based models in public health.

Part 6: Describing the stochastic time evolution of non-interacting agents using state charts.

Part 7: Describing the stochastic interaction of agents using state charts.

Part 8: How to describe the birth and death of agents using state charts.

Part 9: The theory of ‘stochastic C-set rewriting systems’: our framework for describing agents using simple data structures that randomly change state at discrete moments in time.

Part 10: A choice of category C suitable for the Game of Life.

Part 11: Stochastic C-set rewrite rules that describe time evolution in the Game of Life.

Part 12: The formalism of ‘attributed C-sets’, for endowing agents with attributes.

Part 13: Literate code for the Game of Life in our software framework for agent-based models.