Devnology Workshop Genpro 2 feb 2011
Upcoming SlideShare
Loading in...5
×
 

Devnology Workshop Genpro 2 feb 2011

on

  • 1,017 views

 

Statistics

Views

Total Views
1,017
Views on SlideShare
900
Embed Views
117

Actions

Likes
0
Downloads
7
Comments
0

1 Embed 117

http://devnology.nl 117

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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 Devnology Workshop Genpro 2 feb 2011 Presentation Transcript

  • 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 behavior Reinforcement learning Automated logic Simulated annealing Bayesian networks “ computer programs are the best representation of computer programs” - John R. Koza -
  • Representations outside GP
    • if-then production rules
    • Horn clauses
    • decision trees
    • Bayesian networks
    • propositional logic
    • formal grammars
    • binary decision diagrams
    • frames
    • conceptual clusters
    • concept sets
    • numerical weight vectors (for neural nets)
    • vectors of numerical coefficients for polynomials or other fixed expressions (for adaptive systems)
    • genetic classifier system rules
    • fixed tables of values (as in reinforcement learning)
    • linear chromosome strings (as in the conventional genetic algorithm)
  • Genetic algorithm / programming
    • Generate random solutions
    • Evaluate & score (cumulative error => lower is better)
    • Cross and mutate to generate offspring
    • Repeat step 2 and 3 till score is sufficient
    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
  • Program representations in GP
    • bits
    • numerical weight vectors
    • machine / byte code
    • constructs
    • concepts?
    Which granularity is better?
  • Genpro birth
  • One year later: Spreadsheet Inspiration
    • Every cell has a value and a type
    3 = A2 + B1 2 1 41
    • Every cell might have a formula
    • Changing the references (mutation!) changes the outcome
  • One (call)cell, one method call
    • A GenPro cell holds:
    • Type
    • Value
    • Target-object (or class)
    • Target method
    • Parameters
    Integer cc1 = Math.max(a, b)
  • One (call)cell, one method call Integer cc1 = Math.max(a, b)
    • cc1
    • Integer
    • Value: 56
    Math max (a, b) int 56 int 32 param a param b
  • 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 +
  • Working with GenPro
  • Using GenPro: extending Trainer
    • public abstract class Trainer {
    • public abstract Setup createSetup();
    • public abstract TestSetSolutionEvaluator createEvaluator();
    • }
    • TrainerVisual extends Trainer
    • -> autostart of Swing UI
  • Setup
    • Defines: how to create programs and run generations of programs
    • Parts of Setup:
    • Input and output cells
    • Type and maximum nr of cells
    • Elements (constants, libraries)
    • Generation size
    • When to stop
    • When to store solutions
  • GridSolutionEvaluator extends TestSetSolutionEvaluator
    • Defines how to evaluate and select programs.
    • public TestSet createTestSet();
    • public double scoreOutput(ReferenceCell outputCell, Object calculated, Object expected);
    • public double scoreGrid(Grid g);
    • public double scoreGridException(Throwable t);
  • TestSet
    • Defines the inputs and outputs values to evaluate a program.
    • Is actually a list of cellnames with sets of values.
    • public TestSet(Setup setup, String... cellNames)
    • public void addCellValues( final Object... objects)
  • First testcase: exact formula
    • Convert Fahrenheit to Celsius
    • input: Fahrenheit
    • output: Celsius
    • generates exact formula (score goes to 0)
  • GenPro inner working
  • 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
  • The heart of the machine: Method.invoke()
    • public void calc() {
    • // fetch parameter values
    • Object[] paramObjects = new Object[ paramCells.length ];
      • for (int i = 0; i < paramCells.length; i++) {
      • paramObjects[i] = paramCells[i].getValue();
      • }
      • // execute method on target object/class
      • Object val = t argetMethod.invoke(targetCell.getValue(), paramObjects);
      • // store value
      • setValue(val);
    • }
  • Why reflection?
    • Strong typed connecting
    • No compile time ( = faster @ small testsets )
    • Easy extension, just add POJO’s
    • Use existing libraries
    • Reduces learning curve for user
    • Convertible to working Java code
  • Operators / libraries
    • public class NumberOperations {
    • public static double multiply( double a, double b) {
    • return a * b;
    • }
    • public static double divide( double a, double b) {
    • return a / b;
    • }
    • }
    Lib
  • Back to reality ;)
  • Egg Boiling!
  • Second testcase: non-exact formula
    • Eggweight
    • input: width & height of egg
    • output: weight of egg
    • added lib: formula for volume of Egg
    • public class Egg {
    • public static double volume( double l, double b) {
    • return (0.6057 - 0.0018 * b) * l * b * b;
    • }
    • }
  • Search Space size
    • Nr of cells
    • Nr of operators/methods
    • Nr of parameters
    • Nr of data types
  • Third Test case: search space
    • Exact formula (score=0)
    • F(y)=x4+x3+x2-x
  • Forth Test case: Roman Figures
    • Exact formula (score=0)
    • Strings to Integers
    • Does not give a correct solution yet.
  • Genpro current state
  • Program representations
    • Tree based GP (TGP)
    • Linear based GP (LGP)
    • Graph based GP (GGP)
    • OO based GP (OOGP)
    • Reflection based GP
    // 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
  • Runtime Requirements
    • GenPro Core: Java 1.5 or Android 1.0
    • GenPro Examples: Java 1.5 (Swing)
    • GenPro Android Example: Android 1.5
    • Generated programs: Java 1.0, Android 1.0 or J2ME (CLDC 1.0)
  • Features
    • Supported cell types: Integer, Double, Boolean, String
    • Operators:
      • all numeric (+,-,/,*,%),
      • boolean (&, ||, !),
      • logic operators: none
    • Constructs: if, switch (Integer & Double)
  • Wanted Features
    • Cell type mutation (keep the if-cells!)
    • Runtime compiling of programs
    • Support for void ( state-full objects! ), enumerations and arrays
    • enumeration switch
    • for (and while?) loop
    • support for tournaments (eg: Tic tact toe, Robocode)
  • GenPro challenges you!
    • Real world application of GenPro
    • 2 days of free help getting your problem solved.
    • More developers!
    • Join the architecture meeting!
    • Solve the multithreading bug!
  • Links
    • GenPro code: code.google.com/p/genpro
    • GenPro on twitter: @bluevoid
    • Groups: groups.google.com/group/genpro-gp
    • A scientists view on reflective GP: algoval.essex.ac.uk/rep/oogp/ReflectionBasedGP.pdf
    • Koza’s view on GP:
    • www.genetic-programming.com/sevendiffs.html
    • Contact Rob: [email_address]
  • 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) Output1 Integer cc1 Integer parameters Method calls
  • 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 Int Int Int Int 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 .class ); cc2 Integer cc3 Boolean Lib1 Math Input1 Integer abs(int) Output1 Integer cc1 Double
  • 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
  • Crossover in nature: the origin of species Heart Lung “ DNA” of Horse Heart Lung Brain “ DNA” of Dog cross over points do not match!
  • Solving the species problem
    • prevent mismatch by pre-typing the solution template - specie-fy
    • use converters - Heart-brain bypass?
    • on misconnect: no child - allow specie groups as in nature
    • random reconnect - create new species
  • Crossover on mixed value types: random reconnect A2 B1 Int Int Math Int Int Dbl Child B~A compareTo(Integer) Moved connection
  • Here be dragons