egttools.analytical.sed_analytical.calculate_state

calculate_state()

Converts a discrete population configuration into a unique index.

This is typically used to map a population state (i.e., counts of each strategy) to a 1D index, which is useful for vectorized representations and algorithms like replicator dynamics or finite Markov chains.

Parameters:
  • group_size (int) – The total number of individuals (e.g., population size or group size).

  • group_composition (List[int]) – A list representing the number of individuals using each strategy.

Returns:

A unique index corresponding to the group composition.

Return type:

int

Examples

>>> calculate_state(3, [1, 1, 1])
3
>>> calculate_state(2, [2, 0, 0])
0

Converts a discrete population configuration (NumPy vector) into a unique index.

This version takes an integer vector from NumPy and maps it to a 1D index, useful for discrete state space indexing.

Parameters:
  • group_size (int) – The total number of individuals in the population.

  • group_composition (NDArray[np.int64]) – NumPy array of shape (n,) where n is the number of strategies.

Returns:

A unique index corresponding to the input configuration.

Return type:

int

Examples

>>> calculate_state(3, np.array([1, 1, 1]))
3
>>> calculate_state(4, np.array([2, 2, 0]))
6