# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Simulate the self-organizing system of the Persian Immortals as described by Herodotus

Contributed by:
Sander Huisman

ResourceFunction["PersianImmortals"][] simulates 10 | |

ResourceFunction["PersianImmortals"][ simulates 10 | |

ResourceFunction["PersianImmortals"][{ simulates 10 | |

ResourceFunction["PersianImmortals"][…, starts with an agent population | |

ResourceFunction["PersianImmortals"][…, runs the simulation according to the time specification | |

ResourceFunction["PersianImmortals"][…, uses the binning specification |

The Persian Immortals were an elite army described by the Greek historian and geographer Herodotus while attacking Greece in 480-479 BCE under Xerxes's command. Their name refers to the fact that the size of the army was always kept constant at 10000 by immediately replacing every fallen warrior with a warrior from reserve troops. Because of this tactic, morale was kept high, and the army was actually getting stronger over time.

n | Integer, remove the n weakest agents. |

dist | Use the distribution dist to determine how many of the weakest agents are removed. |

m | Integer, remove m agents randomly |

dist | Use the distribution dist to determine how many random agents are removed |

{dist} | Each agent gets a random threshold between 0 and its fitness.
This threshold is then compared to a random attack given by dist.
Fitter agents have a higher chance of survival. |

n | Integer, n agents of fitnesses linearly chosen between 0 and 1. |

Automatic | Use 10^{4} agents of fitnesses linearly chosen between 0 and 1. |

{f_{1}, f_{2},…} | Use agents with fitness f_{i} (should be between 0 and 1). |

n | Integer, simulate n steps and save data from all timesteps. |

{t_{min},t_{max},Δt} | Simulates for t_{max} steps but saves every Δt steps, starting from t_{min}. |

{{t_{1}, t_{2},…}} | Simulates until Max[t_{i}] and saves each t_{i}. |

PersianImmortals takes the following options:

"Repetitions" | Automatic | number of times to simulate |

"NewFitness" | Automatic | fitness for new agents |

"Strengthening" | Automatic | specifies how the surviving agents strengthen over time |

Possible settings for the option "Repetitions" include:

Automatic | perform a single simulation |

n | perform n simulations and average the results |

Possible settings for the option "NewFitness" include:

Automatic | generate agents with random fitnesses uniformly taken between 0 and 1 (UniformDistribution[0,1]) |

dist | generate agents with random fitnesses taken from the distribution dist |

Possible settings for the option "Strengthening" include:

Automatic | agents do not become stronger (equivalent to 0) |

val≤1 | after each time step val is added to the fitness and clipped to[0,1] |

val>1 | after each time step the fitness is multiplied by val and clipped to[0,1] |

Scaled[val] | after each time step the fitness gets a fraction val closer to 1 |

ResourceFunction["PersianImmortals"] returns an Association with the following keys: "Population", "Repetitions", "BinDelimiters", "BinCenters", "BinCounts", "PDFs" and "CDFs".

Perform a simulation where, in each time-step, the weakest agent is replaced by a new random agent:

In[1]:= |

Out[2]= |

Visualize the probability density function (PDF) for the fitness of the agents at various times:

In[3]:= |

Out[3]= |

At each step remove a random number between 1 and 10 of the weakest agents:

In[4]:= |

Out[5]= |

At each step remove between 1 and 5 of the weakest agents and between 1 and 3 random agents:

In[6]:= |

Out[7]= |

Do not remove the weakest agents, but rather randomly remove agents based on a probabilistic distribution. Each agents creates a random threshold in the Range[0,fitness] and this is compared against a random number given by a distribution:

In[8]:= |

Out[9]= |

Use an army of 100 agents:

In[10]:= |

Out[11]= |

Use more bins to get more detailed probability density functions:

In[12]:= |

Out[13]= |

Use a different fitness distribution for new agents:

In[14]:= |

Out[15]= |

Use this distribution:

In[16]:= |

Out[17]= |

Create agents with a normal distribution that is truncated such that the fitness is always between 0 and 1:

In[18]:= |

Out[19]= |

Simulate with this fitness distribution for new agents:

In[20]:= |

Out[21]= |

A single run of the simulation gives jagged results for the probability density function:

In[22]:= |

Out[23]= |

Repeat the simulation and average:

In[24]:= |

Out[25]= |

In case of survival of an agent, add 0.0001 to their fitness:

In[26]:= |

Out[27]= |

In case of survival of an agent, multiply their fitness by 1.0003:

In[28]:= |

Out[29]= |

In case of survival of an agent, improve their fitness by bring it 0.05% closer to 1:

In[30]:= |

Out[31]= |

Find the mean strength of the agents:

In[32]:= |

Out[36]= |

Randomly remove agents based on a small chance:

In[37]:= |

Out[39]= |

Use a different fitness distribution for new agents:

In[40]:= |

Out[42]= |

- 1.1.0 – 22 February 2023
- 1.0.0 – 13 February 2023

This work is licensed under a Creative Commons Attribution 4.0 International License