SlideShare a Scribd company logo
Genetic Algorithms and Genetic Programming in Python
 
Karl Sims
What are Genetic Algorithms and Genetic Programs?
Search algorithms based on the mechanics of natural selection and natural genetics
 
 
John Holland, University of Michigan
The Circle of Life
Find a better path
Minimize connection length
Best set of indexes
Artificial Intelligence
Locomotion
Art
They seem to do well when... ,[object Object]
The solution space is dynamic, non-linear, or otherwise complex
The solution space is poorly understood
Domain knowledge is scarce or difficult to encode
No mathematical analysis is available
Fitness, payoff, or suitability of a solution can be determined
Traditional search methods fail
What are the “mechanics” of natural selection and natural genetics?
The Circle of Life
Genotype and Phenotype “ blueprint”, chromosomes “ Physical manifestation”
Pyevolve Built-In Genotypes ,[object Object]
Two-Dimensional Binary String
One-Dimensional List
Two-Dimensional List
Tree
Genetic Program (Tree specific to GP)
You can roll your own!
1-D Binary String ,[object Object]
2-D Binary String ,[object Object]
1-D and 2-D Lists ,[object Object],“ Alleles” are the object types the list is made of... by default integers You can pass in a function to construct the list with whatever object you want ,[object Object]
Tree and Genetic Program ,[object Object]
Tree and Genetic Program ,[object Object]
Now that we have our genome, how is it expressed, and how do we know how “good” it is?
The Circle of Life
Fitness
Find the global minima of Schaffer F6
The genotype is the (x,y) point, eg. (3.2,-4.7)
Phenotype is the value that results from putting in the (x,y) point into the function
Fitness is how close that resultant value is to the global minimum value (in this case, zero)
The Fitness Function def schafferF6(genome): x2y2 = genome[0]**2 + genome[1]**2 t1 = math.sin(math.sqrt(x2y2)); t2 = 1.0 + 0.001*(x2y2); score = 0.5 + (t1**2 - 0.5)/(t2*t2) return score genome = G1DList.G1DList(2) genome.setParams(rangemin=-100.0, rangemax=100.0,  bestrawscore=0.0000, rounddecimal=4) genome.initializator.set(Initializators.G1DListInitializatorReal) genome.evaluator.set(schafferF6)
The Petri Dish
The GA Engine from pyevolve import GSimpleGA …  create genome … ga = GSimpleGA.GSimpleGA(genome, seed=123) ga.setMinimax(Consts.minimaxType["minimize"]) ga.evolve(freq_stats=1000) print ga.bestIndividual() Output: Gen. 0 (0.00%): Max/Min/Avg Fitness(Raw) [0.60(0.82)/0.37(0.09)/0.50(0.50)] Gen. 1000 (12.50%): Max/Min/Avg Fitness(Raw) [0.30(0.97)/0.23(0.01)/0.25(0.25)] Gen. 2000 (25.00%): Max/Min/Avg Fitness(Raw) [0.21(0.99)/0.17(0.01)/0.18(0.18)] Gen. 3000 (37.50%): Max/Min/Avg Fitness(Raw) [0.26(0.99)/0.21(0.00)/0.22(0.22)] Evolution stopped by Termination Criteria function ! Gen. 3203 (40.04%): Max/Min/Avg Fitness(Raw) [0.30(0.99)/0.23(0.00)/0.25(0.25)] Total time elapsed: 14.357 seconds. - GenomeBase Score:  0.000005 Fitness:  0.232880 - G1DList List size:  2 List:  [0.0020881039453384299, 0.00043589670629584631]
The Circle of Life
Selection
Pyevolve Built-In Selection Operators ,[object Object]
Setting the selector from pyevolve import Selectors ga = GSimpleGA.GSimpleGA(genome) ga.selector.set(Selectors.GRouletteWheel) ga.selector is a “FunctionSlot.”  It can accept any number of functions that will be used in order.  ga.evaluator is another.
The Circle of Life
Crossover
Take two (or more) individuals and combine them in some way to create children
Single Point Crossover
Single Point Crossover
Pyevolve Built-In Crossover Operators ,[object Object]
Mutation
Binary Mutation
Tree Mutation
Pyevolve Built-In Mutation Operators ,[object Object]
Genetic Programs are basically just a type of Genetic Algorithm
John Koza, University of Michigan, Stanford
Plug for Python and Entrepreneurship ,[object Object]
Visual Effects plug-ins for film and video ,[object Object],[object Object]
Scientific Games now a near $1B company
65% of all scatch-off tickets created
A genetic program is just a tree with nodes
 
 
Simple Operator Node Examples ,[object Object]
Terminal Node Examples ,[object Object]
Putting it all together: Creating a better unskilled forecast
Defining The Problem ,[object Object]
Climate Average: 7.67 degrees
Yesterday's High: 8.01 degrees
Last Year's High: 10.87 degrees ,[object Object]
Create The Genome genome = GTree.GTreeGP() genome.setParams(max_depth=4, method="ramped") genome.evaluator.set(eval_func)
Create The Genome genome = GTree.GTreeGP() genome.setParams(max_depth=4, method="ramped") genome.evaluator.set(eval_func)
Create The Genome genome = GTree.GTreeGP() genome.setParams(max_depth=4, method="ramped") genome.evaluator.set(eval_func)
Initialize The Engine ga = GSimpleGA.GSimpleGA(genome) ga.setParams(gp_terminals = ['per', 'perlast', 'clm'], gp_function_prefix = "gp") ga.setMinimax(Consts.minimaxType["minimize"]) ga.setGenerations(50) ga.setCrossoverRate(1.0) ga.setMutationRate(0.25) ga.setPopulationSize(800)
Initialize The Engine ga = GSimpleGA.GSimpleGA(genome) ga.setParams(gp_terminals = ['per', 'perlast', 'clm'], gp_function_prefix = "gp") ga.setMinimax(Consts.minimaxType["minimize"]) ga.setGenerations(50) ga.setCrossoverRate(1.0) ga.setMutationRate(0.25) ga.setPopulationSize(800)
Define The Fitness Function def eval_func(chromosome): code_comp = chromosome.getCompiledCode() error = 0.0 count = 0.0 for day,per,peryest,perlast,clm,actual in data: forecast = eval(code_comp) error += abs(forecast-actual) count += 1 return error/count
Define The Fitness Function def eval_func(chromosome): code_comp = chromosome.getCompiledCode() error = 0.0 count = 0.0 for day,per,peryest,perlast,clm,actual in data: forecast = eval(code_comp) error += abs(forecast-actual) count += 1 return error/count
Define The Operators @GTree.gpdec(representation="+", color="red") def gp_add(a, b): return a+b @GTree.gpdec(representation="-", color="red") def gp_sub(a, b): return a-b @GTree.gpdec(representation="avg", color="green") def gp_avg(a, b): return (a+b)/2.0 @GTree.gpdec(representation="if_gt", color="blue") def gp_gt(a, b, c, d): if a>b: return c else: return d
Define The Operators @GTree.gpdec(representation="+", color="red") def gp_add(a, b): return a+b @GTree.gpdec(representation="-", color="red") def gp_sub(a, b): return a-b @GTree.gpdec(representation="avg", color="green") def gp_avg(a, b): return (a+b)/2.0 @GTree.gpdec(representation="if_gt", color="blue") def gp_gt(a, b, c, d): if a>b: return c else: return d
Run ga = GSimpleGA.GSimpleGA(genome) ga.setParams(gp_terminals = ['per','perlast','clm'], gp_function_prefix = "gp") ga.setMinimax(Consts.minimaxType["minimize"]) ga.setGenerations(50) ga.setCrossoverRate(1.0) ga.setMutationRate(0.25) ga.setPopulationSize(800) ga.evolve(freq_stats=10) best = ga.bestIndividual() print best
The Shiny Stuff
Interactive Mode ga.setInteractiveGeneration(50) >>> it.plotHistPopScore(population) >>> it.plotPopScore(population) >>> popScores = it.getPopScores(population)
GP Tree Graphs Gtree.GTreeGP.writePopulationDot(gp, filename, "png", 0, 1) best = ga.bestIndividual() best.writeDotImage("best.png")
GP Tree Graphs Gtree.GTreeGP.writePopulationDot(gp, filename, "png", 0, 1) best = ga.bestIndividual() best.writeDotImage("best.png")
Callbacks def step_callback(gp_engine): gen = gp_engine.getCurrentGeneration() if gen % 10 == 0: filename = "best_{gen}.png".format(gen=gen)  GTree.GTreeGP.writePopulationDot(gp_engine,  filename, "png", 0, 1) ga.stepCallback.set(step_callback)
Callbacks def step_callback(gp_engine): gen = gp_engine.getCurrentGeneration() if gen % 10 == 0: filename = "best_{gen}.png".format(gen=gen)  GTree.GTreeGP.writePopulationDot(gp_engine,  filename, "png", 0, 1) ga.stepCallback.set(step_callback)
Database Adapters csv_adapter = DBAdapters.DBFileCSV(identify="run1",  filename="stats.csv") ga.setDBAdapter(csv_adapter) ga.evolve(freq_stats=10) print ga.getStatistics() - Statistics Minimum raw score  = 7.35 Fitness average  = 16.43 Minimum fitness  = 16.32 Raw scores variance  = 1352.22 Standard deviation of raw scores  = 36.77 Average of raw scores  = 16.43 Maximum fitness  = 19.72 Maximum raw score  = 295.57
Real-Time Plots adapter = DBAdapters.DBVPythonGraph(identify="run_01",  frequency = 1) ga.setDBAdapter(adapter)

More Related Content

What's hot

COSCUP: Introduction to Julia
COSCUP: Introduction to JuliaCOSCUP: Introduction to Julia
COSCUP: Introduction to Julia
岳華 杜
 
concurrency gpars
concurrency gparsconcurrency gpars
concurrency gparsPaul King
 
20170415 當julia遇上資料科學
20170415 當julia遇上資料科學20170415 當julia遇上資料科學
20170415 當julia遇上資料科學
岳華 杜
 
Julia: The language for future
Julia: The language for futureJulia: The language for future
Julia: The language for future
岳華 杜
 
20190907 Julia the language for future
20190907 Julia the language for future20190907 Julia the language for future
20190907 Julia the language for future
岳華 杜
 
Stuart Mitchell - Pulp Optimisation
Stuart Mitchell - Pulp OptimisationStuart Mitchell - Pulp Optimisation
Stuart Mitchell - Pulp Optimisation
danny.adair
 
Tutorial: Python, PuLP and GLPK
Tutorial: Python, PuLP and GLPKTutorial: Python, PuLP and GLPK
Tutorial: Python, PuLP and GLPK
sucha
 
awesome groovy
awesome groovyawesome groovy
awesome groovyPaul King
 

What's hot (8)

COSCUP: Introduction to Julia
COSCUP: Introduction to JuliaCOSCUP: Introduction to Julia
COSCUP: Introduction to Julia
 
concurrency gpars
concurrency gparsconcurrency gpars
concurrency gpars
 
20170415 當julia遇上資料科學
20170415 當julia遇上資料科學20170415 當julia遇上資料科學
20170415 當julia遇上資料科學
 
Julia: The language for future
Julia: The language for futureJulia: The language for future
Julia: The language for future
 
20190907 Julia the language for future
20190907 Julia the language for future20190907 Julia the language for future
20190907 Julia the language for future
 
Stuart Mitchell - Pulp Optimisation
Stuart Mitchell - Pulp OptimisationStuart Mitchell - Pulp Optimisation
Stuart Mitchell - Pulp Optimisation
 
Tutorial: Python, PuLP and GLPK
Tutorial: Python, PuLP and GLPKTutorial: Python, PuLP and GLPK
Tutorial: Python, PuLP and GLPK
 
awesome groovy
awesome groovyawesome groovy
awesome groovy
 

Similar to Genetic Programming in Python

Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011Devnology
 
Introduction to Julia
Introduction to JuliaIntroduction to Julia
Introduction to Julia
岳華 杜
 
Soft Shake Event / A soft introduction to Neo4J
Soft Shake Event / A soft introduction to Neo4JSoft Shake Event / A soft introduction to Neo4J
Soft Shake Event / A soft introduction to Neo4J
Florent Biville
 
Calculus-level Coding Overview
Calculus-level Coding OverviewCalculus-level Coding Overview
Calculus-level Coding Overview
Optimal Designs Enterprise
 
Artificial Life Creation (Dmytro Tarasenko Technology Stream)
Artificial Life Creation (Dmytro Tarasenko Technology Stream)Artificial Life Creation (Dmytro Tarasenko Technology Stream)
Artificial Life Creation (Dmytro Tarasenko Technology Stream)
IT Arena
 
Structural Optimization using Genetic Algorithms - Artificial Intelligence Fu...
Structural Optimization using Genetic Algorithms - Artificial Intelligence Fu...Structural Optimization using Genetic Algorithms - Artificial Intelligence Fu...
Structural Optimization using Genetic Algorithms - Artificial Intelligence Fu...
Ahmed Gamal Abdel Gawad
 
[GAN by Hung-yi Lee]Part 1: General introduction of GAN
[GAN by Hung-yi Lee]Part 1: General introduction of GAN[GAN by Hung-yi Lee]Part 1: General introduction of GAN
[GAN by Hung-yi Lee]Part 1: General introduction of GAN
NAVER Engineering
 
Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016
Spencer Fox
 
Genetic programming with clojure.spec and Beyond
Genetic programming with clojure.spec and BeyondGenetic programming with clojure.spec and Beyond
Genetic programming with clojure.spec and Beyond
Carin Meier
 
Evolutionary Optimization Algorithms & Large-Scale Machine Learning
Evolutionary Optimization Algorithms & Large-Scale Machine LearningEvolutionary Optimization Algorithms & Large-Scale Machine Learning
Evolutionary Optimization Algorithms & Large-Scale Machine Learning
University of Maribor
 
Gradient Boosted Regression Trees in scikit-learn
Gradient Boosted Regression Trees in scikit-learnGradient Boosted Regression Trees in scikit-learn
Gradient Boosted Regression Trees in scikit-learn
DataRobot
 
Introduction
IntroductionIntroduction
Introductionbutest
 
Intelligent Ruby + Machine Learning
Intelligent Ruby + Machine LearningIntelligent Ruby + Machine Learning
Intelligent Ruby + Machine LearningIlya Grigorik
 
Software testing
Software testingSoftware testing
Software testing
DIPEN SAINI
 
그림 그리는 AI
그림 그리는 AI그림 그리는 AI
그림 그리는 AI
NAVER Engineering
 
Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.
Аліна Шепшелей
 
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
Inhacking
 
GA.pptx
GA.pptxGA.pptx
DevFest Istanbul - a free guided tour of Neo4J
DevFest Istanbul - a free guided tour of Neo4JDevFest Istanbul - a free guided tour of Neo4J
DevFest Istanbul - a free guided tour of Neo4J
Florent Biville
 
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVM
Dierk König
 

Similar to Genetic Programming in Python (20)

Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011
 
Introduction to Julia
Introduction to JuliaIntroduction to Julia
Introduction to Julia
 
Soft Shake Event / A soft introduction to Neo4J
Soft Shake Event / A soft introduction to Neo4JSoft Shake Event / A soft introduction to Neo4J
Soft Shake Event / A soft introduction to Neo4J
 
Calculus-level Coding Overview
Calculus-level Coding OverviewCalculus-level Coding Overview
Calculus-level Coding Overview
 
Artificial Life Creation (Dmytro Tarasenko Technology Stream)
Artificial Life Creation (Dmytro Tarasenko Technology Stream)Artificial Life Creation (Dmytro Tarasenko Technology Stream)
Artificial Life Creation (Dmytro Tarasenko Technology Stream)
 
Structural Optimization using Genetic Algorithms - Artificial Intelligence Fu...
Structural Optimization using Genetic Algorithms - Artificial Intelligence Fu...Structural Optimization using Genetic Algorithms - Artificial Intelligence Fu...
Structural Optimization using Genetic Algorithms - Artificial Intelligence Fu...
 
[GAN by Hung-yi Lee]Part 1: General introduction of GAN
[GAN by Hung-yi Lee]Part 1: General introduction of GAN[GAN by Hung-yi Lee]Part 1: General introduction of GAN
[GAN by Hung-yi Lee]Part 1: General introduction of GAN
 
Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016Introduction to R Short course Fall 2016
Introduction to R Short course Fall 2016
 
Genetic programming with clojure.spec and Beyond
Genetic programming with clojure.spec and BeyondGenetic programming with clojure.spec and Beyond
Genetic programming with clojure.spec and Beyond
 
Evolutionary Optimization Algorithms & Large-Scale Machine Learning
Evolutionary Optimization Algorithms & Large-Scale Machine LearningEvolutionary Optimization Algorithms & Large-Scale Machine Learning
Evolutionary Optimization Algorithms & Large-Scale Machine Learning
 
Gradient Boosted Regression Trees in scikit-learn
Gradient Boosted Regression Trees in scikit-learnGradient Boosted Regression Trees in scikit-learn
Gradient Boosted Regression Trees in scikit-learn
 
Introduction
IntroductionIntroduction
Introduction
 
Intelligent Ruby + Machine Learning
Intelligent Ruby + Machine LearningIntelligent Ruby + Machine Learning
Intelligent Ruby + Machine Learning
 
Software testing
Software testingSoftware testing
Software testing
 
그림 그리는 AI
그림 그리는 AI그림 그리는 AI
그림 그리는 AI
 
Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.
 
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
 
GA.pptx
GA.pptxGA.pptx
GA.pptx
 
DevFest Istanbul - a free guided tour of Neo4J
DevFest Istanbul - a free guided tour of Neo4JDevFest Istanbul - a free guided tour of Neo4J
DevFest Istanbul - a free guided tour of Neo4J
 
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVM
 

Recently uploaded

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 

Recently uploaded (20)

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 

Genetic Programming in Python

  • 1. Genetic Algorithms and Genetic Programming in Python
  • 2.  
  • 4. What are Genetic Algorithms and Genetic Programs?
  • 5. Search algorithms based on the mechanics of natural selection and natural genetics
  • 6.  
  • 7.  
  • 12. Best set of indexes
  • 15. Art
  • 16.
  • 17. The solution space is dynamic, non-linear, or otherwise complex
  • 18. The solution space is poorly understood
  • 19. Domain knowledge is scarce or difficult to encode
  • 20. No mathematical analysis is available
  • 21. Fitness, payoff, or suitability of a solution can be determined
  • 23. What are the “mechanics” of natural selection and natural genetics?
  • 25. Genotype and Phenotype “ blueprint”, chromosomes “ Physical manifestation”
  • 26.
  • 30. Tree
  • 31. Genetic Program (Tree specific to GP)
  • 32. You can roll your own!
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38. Now that we have our genome, how is it expressed, and how do we know how “good” it is?
  • 41. Find the global minima of Schaffer F6
  • 42. The genotype is the (x,y) point, eg. (3.2,-4.7)
  • 43. Phenotype is the value that results from putting in the (x,y) point into the function
  • 44. Fitness is how close that resultant value is to the global minimum value (in this case, zero)
  • 45. The Fitness Function def schafferF6(genome): x2y2 = genome[0]**2 + genome[1]**2 t1 = math.sin(math.sqrt(x2y2)); t2 = 1.0 + 0.001*(x2y2); score = 0.5 + (t1**2 - 0.5)/(t2*t2) return score genome = G1DList.G1DList(2) genome.setParams(rangemin=-100.0, rangemax=100.0, bestrawscore=0.0000, rounddecimal=4) genome.initializator.set(Initializators.G1DListInitializatorReal) genome.evaluator.set(schafferF6)
  • 47. The GA Engine from pyevolve import GSimpleGA … create genome … ga = GSimpleGA.GSimpleGA(genome, seed=123) ga.setMinimax(Consts.minimaxType["minimize"]) ga.evolve(freq_stats=1000) print ga.bestIndividual() Output: Gen. 0 (0.00%): Max/Min/Avg Fitness(Raw) [0.60(0.82)/0.37(0.09)/0.50(0.50)] Gen. 1000 (12.50%): Max/Min/Avg Fitness(Raw) [0.30(0.97)/0.23(0.01)/0.25(0.25)] Gen. 2000 (25.00%): Max/Min/Avg Fitness(Raw) [0.21(0.99)/0.17(0.01)/0.18(0.18)] Gen. 3000 (37.50%): Max/Min/Avg Fitness(Raw) [0.26(0.99)/0.21(0.00)/0.22(0.22)] Evolution stopped by Termination Criteria function ! Gen. 3203 (40.04%): Max/Min/Avg Fitness(Raw) [0.30(0.99)/0.23(0.00)/0.25(0.25)] Total time elapsed: 14.357 seconds. - GenomeBase Score: 0.000005 Fitness: 0.232880 - G1DList List size: 2 List: [0.0020881039453384299, 0.00043589670629584631]
  • 50.
  • 51. Setting the selector from pyevolve import Selectors ga = GSimpleGA.GSimpleGA(genome) ga.selector.set(Selectors.GRouletteWheel) ga.selector is a “FunctionSlot.” It can accept any number of functions that will be used in order. ga.evaluator is another.
  • 54. Take two (or more) individuals and combine them in some way to create children
  • 57.
  • 61.
  • 62. Genetic Programs are basically just a type of Genetic Algorithm
  • 63. John Koza, University of Michigan, Stanford
  • 64.
  • 65.
  • 66. Scientific Games now a near $1B company
  • 67. 65% of all scatch-off tickets created
  • 68. A genetic program is just a tree with nodes
  • 69.  
  • 70.  
  • 71.
  • 72.
  • 73. Putting it all together: Creating a better unskilled forecast
  • 74.
  • 77.
  • 78. Create The Genome genome = GTree.GTreeGP() genome.setParams(max_depth=4, method="ramped") genome.evaluator.set(eval_func)
  • 79. Create The Genome genome = GTree.GTreeGP() genome.setParams(max_depth=4, method="ramped") genome.evaluator.set(eval_func)
  • 80. Create The Genome genome = GTree.GTreeGP() genome.setParams(max_depth=4, method="ramped") genome.evaluator.set(eval_func)
  • 81. Initialize The Engine ga = GSimpleGA.GSimpleGA(genome) ga.setParams(gp_terminals = ['per', 'perlast', 'clm'], gp_function_prefix = "gp") ga.setMinimax(Consts.minimaxType["minimize"]) ga.setGenerations(50) ga.setCrossoverRate(1.0) ga.setMutationRate(0.25) ga.setPopulationSize(800)
  • 82. Initialize The Engine ga = GSimpleGA.GSimpleGA(genome) ga.setParams(gp_terminals = ['per', 'perlast', 'clm'], gp_function_prefix = "gp") ga.setMinimax(Consts.minimaxType["minimize"]) ga.setGenerations(50) ga.setCrossoverRate(1.0) ga.setMutationRate(0.25) ga.setPopulationSize(800)
  • 83. Define The Fitness Function def eval_func(chromosome): code_comp = chromosome.getCompiledCode() error = 0.0 count = 0.0 for day,per,peryest,perlast,clm,actual in data: forecast = eval(code_comp) error += abs(forecast-actual) count += 1 return error/count
  • 84. Define The Fitness Function def eval_func(chromosome): code_comp = chromosome.getCompiledCode() error = 0.0 count = 0.0 for day,per,peryest,perlast,clm,actual in data: forecast = eval(code_comp) error += abs(forecast-actual) count += 1 return error/count
  • 85. Define The Operators @GTree.gpdec(representation="+", color="red") def gp_add(a, b): return a+b @GTree.gpdec(representation="-", color="red") def gp_sub(a, b): return a-b @GTree.gpdec(representation="avg", color="green") def gp_avg(a, b): return (a+b)/2.0 @GTree.gpdec(representation="if_gt", color="blue") def gp_gt(a, b, c, d): if a>b: return c else: return d
  • 86. Define The Operators @GTree.gpdec(representation="+", color="red") def gp_add(a, b): return a+b @GTree.gpdec(representation="-", color="red") def gp_sub(a, b): return a-b @GTree.gpdec(representation="avg", color="green") def gp_avg(a, b): return (a+b)/2.0 @GTree.gpdec(representation="if_gt", color="blue") def gp_gt(a, b, c, d): if a>b: return c else: return d
  • 87. Run ga = GSimpleGA.GSimpleGA(genome) ga.setParams(gp_terminals = ['per','perlast','clm'], gp_function_prefix = "gp") ga.setMinimax(Consts.minimaxType["minimize"]) ga.setGenerations(50) ga.setCrossoverRate(1.0) ga.setMutationRate(0.25) ga.setPopulationSize(800) ga.evolve(freq_stats=10) best = ga.bestIndividual() print best
  • 89. Interactive Mode ga.setInteractiveGeneration(50) >>> it.plotHistPopScore(population) >>> it.plotPopScore(population) >>> popScores = it.getPopScores(population)
  • 90. GP Tree Graphs Gtree.GTreeGP.writePopulationDot(gp, filename, "png", 0, 1) best = ga.bestIndividual() best.writeDotImage("best.png")
  • 91. GP Tree Graphs Gtree.GTreeGP.writePopulationDot(gp, filename, "png", 0, 1) best = ga.bestIndividual() best.writeDotImage("best.png")
  • 92. Callbacks def step_callback(gp_engine): gen = gp_engine.getCurrentGeneration() if gen % 10 == 0: filename = "best_{gen}.png".format(gen=gen) GTree.GTreeGP.writePopulationDot(gp_engine, filename, "png", 0, 1) ga.stepCallback.set(step_callback)
  • 93. Callbacks def step_callback(gp_engine): gen = gp_engine.getCurrentGeneration() if gen % 10 == 0: filename = "best_{gen}.png".format(gen=gen) GTree.GTreeGP.writePopulationDot(gp_engine, filename, "png", 0, 1) ga.stepCallback.set(step_callback)
  • 94. Database Adapters csv_adapter = DBAdapters.DBFileCSV(identify="run1", filename="stats.csv") ga.setDBAdapter(csv_adapter) ga.evolve(freq_stats=10) print ga.getStatistics() - Statistics Minimum raw score = 7.35 Fitness average = 16.43 Minimum fitness = 16.32 Raw scores variance = 1352.22 Standard deviation of raw scores = 36.77 Average of raw scores = 16.43 Maximum fitness = 19.72 Maximum raw score = 295.57
  • 95. Real-Time Plots adapter = DBAdapters.DBVPythonGraph(identify="run_01", frequency = 1) ga.setDBAdapter(adapter)
  • 97.  
  • 98.  
  • 99.  
  • 100.  
  • 101.  
  • 102.  
  • 103.
  • 104. Today's High: 5.74 degrees
  • 107.
  • 108. Average skilled forecast is about 3 degrees error
  • 109.
  • 110.
  • 112. = There is a supercomputer under your desk
  • 113. There is a supercomputer under your desk
  • 114.  
  • 115.  
  • 116.  
  • 119.  

Editor's Notes

  1. Intellovations – internet applications for data analysis and display ForecastWatch and ForecastAdvisor Background – C/C++/Java Amateur scientist Wanted to answer the question “is there any difference between weather forecasts from different providers”
  2. Intellovations – internet applications for data analysis and display ForecastWatch and ForecastAdvisor Background – C/C++/Java Amateur scientist Wanted to answer the question “is there any difference between weather forecasts from different providers”