metapypulation package

Submodules

metapypulation.individual module

A module containing the individual class.

class metapypulation.individual.Individual(id: int, original_deme_id: int, number_of_features: int, number_of_traits: int, mutation_rate: float = 0.0, features: List = None)

Bases: object

Base class for an individual in the metapopulation.

id

The identifier for the individual (unique within the subpopulation).

Type:

int

original_deme_id

Identifier of the deme where the individual originated.

Type:

int

number_of_features

Number of cultural features of the individual.

Type:

int

number_of_traits

Number of traits per feature of the individual.

Type:

int

mutation_rate

Probability of a random mutation to occur during cultural transmission.

Type:

float

features

List of features of the individual.

Type:

List[int]

number_of_changes

The number of times this individual has changed set of features following an interaction.

Type:

int

axelrod_interaction(interacting_individual: Individual) None

Interaction following the Axelrod model of culture dissemination. A random individual (source) is selected. The probability of interacting is given by the number of traits in common between the focal individual (self) and the source divided by the total number of features. If they interact, the focal individual copies one of the features of the source for which they are not equal.

Parameters:

interacting_individual (Individual) – Individual with which the self individual interacts. Currently accepts only “axelrod_interaction”.

interact(interacting_individual: Individual, interaction_function: str) None

Wrapper for interactions, it allows to pass any interaction that is coded for.

Parameters:
  • interaction_function (str) – The type of interaction that decides the outcome of the interaction. Current options are “neutral_interaction” and “axelrod_interaction”.

  • interacting_individual (Individual) – Individual with which the self individual interacts.

neutral_interaction(interacting_individual: Individual) None

Interaction following a neutral model, where replication of a trait is purely based on frequency in the population. The focal indivdual changes one trait at random copying from the source individual.

metapypulation.metapopulation module

metapypulation.subpopulation module

A module containing the subpopulation class.

class metapypulation.subpopulation.IndividualsIterator(individuals)

Bases: object

An iterator object ot iterate over the SetOfSubpopulations class.

class metapypulation.subpopulation.SetOfIndividuals(deme: Subpopulation)

Bases: MutableSet

A class inheriting from MutableSet to act as container of Individual objects. Methods are standard for a MutableSet.

add(individual: Individual)

Adds an Individual to the SetOfIndividuals.

Parameters:

individual (Individual) – Individual to add to the set.

discard(individual: Individual)

Eliminates an individual from the set (and from the population).

Parameters:

individual (Individual) – Individual to be discarded.

empty_set() None

Empty the Set.

sample_and_remove(number_of_individuals: int) List[Individual]

Sample an individual, remove it from the Set and return it in a list.

Parameters:

number_of_individuals (int) – Number of individuals to sample randomly.

Returns:

List of all the individuals that have been sampled from the population.

Return type:

List[Individual]

shuffle() None

Shuffle the Set.

class metapypulation.subpopulation.Subpopulation(id: int, type_of_interaction: str)

Bases: object

The base class for a subpopulation in the metapopulation.

id

Unique id of the subpopulation.

Type:

int

population

Set containing all the individuals in the subpopulation

Type:

SetOfIndividuals

outgoing_migrants

Set containing individuals that are being prepared for emigration. Empty outside of the migration step.

Type:

SetOfIndividuals

incoming_migrants

Set containind individuals that were received through immigration. Empty outside of the migration step.

Type:

SetOfIndividuals

type_of_interaction

The type of interaction to implement between individuals for cultural changes. Currently accepts only “axelrod_interaction”.

Type:

str

add_individual(individual: Individual) None

Adds an individual to the subpopulation. This function does not remove the individual from somewhere else (in case of passages from list to list).

Parameters:

individual (Individual) – individual to be added to the subpopulation.

count_deme_origin_id(total_number_of_subpopulations: int) List[int]

Count how many individuals originally from each deme are found in this deme. It is generally invoked from Metapopulation to get a summary.

Parameters:

total_number_of_subpopulations – number of subpopulations in the whole metapopulation.

Returns:

list containing a count of individuals for each subpopulation present.

Return type:

List[int]

count_traits_sets() int

This function counts the total of unique sets of traits in the subpopulation. For example, [0, 1, 2, 3, 4] is a set different from [1, 1, 2, 3, 4], which is different from [5, 4, 3, 2, 1], etc.

Returns:

The current number of different sets of traits in the subpopulation.

Return type:

int

create_interaction() None

Samples two individuals at random in the subpopulation and makes them interact.

get_current_number_of_migrants() int

Returns the current number of incoming immigrants during. Only returns a non-zero number during the migration step.

Returns:

Current number of immigrants.

Return type:

int

get_population_size() int

Returns the current subpopulation size.

Returns:

Current subpopulation size.

Return type:

int

get_traits_sets() ndarray

This function returns all the feature sets found in a subpopulation in an array.

Returns:

All the current sets of features in the subpopulation.

Return type:

np.ndarray

gini_diversity() float

Calculate the Gini-Simpson diversity index of the subpopulation. This is equal to 1 - Simpson_index

Returns:

The Gini-Simpson diversity index of the subpopulation.

Return type:

float

incorporate_migrants_in_population() None

Merges incoming migrants into the local population.

is_trait_in_subpopulation(trait: int, feature: int = None) bool

This function checks whether a given trait at a given feature is in the population.

Parameters:
  • trait (int) – the int referring to the trait that needs to be checked against

  • feature (Optional, int) – the feature that needs to be checked (index from 0 to N_features-1). If None, it checks for the trait in any feature. Default is None.

Returns:

True if the trait is found in the subpopulation.

Return type:

bool

list_migrants(migration_rate: float) None

Create a list of migrants that will be sent out of the subpopulation.

Parameters:

migration_rate (float) – The migration rate is defined as the expected percentage of population that will migrate at each generation.

Returns:

A list of individuals from the subpopulation.

Return type:

List[Individual]

receive_migrants(giving_subpopulation: Subpopulation, migration_rate: float) None

Populate the list of incoming migrants with individuals coming from a giving_subpopulation.

Parameters:
  • giving_subpopulation (Subpopulation) – Subpopulation from which individuals are migrating.

  • migration_rate (float) – Percentage of the giving subpopulation that will migrate at each generation into the current subpopulation.

Returns:

A list of individuals from the giving subpopulation.

Return type:

List[Individual]

shannon_diversity() float

Calculate the Shannon diversity index in the subpopulation.

Returns:

The current Shannon diversity index in the subpopulation.

Return type:

float

simpson_diversity() float

Calculate the Simpson diversity index of the subpopulation.

Returns:

The Simpson diversity index of the subpopulation.

Return type:

float

metapypulation.simulation module

Module contents