-
Notifications
You must be signed in to change notification settings - Fork 282
Breeding
Breeding aso known as 'crossover' is the way in which a genetical algorithm decides how the previous generation will form a new generation. There are a lot of different ways of choosing which traits should come from one parent and which traits from the other.
At the moment, there are 4 built-in crossover methods:
// more to come
Methods.Crossover.SINGLE_POINT; // takes all the values from one parent till a certain point, afterwards the other parent
Methods.Crossover.TWO_POINT; // same as single point, but switches twice
Methods.Crossover.UNIFORM; // the offspring inherits a random 50% of each parents biases and weights
Methods.Crossover.AVERAGE; // the offspring inherits the average value of each weight and bias of its parents
These methods can be executed on sets of Neurons
, Layers
and Networks
. Keep in mind that some methods don't work on certain neural objects. The main function looks like this:
var offspring = objectType.crossOver(parent1, parent2, METHOD);
// where METHOD is optional, default method is Cossover.UNIFORM
Crossover.SINGLE_POINT
and Crossover.TWO_POINT
are configurable. The default value of SINGLE_POINT
is [0.4]
, which means that the first 40% of biases and weights come from parent1, the next 60% from parent2. The default value of TWO_POINT
is [0.4, 0.9]
, which means that the first 40% comes from parent1, the next 50% from parent2, and the last 10% from parent1 again.
Please note, when you crossover layers or neurons, this will not crossover the weights of the connections! In the future, it will be possible to crossover internal connections (self-connections). If you crossover a layer or a neuron, you can use this to construct new connections. You cannot insert these layers or neurons into existing networks, as they won't be connected! Also, if you crossover a network or a layer, they should be the same size!
Accepted crossover methods: Methods.Crossover.SINGLE_POINT
, Methods.Crossover.TWO_POINT
, Methods.Crossover.UNIFORM
and Methods.Crossover.AVERAGE
.
var network1 = new Architect.Perceptron(2,4,2);
var network2 = new Architect.Perceptron(2,4,2);
var offspring = Network.crossOver(network1, network2, Methods.Crossover.UNIFORM);
Accepted crossover methods: Methods.Crossover.SINGLE_POINT
, Methods.Crossover.TWO_POINT
, Methods.Crossover.UNIFORM
and Methods.Crossover.AVERAGE
.
var layer1 = new Layer(4);
var layer2 = new Layer(4);
var offspring = Layer.crossOver(layer1, layer2, Methods.Crossover.SINGLE_POINT);
Accepted crossover methods: Methods.Crossover.UNIFORM
and Methods.Crossover.AVERAGE
.
var neuron1 = new Neuron();
var neuron2 = new Neuron();
var offspring = Neuron.crossOver(neuron1, neuron2, Methods.Crossover.AVERAGE);