Package me.yixqiao.jlearn.genetic
Class Population
- java.lang.Object
-
- me.yixqiao.jlearn.genetic.Population
-
public abstract class Population extends java.lang.ObjectPopulation of individuals.
-
-
Field Summary
Fields Modifier and Type Field Description intgenerationWhich generation the population is on.protected intindivCountNumber of individuals.protected Individual[]individualsArray of individuals.protected intlayerCountNumber of layers.protected java.util.ArrayList<Layer>layersArrayList 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 PopulationaddLayer(Layer layer)Add a layer to the general layer template.protected abstract voidcalcScores()Calculate the scores for each network.MatrixforwardPropagate(int indivNum, Matrix x)Forward propagate for a single individual.voidinit()Initialize the population.protected voidinitLayers()Initialize all layers.voidoneGeneration()Simulate one generation.protected voidprintBest(int n)Print scores of the best networks.protected voidresetScores()Reset scores.protected abstract voidselect()Select and randomize networks for the next generation.voidsimGenerations(int generations)Simulate generations.
-
-
-
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.
-
-
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
initmethod 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 individualx- 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 withinoneGeneration.
-
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
-
-