agent_selection
This function selects a n agents from all population (uniform selection).
agent_selection(n_population, n, i_pop=False)
Input variables
Name | Description | Type |
n_population | Number of population | Integer |
n | Number of agents to select | Integer |
i_pop | Default is False (Selects n agents among all population). i_pop=Integer Selects n agents among all population, excluding i_pop agent | Integer or Boolean | </table> Output variables {: .label .label-yellow } Name | Description | Type |
selected | Selected agents. | List |
report | Report about the selection process. | String |
Example 1 {: .label .label-blue } Select three agents from population $n_{pop} = 5$, except agent $i=2$. ```python # Import # pip install metapy-toolbox or pip install --upgrade metapy-toolbox from metapy_toolbox import agent_selection # or import * # Data nPop = 5 n = 3 excludedAgent = 2 # Call function selected, report = agent_selection(nPop, n, excludedAgent) print(f'selected ids from population: {selected} \n') print(report) ``` ```bash selected ids from population: [1 0 3] Selection population operator probs = [0.25, 0.25, 0.0, 0.25, 0.25] the selected agents = [1 0 3] ``` Example 2 {: .label .label-blue } Select three agents from population $n_{pop} = 5$. ```python # Import # pip install metapy-toolbox or pip install --upgrade metapy-toolbox from metapy_toolbox import agent_selection # or import * # Data nPop = 5 n = 3 # Call function selected, report = agent_selection(nPop, n) print(f'selected ids from population: {selected} \n') print(report) ``` ```bash selected ids from population: [3 4 1] Selection population operator probs = [0.2, 0.2, 0.2, 0.2, 0.2] the selected agents = [3 4 1] ```