Spawns a new agent, inheriting specified properties from the parent agent(s). The parent agent is stored in the child’s agent.parent
, and the child agent is added to the parent agent’s agent.children
list. Properties not specified in either the inherit
or mutate
arguments will be instantiated according to the agent.__init__()
function (and therefore after the agentInit
hook runs on the child agent).
NOTE. This function accounts for parents and children by creating a directed network titled 'lineage'
.
Parameters
inherit — list[str|tuple], optional
A list of strings or tuples referring to properties that should be copied from the parent agent to the child agent. Any properties not listed in
inherit
will take their initial value at the instantiation of the primitive object. If a string, the child property will be a mean of the property values of the parents, or the property value of the first parent for non-numeric property values.
If a tuple, the first element is a string referring to the property value to inherit. The second value is a string referring to a statistic determining how the properties of the parent agents should be inherited, or a function that takes a list of parents' property values and returns a value. Possible statistic values are:'mean'
– Averages the values of the parents' properties.'gmean'
– Calculates the geometric mean of the parents' properties.'sum'
– Totals the values of the parents' properties.'max'
– Chooses the maximum value of the parents' properties.'min'
– Chooses the minimum value of the parents' properties.'first'
– Passes the value to the child of the agent on whom thereproduce()
function was called.'last'
– Passes the value of the last parent in theparents
argument.'rand'
– Chooses a random parent whose property value to pass to the child.
Default value: []
mutate — dict, optional
Properties to be mutated, either from the inherited value if specified in
inherit
, or the initial value otherwise. The keys of thedict
indicate properties to be mutated. The values can be either:- a number, in which case the value is drawn from a normal distribution with a mean of the old value and a standard devation of the number,
- a tuple, the first item of which is a numeric standard deviation, and the second of which is either
'log'
or'linear'
(this allows the mutated value to be drawn from a log-normal distribution), or - a function that takes a value and returns a value, useful for more complex mutations.
Default value: {}
partners — list[Agent], optional
A list of other agents (not including the self) whose attributes should be used in parentage.
Default value: []
Return Value — Agent
The new agent object.
charwick
Oct 20, 2020 at 23:52By default the breed is inherited directly from the parent whose object
.reproduce()
was called from. However, the breed can be set to randomize between the parents. For example, sexual reproduction between a'male'
and a'female'
can randomize the gender of the offspring this way:charwick
Nov 09, 2020 at 4:55This example passes on the value of the
H
parameter from a single parent to the child, and mutates it by drawing from a lognormal distribution with a standard deviation of 0.5. The child also inherits half the parent’swealth
.