This code implements the simulation of cultural evolution for the paper “Inferring individual-level processes in cultural evolution from population-level patterns".
The code is all written for Python 2.7. The only external dependency is Numpy. For faster execution, the simulation is also fully compatible with PyPy.
-
doSim.py: The main simulation loop
-
transmission.py: Function to implement the different modes of transmission
-
getDiscrete.py: Given a starting value of a discrete trait, returns a transmitted value (possibly perturbed by mutation)
-
getContinuous.py: Returns a possibly mutated continuous trait
-
histogram.py: Implementation of histogram function (c.f. numpy.histogram). Included for PyPy compatibility.
To run the simulation, call the function doSim in doSim.py. doSim takes a single argument which is a tuple with all of the simulation parameters. This tuple should have entries
-
pWithin: probability of transmission
-
startingPop: the size of the population
-
pMutate: probability of mutation in each transmission event
-
numSims: Number of simulation runs to execute.
-
pOblique: Probability that mixed transmission chooses the oblique mode (as opposed to horizontal).
-
mutationStd: Standard deviation of noise added in mutation of continuous traits.
-
discreteTraitBins: Number of variants for discrete traits.
-
suffix: a string which is appended to the name of the output file.
-
conformity: boolean value of whether transmission includes conformity.
-
conformityB: parameter of conformity strength.
Example call: doSim((0.5, 100, 0.05, 5, 0.2, 0.1, 5, ’test’, False, 0.2))
doSim returns a string which is the name of the file that the results were written to. This file is a Python pickle file, which contains a dictionary with two fields: “params" contains another dictionary with the parameter values used for the run, and “results" contains the results from the simulation. Results are collected at each timestep in the array “coarseSteps"
Results is a dictionary which is keyed by one of the following statistics:
-
frequencies: number of individuals with each variant
-
mean: mean of the entire population (for continuous traits)
-
var: variance of the entire population (for continuous traits)
-
turnoverDiscrete: mean turnoever rate of the most frequent trait
The entry for each of these statistics is a dictionary which is keyed by the mode of transmission. Each mode maps to an array with dimension (numSims, len(coarseSteps)), with entry i**j corresponding to the value of the statistic in simulation i at time point j.