Package me.yixqiao.jlearn.genetic
Class Population
- java.lang.Object
-
- me.yixqiao.jlearn.genetic.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.
-
-
-
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
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 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
-
-