Class Population


  • public abstract class Population
    extends java.lang.Object
    Population of individuals.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int generation
      Which generation the population is on.
      protected int indivCount
      Number of individuals.
      protected Individual[] individuals
      Array of individuals.
      protected int layerCount
      Number of layers.
      protected java.util.ArrayList<Layer> layers
      ArrayList of layers as a template for individuals.
    • Constructor Summary

      Constructors 
      Constructor Description
      Population​(int indivCount)
      Create a new population.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      Population addLayer​(Layer layer)
      Add a layer to the general layer template.
      protected abstract void calcScores()
      Calculate the scores for each network.
      Matrix forwardPropagate​(int indivNum, Matrix x)
      Forward propagate for a single individual.
      void init()
      Initialize the population.
      protected void initLayers()
      Initialize all layers.
      void oneGeneration()
      Simulate one generation.
      protected void printBest​(int n)
      Print scores of the best networks.
      protected void resetScores()
      Reset scores.
      protected abstract void select()
      Select and randomize networks for the next generation.
      void simGenerations​(int generations)
      Simulate generations.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • indivCount

        protected final int indivCount
        Number of individuals.
      • layers

        protected final java.util.ArrayList<Layer> layers
        ArrayList of layers as a template for individuals.
      • generation

        public int generation
        Which generation the population is on.
      • individuals

        protected Individual[] individuals
        Array of individuals.
      • layerCount

        protected int layerCount
        Number of layers.
    • Constructor Detail

      • Population

        public Population​(int indivCount)
        Create a new population.
        Parameters:
        indivCount - number of individuals
    • Method Detail

      • addLayer

        public Population addLayer​(Layer layer)
        Add a layer to the general layer template.
        Parameters:
        layer - the layer
        Returns:
        the population itself to allow for daisy chaining
      • initLayers

        protected void initLayers()
        Initialize all layers.

        This function should not be called directly; the init method does this already.

      • init

        public void init()
        Initialize the population.

        This must be run after adding all layers and before simulating.

      • forwardPropagate

        public Matrix forwardPropagate​(int indivNum,
                                       Matrix x)
        Forward propagate for a single individual.
        Parameters:
        indivNum - the individual
        x - the input matrix
        Returns:
        the output
      • simGenerations

        public void simGenerations​(int generations)
        Simulate generations.
        Parameters:
        generations - number of generations
      • oneGeneration

        public void oneGeneration()
        Simulate one generation.
      • resetScores

        protected void resetScores()
        Reset scores. This is called within oneGeneration.
      • calcScores

        protected abstract void calcScores()
        Calculate the scores for each network.
      • select

        protected abstract void select()
        Select and randomize networks for the next generation.
      • printBest

        protected void printBest​(int n)
        Print scores of the best networks.
        Parameters:
        n - number of networks to print