Agent-Based Models (Part 8)

Last time I presented a class of agent-based models where agents hop around a graph in a stochastic way. Each vertex of the graph is some ‘state’ agents can be in, and each edge is called a ‘transition’. In these models, the probability per time of an agent making a transition and leaving some state can depend on when it arrived at that state. It can also depend on which agents are in other states that are ‘linked’ to that edge—and when those agents arrived.

I’ve been trying to generalize this framework to handle processes where agents are born or die—or perhaps more generally, processes where some number of agents turn into some other number of agents. There’s already a framework that does something sort of like this. It’s called ‘stochastic Petri nets’, and we explained this framework here:

• John Baez and Jacob Biamonte, Quantum Techniques for Stochastic Mechanics, World Scientific Press, Singapore, 2018. (See also blog articles here.)

However, in their simplest form, stochastic Petri nets are designed for agents whose only distinguishing information is which state they’re in. They don’t have ‘names’—that is, individual identities. Thus, even calling them ‘agents’ is a bit of a stretch: usually they’re called ‘tokens’, since they’re drawn as black dots.

We could try to enhance the Petri net framework to give tokens names and other identifying features. There are various imaginable ways to do this, such as ‘colored Petri nets’. But so far this approach seems rather ill-adapted for processes where agents have identities—perhaps because I’m not thinking about the problem the right way.

So, at some point I decided to try something less ambitious. It turns out that in applications to epidemiology, general processes where n agents come in and m go out are not often required. So I’ve been trying to minimally enhance the framework from last time to include processes ‘birth’ and ‘death’ processes as well as transitions from state to state.

As I thought about this, some questions kept plaguing me:

When an agent gets created, or ‘born’, which one actually gets born? In other words, what is its name? Its precise name may not matter, but if we want to keep track of it after it’s born, we need to give it a name. And this name had better be ‘fresh’: not already the name of some other agent.

There’s also the question of what happens when an agent gets destroyed, or ‘dies’. This feels less difficult: there just stops being an agent with the given name. But probably we want to prevent a new agent from having the same name as that dead agent.

Both these questions seem fairly simple, but so far they’re making it hard for me to invent a truly elegant framework. At first I tried to separately describe transitions between states, births, and deaths. But this seemed to triplicate the amount of work I needed to do.

Then I tried models that have

• a finite set S of states,

• a finite set T of transitions,

• maps u, d \colon T \to S + \{\textrm{undefined}\} mapping each transition to its upstream and downstream states.

Here S + \{\textrm{undefined}\} is the disjoint union of S and a singleton whose one element is called undefined. Maps from T to S + \{\textrm{undefined}\} are a standard way to talk about partially defined maps from T to S. We get four cases:

1) If the downstream of a transition is defined (i.e. in S) but its upstream is undefined we call this transition a birth transition.

2) If the upstream of a transition is defined but its downstream is undefined we call this transition a death transition.

3) If the upstream and downstream of a transition are both defined we call this transition a transformation. In practice most of transitions will be of this sort.

4) We never need transitions whose upstream and downstream are undefined: these would describe agents that pop into existence and instantly disappear.

This is sort of nice, except for the fourth case. Unfortunately when I go ahead and try to actually describe a model based on this paradigm, I seem still to wind up needing to handle births, deaths and transformations quite differently.

For example, last time my models had a fixed set A of agents. To handle births and deaths, I wanted to make this set time-dependent. But I need to separately say how this works for transformations, birth transitions and death transitions. For transformations we don’t change A. For birth transitions we add a new element to A. And for death transitions we remove an element from A, and maybe record its name on a ledger or drive a stake through its heart to make sure it can never be born again!

So far this is tolerable, but things get worse. Our model also needs ‘links’ from states to transitions, to say how agents present in those states affect the timing of those transition. These are used in the ‘jump function’, a stochastic function that answers this question:

If at time t agent a arrives at the state upstream to some transition e, and the agents at states linked to the transition e form some set S_e, when will agent a make the transition e given that it doesn’t do anything else first?

This works fine for transformations, meaning transitions e that have both an upstream and downstream state. It works just a tiny bit differently for death transitions. But birth transitions are quite different: since newly born agents don’t have a previous upstream state u(e), they don’t have a time at which they arrived at that state.

Perhaps this is just how modeling works: perhaps the search for a staggeringly beautiful framework is a distraction. But another approach just occurred to me. Today I just want to briefly state it. I don’t want to write a full blog article on it yet, since I’ve already spent a lot of time writing two articles that I deleted when I became disgusted with them—and I might become disgusted with this approach too!

Briefly, this approach is exactly the approach I described last time. There are fundamentally no births and no deaths: all transitions have an upstream and a downstream state. There is a fixed set A of agents that does not change with time. We handle births and deaths using a dirty trick.

Namely, births are transitions out of a ‘unborn’ state. Agents hang around in this state until they are born.

Similarly, deaths are transitions to a ‘dead’ state.

There can be multiple ‘unborn’ states and ‘dead’ states. Having multiple unborn states makes it easy to have agents with different characteristics enter the model. Having multiple dead states makes it easy for us to keep tallies of different causes of death. We should make the unborn states distinct from the dead states to prevent ‘reincarnation’—that is, the birth of a new agent that happens to equal an agent that previously died.

I’m hoping that when we proceed this way, we can shoehorn birth and death processes into the framework described last time, without really needing to modify it at all! All we’re doing is exploiting it in a new way.

Here’s one possible problem: if we start with a finite number of agents in the ‘unborn’ states, the population of agents can’t grow indefinitely! But this doesn’t seem very dire. For most agent-based models we don’t feel a need to let the number of agents grow arbitrarily large. Or we can relax the requirement that the set of agents is finite, and put an infinite number of agents u_1, u_2, u_3, \dots in an unborn state. This can be done without using an infinite amount of memory: it’s a ‘potential infinity’ rather than an ‘actual infinity’.

There could be other problems. So I’ll post this now before I think of them.

17 Responses to Agent-Based Models (Part 8)

  1. Glen Alleman says:

    Thanks for the post.
    We are in the process of integrating the physical and virtual aspects of Digital Twins with Program Planning and Controls for the US Navy. Any thoughts of Model Based Systems Engineering and the modeling principles and practices you’ve been speaking to?
    Also is there a place on your site for all the agent based parts from 1 to now?

    Glen B. Alleman, MSSM, USC
    Integrated Program Performance Management

    [signature_2997834526]

    +1-303-241-9633
    glen.alleman@niwotridge.com

    • John Baez says:

      I’m afraid I don’t really know anything about “model based systems engineering”. You might talk to Eswaran Subrahmanian at the National Institute of Standards and Technology: he’s working with people at the Topos Institute to apply category theory to engineering, and he’s spent decades thinking about how to improve the practice of engineering.

      Here is a way to see all the articles in this thread.

    • MBSE in the context of the discussion here is Matlab’s Simulink for dataflow computation, all the digital CAD tools that feature VHDL and Verilog, IBM Rational Rhapsody that features SysML for SW/HW design. These all have capability for Petri Net logic and control flow.

      Before the term Digital Twin came into vogue, the terms were Virtual Reality and before that Flight Simulator. Send me a note as I can give my experiences with regard to DoD: Navy, Army, Air Force, DARPA in that realm

  2. bhaugen says:

    We’re working on software for real-life economic agents and have been influenced by Category Theory. Here’s an overview of our model:https://www.valueflo.ws/introduction/core/

  3. Grandpa D says:

    John,

    Thanks !  Interesting !

    In re the “agent-based” models I’ve seen in anthro,  the scope has been
    more limited:  looking at a population of people who have to make some  
    sequence of decisions  regarding  some activity –[i.e., to do it, to
    stop doing it, to do it differently] where the people come with
    attributes, and the context of activities has attribute constraints of
    some sort, and present decisions affect future attributes and
    constraints–and some sets of activities wind up producing some sort of
    tangible benefit.  Then the simulation has been to look at the behavior
    of people in the hypothetical simulated population over some time span
    and see their outcomes; The distribution of behavior of the simulated
    population is compared with the distribution of behavior observed in
    some slice of the real people.  Since this is anthropology, both
    cultural values and internal feedback (as in Durkheim’s “collective
    representations) is ideally built in.

    Decisions re actions are made via  a random number draw–in which, based
    on the problem–some range => “yes, do it” and some range +> “no, don’t.

    Eventually, the behavior of the by then calibrated simulation
    population/attributes is compared with the behavior of the “real”
    targeted population (via a different subset from that on which the
    calibration was done)–how well does the progress of the simulation
    population match that of the “real” population ?  And the distribution
    of outcomes  for a repeated set of runs of the same simulation can be
    looked at.

    I’ve been involved in some few such efforts.

    This is a rough overview of stuff I (and others) did back in the day,
    and dependent on my limited memory and varyingly thin records !

                Cheers,

                        david

  4. Giampiero Campa says:

    Once when I was a research faculty I had a similar problem with neurons of a network that needed to pop in or out of existence all of a sudden.

    What I did was allow up to a maximum of Nmax neurons (potentially very high). Then and every time a neuron was born, it was simply activated, i.e. its weight were allow to change and it was allowed to have a nonzero output. But each possible neuron had a number basically. And the reverse happened for neurons dying.

    But I acknowledge that if you actually use this for implementation for large Nmax it is very inefficient, because in some way you work with all the neurons all of the time. Whether is it ok theoretically as a framework I am not sure.

    • John Baez says:

      Hi! It’s nice to hear some other modelers have faced this curious issue of how to model unborn agents. I’m starting to feel that as a theoretical framework it’s good to think of them as waiting their turn to be born in an infinite queue. I’ll let the more practical members of my team figure out the best way to implement this. I don’t think there’s any need to actually spend resources holding them in memory, except perhaps in states like Arkansas where the unborn are now considered ‘children’.

      • Giampiero Campa says:

        Yes you should totally propose your model to the Arkansas birth registry! :)

        Anyway, along those lines, i was thinking that your model basically already allows for reincarnation, which should be fun!

  5. William Waites says:

    For time, why not: when an agent arrives in a state, it gets stamped with a time. The length of time it has been in that state is just the difference between now and that stamp. For birth processes and transitions this works the same way. For death processes, there is nothing to stamp. Or do I misunderstand?

    Nothing prevents having latent individuals ready to be born or ex-individuals who have died so we can count them, some models might want to do that, but it does not seem to me that it is required.

    • John Baez says:

      For time, why not: when an agent arrives in a state, it gets stamped with a time. The length of time it has been in that state is just the difference between now and that stamp. For birth processes and transitions this works the same way. For death processes, there is nothing to stamp. Or do I misunderstand?

      No, you’re not misunderstanding. This is basically exactly what I’m doing. Last time I said

      So now we’ll want to keep track of the residence time of each agent—that is, how long it’s been in its current state. But William Waites pointed out a clever way to do this: it’s cheaper to keep track of the agent’s arrival time, i.e. when it entered its current state. This way you don’t need to keep updating the residence time. Whenever you need to know the residence time, you can just subtract the arrival time from the current clock time.

      The framework this time is exactly the same as it was last time. All I’m doing is realizing, rather belatedly, that this framework is general enough to easily handle birth and death process.

      One tiny point: even when agents transition to a ‘dead’ state, they get an arrival time! It works like any other transition. So you can imagine a bunch of people in heaven happily playing harps with their death dates stamped on their foreheads.

      • William Waites says:

        Thanks, I get it. Except for:

        One tiny point: even when agents transition to a ‘dead’ state, they get an arrival time! It works like any other transition. So you can imagine a bunch of people in heaven happily playing harps with their death dates stamped on their foreheads.

        Sure you could have that but is it necessary? Is there something subtle that I am not seeing that requires it?

        If a model has one or more ‘dead’ states they are just states like any other and nothing says they can’t absorb agents (or maybe maybe agents can be resurrected or turned into zombies), but why does this need to be baked in?

        Consider about a model with people agents and mosquito agents. Maybe we want to keep track of the people the way you say but not the mosquitos perhaps for computational reasons, e.g. there are many more mosquitos than people.

        This seems more like a modelling choice than a model framework choice. No?

      • John Baez says:

        Sure you could have that but is it necessary? Is there something subtle that I am not seeing that requires it?

        In using category theory it turns out to be extremely advantageous to do everything as uniformly as possible, not pulling special tricks here and there just because you can get away with it. We like to make sure strange special cases follow *exactly* the same rules as all other cases. Then defining functors from our categories to other categories, and performing other constructions, doesn’t require constantly mentioning these special cases. Everything stays clean and the power tools function smoothly.

        So I’m very happy that we can treat births and deaths *exactly* like any other transition. This means keeping keep track of the arrival time of each agent into a dead state, just like any other state. The benefit is that the whole framework so far fits into a short blog article, and it will be easy to do a lot of things with it.

        Consider about a model with people agents and mosquito agents. Maybe we want to keep track of the people the way you say but not the mosquitos perhaps for computational reasons, e.g. there are many more mosquitos than people.

        Now you’re talking about a hybrid of an agent-based model and (say) a stock-flow model, which goes beyond the framework I described last time. But one reason I like the framework I described last time is that it’s mathematically closely akin to a stock-flow model: they both use the same C-set. I’m hoping this will make it easier to hybridize the two kinds of model.

        (By the way, stock-flow models often treat birth and death processes differently from all others. I fought against this when some of us were creating StockFlow.jl, but not very hard. Now I’ll fight harder, because there too it works quite smoothly to treat them exactly the same as all other processes.)

        • bhaugen says:

          “(By the way, stock-flow models often treat birth and death processes differently from all others. I fought against this when some of us were creating StockFlow.jl, but not very hard. Now I’ll fight harder, because there too it works quite smoothly to treat them exactly the same as all other processes.)”

          I’ll be very interested in the details of combined agent and stockflow models. Is any of that combo worked out a bit around here?

        • John Baez says:

          The business of combining agent-based models and stock-flow models is not worked out yet: that’s part of what I’m working out right here in this series of blog articles—and also with William Waites and 4 others for 6 weeks starting May 1st.

  6. Bruce Smith says:

    As I started reading your post, I planned to post a comment suggesting essentially the same approach as the one you came to. I think it has no problems and is not in any sense a “dirty trick”. It’s just the most straightforward way of describing what you want.

    If you want the model’s operations to be more deterministic, you can also require that the agents in each unborn state have an order, and the next one in that order is the next one born from that state. These unborn states are just like entry halls where players can be ready to enter an arena. They wait in line until it’s their turn to enter.

    • John Baez says:

      Thanks! When I suggested an infinite set of unborn agents u_1, u_2, u_3, \dots, I had in mind that they’d get born in order. But I didn’t think about how to ensure that. It’s certainly easy enough to impose by fiat. But now I realize that my rules for transitions, described last time using a [jump function](https://johncarlosbaez.wordpress.com/2024/02/28/agent-based-models-part-7/), are so ridiculously general that this is just a special case. This makes me happy, because if we go down this road I really want to treat birth as a transition like any other.

      • Matias Schrauf says:

        Thanks for the post!

        While reading it, I had this question about these ‘unborn’ states: if you have the same ‘jump function’ for each of the agents in such a state, how do you prevent to have infinite agents transitioning at the same time?

        But now I saw that in the definition for ‘jump function’ you gave in the previous post, you make it depend on S_e , and you have identifiable agents (so you can have them ordered, among other things). Thus you can make the jump function for any ‘unborn’ agent to be zero until the previous agent leaves the ‘unborn’ state. And then you have them neatly in queue, waiting to be born.

        Otherwise, if you have jump events that are assigned to states instead of agents (and when triggered just pick an agent in that state), then you can have a uniform rate of births. I’m not saying you should go this way, I only mention it to raise a possibility.

        Incidentally, S_e is a product of disjoint subsets of 2^A , as the assignment of agents to states in a given time should form a partition.

You can use Markdown or HTML in your comments. You can also use LaTeX, like this: $latex E = m c^2 $. The word 'latex' comes right after the first dollar sign, with a space after it.

This site uses Akismet to reduce spam. Learn how your comment data is processed.