Genetic Algorithms And Evolutionary Learning .*;

Simple Function Example 3

This one is similar to Example 2, but includes a type of stagnation avoidance and more code improvements.  Again, it's a simple genetic algorithm that generates combinations of five numbers and four operators with results that aim toward a target number.

These are the constraints of this example:

  1. The population remains the same size from one generation to the next; the chromosomes that aren't selected for reproduction are overwritten by the offspring of those that are selected.  Only enough offspring are created to make the population a specified size, so even though several chromosomes are selected for reproduction, not all get to reproduce.
  2. Selection is accomplished using a general random method.
  3. The usual operator precedence rules of algebra are not used, the expressions are simply evaluated from left to right.
  4. Instead of stopping the tests upon total NaN, I've decided to borrow a concept from simulated annealing: shaking up the population with an epidemic of several mutations.

 

The way I've implemented this genetic algorithm, it will sometimes weed out all but the one chromosome closest to the target, which leaves nothing but a whole population of the exact same chromosome.  And when there's no diversity, the BreakNaN() function shakes up the population much in the same way simulated annealing does to shake itself free of local minima.

I've also decided to use Double (floating point) instead of Integer variable types in order to squeeze a little more definition out of as many chromosomes as possible.  For instance, let's say the target number is 100.  Sometimes one chromosome's total would come out to 98.333333333 and another's would be 98.99999999, but the conversion to integer would render both to 98.  There is the remote possibility that different fitness scores for these two might make a difference when it comes time for selection.  This of course could also open the possibility of a chromosome's total of 99.999999 being considered an acceptable solution for the algorithm.

Note that as a floating point value, I can be a little more lenient with the algorithm's solutions.

I've arbitrarily chosen the range between 99.999 and 100.001 as acceptable solutions.

 

Example Results

I'm not sure I like this one so much. The comparison of floating point values versus integer doesn't seem to be helping. If anything, it's hurting it. More often than not, the algorithm will run through thousands of epochs and accomplish nothing. The following is one of the few that succeeded.

 

010011100110101010001101100110110111 = 30	93.3179723502304%
011111010011111000101101011111000111 = -6	89.1705069124424%
010011010001111001111101000011110100 = 5.25	90.4665898617511%
011110110100110001011101100011000011 = -5	89.2857142857143%
010111100110101101001110001011010100 = 64	97.2350230414746%
001111110001101000001011100011101000 = 88	100%
010011010110111100011011100111000111 = 0	89.8617511520737%
010110111000111100111111000010110100 = 8.33333333333333	90.8218125960062%
100010111000110100011101010110100111 = 17	91.8202764976959%
000111101000110010001011100111000011 = 6	90.5529953917051%
011010110110110000111101100010110110 = 7	90.668202764977%
010011010000111101011101000111010110 = -6.2	89.147465437788%
011111010010110001001100010011110000 = -3	89.5161290322581%
001011100000111100111100010010110111 = 3	90.2073732718894%
000011110101101100111101001011000101 = -4	89.4009216589862%
010110110100111110011100011011100100 = -20	87.5576036866359%
011111001000101101101011010011000110 = 3	90.2073732718894%
001111100100110101111110100010110101 = 45	95.0460829493088%
011011101000110000101110100011000101 = 363	71.0829493087558%
100110111000110101001100010011010010 = 7	90.668202764977%
001111000111110000111101010011000011 = -14	88.2488479262673%
011111001001111101011100011111010011 = -10.4	88.6635944700461%
011011100101110100101011011111110010 = 17.5	91.8778801843318%
011110110110101101011110010111000011 = 87	99.8847926267281%
011011010001111010011010000010110101 = 50	95.6221198156682%
010110100000101101101100100010110111 = 10	91.0138248847926%
100010110100101110001110011111100111 = 980	0%
010111000101101101101100011011100111 = 0	89.8617511520737%
011010110110101110011110011010101000 = 134	97.4654377880184%
011011110001111001111101001111100010 = 78	98.8479262672811%
010111100100111001001101000111100111 = 553	49.1935483870968%
011010101001110001111011010011000101 = 7	90.668202764977%
011011110011110001011110011010110100 = -14	88.2488479262673%
100010110101110000111111000110100000 = 10	91.0138248847926%
000111100111111001001101011011110001 = 22	92.3963133640553%
000111110100111001011011100011110011 = 3.08333333333333	90.2169738863287%
100010100010110010001011100011010001 = 9	90.8986175115207%
010111010001111000011110100011001000 = 24	92.6267281105991%
000111110011101101101011011011000011 = 9.33333333333333	90.937019969278%
011011110010110101001101000011110101 = -0.2	89.8387096774194%
010110110101110101111101001011000100 = -3	89.5161290322581%
001111001000101000101110000011110011 = 0	89.8617511520737%
001111000010111000001111010110110011 = 3	90.2073732718894%
011010110011110101011011010011111001 = 0.888888888888889	89.9641577060932%
010011011000110001111100100010110110 = -13	88.3640552995392%
001011000011110100111110010011010111 = -23	87.2119815668203%
011011110010110101101110100011000010 = -26	86.8663594470046%
011111100100110110011011100011010100 = 23	92.5115207373272%
010011000101101100111100011111000011 = -8	88.9400921658986%
011011000100110001111100100111110101 = -2.8	89.5391705069124%

-- abbreviated results --

010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011000001111001111101010111000110 = 10	57.345971563981%
010011000001111001111110010110110110 = 111	94.7867298578199%
010010110001111001111110010111000110 = 169	67.2985781990521%
010011000001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010010110001111001111110010111000110 = 169	67.2985781990521%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011000001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000000 = 105	97.6303317535545%
010011000001111001111110010111000110 = 99	99.5260663507109%
010011000001111001111110010111000110 = 99	99.5260663507109%
010011010101111001111110010111000110 = -41	33.175355450237%
010011000001111001111110010111000110 = 99	99.5260663507109%
010011000001111001111110010111010110 = 99	99.5260663507109%
010011010001111001111101010111000100 = 12	58.2938388625592%
010011000001111001111110000111000110 = 15	59.7156398104265%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
001111010001111001111110010111000110 = 64	82.9383886255924%
010011010001111001111110001011000110 = 36	69.6682464454976%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111100010111000110 = 10	57.345971563981%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011000001111001111110010111000101 = 100	100%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011000001111001111101010111000110 = 10	57.345971563981%
010011000001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011010001110001111110010111000110 = -26	40.2843601895735%
010011000001111001111110010111010110 = 99	99.5260663507109%
010011000001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%
010011000111111001111110010111000110 = -111	0%
001111000001111001111110010111000110 = 64	82.9383886255924%
010011000001111001111110010111000110 = 99	99.5260663507109%
010011010001111001111110010111000110 = 99	99.5260663507109%

Done.
010011000001111001111110010111000101
4 - 1 * 7 * 5 - 5 = 100
Completed 246 epochs.
Encountered 305 mutations in 1377 offspring.
NaN avoidance routine called 17 times.

 

public void footer() {
About | Contact | Privacy Policy | Terms of Service | Site Map
Copyright© 2009-2012 John McCullock. All Rights Reserved.
}