After the outline of theoretic considerations concerning the behavior of single agents its time for implementation. In this post I will develop a pseudo-code to model the centralized version of the single mating behavior.
===START: 1. time step===
In the first time step the agent post their ‘wishes’ to the board. To do so they first have to build their intention and draw a location. Both actions involve a random component which we will simulate using just a simple uniform-RNG. But lets first look at the code on a higher level:
int = d.calculate_intention(AGE, PID, SEXOR)
if int == 1:
loc = d.calculate_location(AGE, SEXOR, PID)
f.post AGE, loc, SEXOR, INFEC
A note on notation: Upper-case variables indicate memory variables of the agent, the prefix ‘d.’ indicates that this function will be defined later and ‘f.’ marks the function a FLAME-specific.
So the agent builds its intention (conditional on its age, if it is in a partnership or not [indicated by the fact that it finds a valid partner ID] and sexual orientation) if the intention is zero the agent will not engage in any partner seeking activities. When ‘int ==1’ is true the agent draws a location and posts all relevant information to the message board.
How does the agent calculate its intention? It basically calculates the probability of having sex (conditional on its age, …) and takes the square-root as we assume that the agents are symmetric. This probability is then used as the parameter for a bernoulli RV.
DEFINE caluclate_intention(AGE, PID, SEXOR) => OUTPUT: int = {0,1}
pid = 0, int = 0
if PID != 0
pid = 1
p = b0 + b1 * AGE + b2 * pid + b3 * SEXOR
if rand(1) <= p
int = 1
Now that the agent is able to calculate its intention we turn to the location function. Let’s assume that there are three locations. Further we define the chance for unfaithful behavior of agents within a partnership to be 3 %. Lastly we define two age groups each with the following probabilities to be within a location: loc = 1 0.5/0.2, loc= 2 0.25/0.1, loc = 3 0.25/0.7. The random numbers are again derived by a (simple) inversion method (see for example Bucklew 2004, p. 8ff)
DEFINE calculate_location(AGE, PID, SEXOR)
if PID != 0
x = rand(1)
if x <= 0.97
loc = PID * ID
if 0.97 < x <= 0.98
loc = 1
if 0.98 < x <= 0.99
loc =2
else
loc=3
else
if AGE < AGE1
x = rand(1)
if x <= 0.5
loc = 1
if 0.5 < x <= 0.75
loc =2
else
loc=3
else
…
=== 2. time step ==
Now its time for the
