org.apache.ignite.ml.util.genetic

## Class Population

- java.lang.Object
- - org.apache.ignite.ml.util.genetic.Population

-     public class Population
      extends Object

  Represents a populations of chromosomes.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Population(int size)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `calculateFitnessForAll(Function<Chromosome,Double> fitnessFunction)` Calculates fitness for all chromosomes with custom fitness function.
    `double` | `calculateFitnessForChromosome(int idx, Function<Chromosome,Double> fitnessFunction)` Calculates fitness for chromosome found by index with custom fitness function.
    `double` | `getAverageFitness()` Returns the average fitness of population or Double.NaN if not all fitness values are calculated for all chromosomes.
    `Chromosome` | `getChromosome(int idx)` Returns an individual chromosome.
    `Chromosome` | `getChromosome(Integer idx)` Returns the chromosome by given index.
    `double` | `getTotalFitness()` Returns the total fitness value of population or Double.NaN if not all fitness values are calculated for all chromosomes.
    `Chromosome[]` | `selectBestKChromosome(int k)` Selects the top K chromosomes by fitness value from the smallest to the largest.
    `void` | `setChromosome(int idx, Chromosome chromosome)` Sets the chromsome for given index.
    `void` | `setFitness(Integer idx, Double fitness)` Sets the fitness value for chromosome with the given index.
    `int` | `size()` Returns the size of population.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Population

          public Population(int size)

      Parameters:
        `size` - Size.

  - ### Method Detail

    - #### getChromosome

          public Chromosome getChromosome(int idx)

      Returns an individual chromosome.
      Parameters:
        `idx` - Index of chromosome.

    - #### calculateFitnessForChromosome

          public double calculateFitnessForChromosome(int idx,
                                                      Function<Chromosome,Double> fitnessFunction)

      Calculates fitness for chromosome found by index with custom fitness function.
      Parameters:
        `idx` - Index.
        `fitnessFunction` - Fitness function.

    - #### calculateFitnessForAll

          public void calculateFitnessForAll(Function<Chromosome,Double> fitnessFunction)

      Calculates fitness for all chromosomes with custom fitness function.
      Parameters:
        `fitnessFunction` - Fitness function.

    - #### setChromosome

          public void setChromosome(int idx,
                                    Chromosome chromosome)

      Sets the chromsome for given index.
      Parameters:
        `idx` - Index.
        `chromosome` - Chromosome.

    - #### getChromosome

          public Chromosome getChromosome(Integer idx)

      Returns the chromosome by given index.
      Parameters:
        `idx` - Index.

    - #### selectBestKChromosome

          public Chromosome[] selectBestKChromosome(int k)

      Selects the top K chromosomes by fitness value from the smallest to the largest.
      Parameters:
        `k` - The amount of top chromosome with highest value of the fitness. Returns null if not all fitness values are calculated for all chromosomes.

    - #### getTotalFitness

          public double getTotalFitness()

      Returns the total fitness value of population or Double.NaN if not all fitness values are calculated for all chromosomes.

    - #### getAverageFitness

          public double getAverageFitness()

      Returns the average fitness of population or Double.NaN if not all fitness values are calculated for all chromosomes.

    - #### size

          public int size()

      Returns the size of population.

    - #### setFitness

          public void setFitness(Integer idx,
                                 Double fitness)

      Sets the fitness value for chromosome with the given index.
      Parameters:
        `idx` - Index.
        `fitness` - Fitness.

2021 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.10.0
Release Date | : March 10 2021