GenPro   Genetic Programming made simple Rob van der Veer Bluevoid
Bio Java Development (Web, OSGi, Android, Swing) Project Leader (o.a. Scrum) [email_address]
Genpro preamble
Automated help: “Grrr”
Settings vs re-programmable logic
AI to the rescue! Genetic Programming Genetic Algorithm Neural networks Fuzzy logic Self learning machines Emergent behavi...
Representations outside GP <ul><li>if-then production rules </li></ul><ul><li>Horn clauses </li></ul><ul><li>decision tree...
Genetic algorithm / programming  <ul><li>Generate random solutions  </li></ul><ul><li>Evaluate & score  (cumulative error ...
Program representations in GP <ul><li>bits </li></ul><ul><li>numerical weight vectors </li></ul><ul><li>machine / byte cod...
Genpro birth
One year later: Spreadsheet Inspiration <ul><li>Every cell has a value and a type  </li></ul>3 = A2 + B1 2 1 41 <ul><li>Ev...
One (call)cell, one method call <ul><li>A GenPro cell holds: </li></ul><ul><li>Type </li></ul><ul><li>Value </li></ul><ul>...
One (call)cell, one method call Integer cc1 = Math.max(a, b)   <ul><li>cc1 </li></ul><ul><li>Integer  </li></ul><ul><li>Va...
A grid of cells i1 37 17.4 Input  values 1: 113 2: 212 3: 392 4: 752 Expected Output values 1: 45 2: 100 3: 200 4: 400 O1 ...
Working with GenPro
Using GenPro: extending Trainer <ul><li>public   abstract   class  Trainer { </li></ul><ul><li>public   abstract  Setup cr...
Setup <ul><li>Defines: how to create programs and run generations of programs </li></ul><ul><li>Parts of Setup: </li></ul>...
GridSolutionEvaluator extends TestSetSolutionEvaluator <ul><li>Defines how to evaluate and select programs. </li></ul><ul>...
TestSet <ul><li>Defines the inputs and outputs values to evaluate a program. </li></ul><ul><li>Is actually a list of celln...
First testcase: exact formula  <ul><li>Convert Fahrenheit to Celsius </li></ul><ul><li>input: Fahrenheit </li></ul><ul><li...
GenPro inner working
Creating a random solution Lib1 Math input1 Integer output1 Integer Integer c1 = Math.abs(input1); Integer c2 = Math.round...
The heart of the machine:  Method.invoke() <ul><li>public void calc() {  </li></ul><ul><li>  // fetch parameter values </l...
Why reflection? <ul><li>Strong typed connecting </li></ul><ul><li>No compile time  ( = faster @ small testsets ) </li></ul...
Operators / libraries <ul><li>public class NumberOperations { </li></ul><ul><li>public   static   double  multiply( double...
Back to reality ;)
Egg Boiling!
Second testcase: non-exact formula <ul><li>Eggweight </li></ul><ul><li>input: width & height of egg </li></ul><ul><li>outp...
Search Space size <ul><li>Nr of cells </li></ul><ul><li>Nr of operators/methods </li></ul><ul><li>Nr of parameters </li></...
Third Test case: search space <ul><li>Exact formula (score=0) </li></ul><ul><li>F(y)=x4+x3+x2-x </li></ul>
Forth Test case: Roman Figures <ul><li>Exact formula (score=0) </li></ul><ul><li>Strings to Integers </li></ul><ul><li>Doe...
Genpro current state
Program representations <ul><li>Tree  based GP (TGP) </li></ul><ul><li>Linear  based GP (LGP) </li></ul><ul><li>Graph  bas...
Runtime Requirements <ul><li>GenPro Core: Java 1.5 or Android 1.0 </li></ul><ul><li>GenPro Examples: Java 1.5 (Swing) </li...
Features <ul><li>Supported cell types: Integer, Double, Boolean, String </li></ul><ul><li>Operators:  </li></ul><ul><ul><l...
Wanted Features <ul><li>Cell type mutation (keep the if-cells!) </li></ul><ul><li>Runtime compiling of programs </li></ul>...
GenPro challenges you! <ul><li>Real world application of GenPro </li></ul><ul><li>2 days of free help getting your problem...
Links <ul><li>GenPro code:  code.google.com/p/genpro </li></ul><ul><li>GenPro on twitter: @bluevoid </li></ul><ul><li>Grou...
Genpro, the origin of species  (not covered on feb 2!)
Example Solution structure cc2 Integer cc3 Integer Lib1 Math Input1 Integer abs(int) round(double) compareTo(Integer) Outp...
Crossing of solutions cross over point Int Int Math Int Int Int Solution A Int Int Math Int Int Int Solution B
Creating children of A & B Int Int Int Int Parent A Int Int Int Int Parent B Child A~B Child B~A cross over point Int Int ...
Crossover Reconnecting A2 B1 B2 A1 Int Int Math Int Int Int Child A~B Int Int Math Int Int Int Child B~A
Example Solution structure 2 in code: setup.setCallCells(3, &quot;cc&quot;,  Double .class,  Integer.class ,  Boolean .cla...
Crossover on mixed value types A2 B1 Int Int Math Int Int Dbl Child B~A compareTo(Integer) Mismatch in  param type! Potent...
Crossover in nature:  the origin of species Heart Lung “ DNA” of Horse Heart Lung Brain “ DNA” of Dog cross over points do...
Solving the species problem <ul><li>prevent mismatch by pre-typing the solution template - specie-fy </li></ul><ul><li>use...
Crossover on mixed value types: random reconnect A2 B1 Int Int Math Int Int Dbl Child B~A compareTo(Integer) Moved  connec...
Here be dragons
Upcoming SlideShare
Loading in...5
×

Devnology Workshop Genpro 2 feb 2011

813

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
813
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • User feedback: “ Grrr ”
  • all methods have a way of representing logic
  • input output operationcells constants pairs of testcases
  • build list of class/object-method combination build list of parameter values
  • Devnology Workshop Genpro 2 feb 2011

    1. 1. GenPro Genetic Programming made simple Rob van der Veer Bluevoid
    2. 2. Bio Java Development (Web, OSGi, Android, Swing) Project Leader (o.a. Scrum) [email_address]
    3. 3. Genpro preamble
    4. 4. Automated help: “Grrr”
    5. 5. Settings vs re-programmable logic
    6. 6. AI to the rescue! Genetic Programming Genetic Algorithm Neural networks Fuzzy logic Self learning machines Emergent behavior Reinforcement learning Automated logic Simulated annealing Bayesian networks “ computer programs are the best representation of computer programs” - John R. Koza -
    7. 7. Representations outside GP <ul><li>if-then production rules </li></ul><ul><li>Horn clauses </li></ul><ul><li>decision trees </li></ul><ul><li>Bayesian networks </li></ul><ul><li>propositional logic </li></ul><ul><li>formal grammars </li></ul><ul><li>binary decision diagrams </li></ul><ul><li>frames </li></ul><ul><li>conceptual clusters </li></ul><ul><li>concept sets </li></ul><ul><li>numerical weight vectors (for neural nets) </li></ul><ul><li>vectors of numerical coefficients for polynomials or other fixed expressions (for adaptive systems) </li></ul><ul><li>genetic classifier system rules </li></ul><ul><li>fixed tables of values (as in reinforcement learning) </li></ul><ul><li>linear chromosome strings (as in the conventional genetic algorithm) </li></ul>
    8. 8. Genetic algorithm / programming <ul><li>Generate random solutions </li></ul><ul><li>Evaluate & score (cumulative error => lower is better) </li></ul><ul><li>Cross and mutate to generate offspring </li></ul><ul><li>Repeat step 2 and 3 till score is sufficient </li></ul>generation x generation x+1 generate evaluate evaluate 41 32 92 71 80 35 23 78 15 42 99 12 37 29 76 57 45 34 21 12 45 8 98 46 cross and mutate cross and mutate
    9. 9. Program representations in GP <ul><li>bits </li></ul><ul><li>numerical weight vectors </li></ul><ul><li>machine / byte code </li></ul><ul><li>constructs </li></ul><ul><li>concepts? </li></ul>Which granularity is better?
    10. 10. Genpro birth
    11. 11. One year later: Spreadsheet Inspiration <ul><li>Every cell has a value and a type </li></ul>3 = A2 + B1 2 1 41 <ul><li>Every cell might have a formula </li></ul><ul><li>Changing the references (mutation!) changes the outcome </li></ul>
    12. 12. One (call)cell, one method call <ul><li>A GenPro cell holds: </li></ul><ul><li>Type </li></ul><ul><li>Value </li></ul><ul><li>Target-object (or class) </li></ul><ul><li>Target method </li></ul><ul><li>Parameters </li></ul>Integer cc1 = Math.max(a, b)
    13. 13. One (call)cell, one method call Integer cc1 = Math.max(a, b) <ul><li>cc1 </li></ul><ul><li>Integer </li></ul><ul><li>Value: 56 </li></ul>Math max (a, b) int 56 int 32 param a param b
    14. 14. A grid of cells i1 37 17.4 Input values 1: 113 2: 212 3: 392 4: 752 Expected Output values 1: 45 2: 100 3: 200 4: 400 O1 x +
    15. 15. Working with GenPro
    16. 16. Using GenPro: extending Trainer <ul><li>public abstract class Trainer { </li></ul><ul><li>public abstract Setup createSetup(); </li></ul><ul><li>public abstract TestSetSolutionEvaluator createEvaluator(); </li></ul><ul><li>} </li></ul><ul><li>TrainerVisual extends Trainer </li></ul><ul><li>-> autostart of Swing UI </li></ul>
    17. 17. Setup <ul><li>Defines: how to create programs and run generations of programs </li></ul><ul><li>Parts of Setup: </li></ul><ul><li>Input and output cells </li></ul><ul><li>Type and maximum nr of cells </li></ul><ul><li>Elements (constants, libraries) </li></ul><ul><li>Generation size </li></ul><ul><li>When to stop </li></ul><ul><li>When to store solutions </li></ul>
    18. 18. GridSolutionEvaluator extends TestSetSolutionEvaluator <ul><li>Defines how to evaluate and select programs. </li></ul><ul><li>public TestSet createTestSet(); </li></ul><ul><li>public double scoreOutput(ReferenceCell outputCell, Object calculated, Object expected); </li></ul><ul><li>public double scoreGrid(Grid g); </li></ul><ul><li>public double scoreGridException(Throwable t); </li></ul>
    19. 19. TestSet <ul><li>Defines the inputs and outputs values to evaluate a program. </li></ul><ul><li>Is actually a list of cellnames with sets of values. </li></ul><ul><li>public TestSet(Setup setup, String... cellNames) </li></ul><ul><li>public void addCellValues( final Object... objects) </li></ul>
    20. 20. First testcase: exact formula <ul><li>Convert Fahrenheit to Celsius </li></ul><ul><li>input: Fahrenheit </li></ul><ul><li>output: Celsius </li></ul><ul><li>generates exact formula (score goes to 0) </li></ul>
    21. 21. GenPro inner working
    22. 22. Creating a random solution Lib1 Math input1 Integer output1 Integer Integer c1 = Math.abs(input1); Integer c2 = Math.round(c1); Integer c3 = c2.compareTo(c1); return c2; } import java.lang.Math; public Integer calc(Integer input1) { Math.cos(…) Math.abs(…) … input1 Call targets Param values Math.cos(…) Math.abs(…) c1.compareTo … input1 c1 input1 c1 c2 input1 c1 c2 c3 c3 Integer compareTo(Integer) abs(int) c1 Integer c2 Integer round(double) junk DNA, aka intron ineffective DNA
    23. 23. The heart of the machine: Method.invoke() <ul><li>public void calc() { </li></ul><ul><li> // fetch parameter values </li></ul><ul><li> Object[] paramObjects = new Object[ paramCells.length ]; </li></ul><ul><ul><li>for (int i = 0; i < paramCells.length; i++) { </li></ul></ul><ul><ul><li>paramObjects[i] = paramCells[i].getValue(); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>// execute method on target object/class </li></ul></ul><ul><ul><li>Object val = t argetMethod.invoke(targetCell.getValue(), paramObjects); </li></ul></ul><ul><ul><li>// store value </li></ul></ul><ul><ul><li>setValue(val); </li></ul></ul><ul><li>} </li></ul>
    24. 24. Why reflection? <ul><li>Strong typed connecting </li></ul><ul><li>No compile time ( = faster @ small testsets ) </li></ul><ul><li>Easy extension, just add POJO’s </li></ul><ul><li>Use existing libraries </li></ul><ul><li>Reduces learning curve for user </li></ul><ul><li>Convertible to working Java code </li></ul>
    25. 25. Operators / libraries <ul><li>public class NumberOperations { </li></ul><ul><li>public static double multiply( double a, double b) { </li></ul><ul><li>return a * b; </li></ul><ul><li>} </li></ul><ul><li>public static double divide( double a, double b) { </li></ul><ul><li>return a / b; </li></ul><ul><li>} </li></ul><ul><li>… </li></ul><ul><li>} </li></ul>Lib
    26. 26. Back to reality ;)
    27. 27. Egg Boiling!
    28. 28. Second testcase: non-exact formula <ul><li>Eggweight </li></ul><ul><li>input: width & height of egg </li></ul><ul><li>output: weight of egg </li></ul><ul><li>added lib: formula for volume of Egg </li></ul><ul><li>public class Egg { </li></ul><ul><li>public static double volume( double l, double b) { </li></ul><ul><li>return (0.6057 - 0.0018 * b) * l * b * b; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
    29. 29. Search Space size <ul><li>Nr of cells </li></ul><ul><li>Nr of operators/methods </li></ul><ul><li>Nr of parameters </li></ul><ul><li>Nr of data types </li></ul>
    30. 30. Third Test case: search space <ul><li>Exact formula (score=0) </li></ul><ul><li>F(y)=x4+x3+x2-x </li></ul>
    31. 31. Forth Test case: Roman Figures <ul><li>Exact formula (score=0) </li></ul><ul><li>Strings to Integers </li></ul><ul><li>Does not give a correct solution yet. </li></ul>
    32. 32. Genpro current state
    33. 33. Program representations <ul><li>Tree based GP (TGP) </li></ul><ul><li>Linear based GP (LGP) </li></ul><ul><li>Graph based GP (GGP) </li></ul><ul><li>OO based GP (OOGP) </li></ul><ul><li>Reflection based GP </li></ul>// 4 registers in r double lgp ( double[] r ) { r[0] = r[3] + 43 r[2] = r[1] + r[0] if( [r2] > 2) r[3] = sin ( r [2] ) r[0] = r[2] + r[3] return r[0]; } Linear example Tree example
    34. 34. Runtime Requirements <ul><li>GenPro Core: Java 1.5 or Android 1.0 </li></ul><ul><li>GenPro Examples: Java 1.5 (Swing) </li></ul><ul><li>GenPro Android Example: Android 1.5 </li></ul><ul><li>Generated programs: Java 1.0, Android 1.0 or J2ME (CLDC 1.0) </li></ul>
    35. 35. Features <ul><li>Supported cell types: Integer, Double, Boolean, String </li></ul><ul><li>Operators: </li></ul><ul><ul><li>all numeric (+,-,/,*,%), </li></ul></ul><ul><ul><li>boolean (&, ||, !), </li></ul></ul><ul><ul><li>logic operators: none </li></ul></ul><ul><li>Constructs: if, switch (Integer & Double) </li></ul>
    36. 36. Wanted Features <ul><li>Cell type mutation (keep the if-cells!) </li></ul><ul><li>Runtime compiling of programs </li></ul><ul><li>Support for void ( state-full objects! ), enumerations and arrays </li></ul><ul><li>enumeration switch </li></ul><ul><li>for (and while?) loop </li></ul><ul><li>support for tournaments (eg: Tic tact toe, Robocode) </li></ul>
    37. 37. GenPro challenges you! <ul><li>Real world application of GenPro </li></ul><ul><li>2 days of free help getting your problem solved. </li></ul><ul><li>More developers! </li></ul><ul><li>Join the architecture meeting! </li></ul><ul><li>Solve the multithreading bug! </li></ul>
    38. 38. Links <ul><li>GenPro code: code.google.com/p/genpro </li></ul><ul><li>GenPro on twitter: @bluevoid </li></ul><ul><li>Groups: groups.google.com/group/genpro-gp </li></ul><ul><li>A scientists view on reflective GP: algoval.essex.ac.uk/rep/oogp/ReflectionBasedGP.pdf </li></ul><ul><li>Koza’s view on GP: </li></ul><ul><li>www.genetic-programming.com/sevendiffs.html </li></ul><ul><li>Contact Rob: [email_address] </li></ul>
    39. 39. Genpro, the origin of species (not covered on feb 2!)
    40. 40. Example Solution structure cc2 Integer cc3 Integer Lib1 Math Input1 Integer abs(int) round(double) compareTo(Integer) Output1 Integer cc1 Integer parameters Method calls
    41. 41. Crossing of solutions cross over point Int Int Math Int Int Int Solution A Int Int Math Int Int Int Solution B
    42. 42. Creating children of A & B Int Int Int Int Parent A Int Int Int Int Parent B Child A~B Child B~A cross over point Int Int Int Int Int Int Int Int
    43. 43. Crossover Reconnecting A2 B1 B2 A1 Int Int Math Int Int Int Child A~B Int Int Math Int Int Int Child B~A
    44. 44. Example Solution structure 2 in code: setup.setCallCells(3, &quot;cc&quot;, Double .class, Integer.class , Boolean .class ); cc2 Integer cc3 Boolean Lib1 Math Input1 Integer abs(int) Output1 Integer cc1 Double
    45. 45. Crossover on mixed value types A2 B1 Int Int Math Int Int Dbl Child B~A compareTo(Integer) Mismatch in param type! Potential mismatch in return type and method call
    46. 46. Crossover in nature: the origin of species Heart Lung “ DNA” of Horse Heart Lung Brain “ DNA” of Dog cross over points do not match!
    47. 47. Solving the species problem <ul><li>prevent mismatch by pre-typing the solution template - specie-fy </li></ul><ul><li>use converters - Heart-brain bypass? </li></ul><ul><li>on misconnect: no child - allow specie groups as in nature </li></ul><ul><li>random reconnect - create new species </li></ul>
    48. 48. Crossover on mixed value types: random reconnect A2 B1 Int Int Math Int Int Dbl Child B~A compareTo(Integer) Moved connection
    49. 49. Here be dragons
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×