SlideShare a Scribd company logo
1 of 95
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 Optimisationdanny.adair
 
Tutorial: Python, PuLP and GLPK
Tutorial: Python, PuLP and GLPKTutorial: Python, PuLP and GLPK
Tutorial: Python, PuLP and GLPKsucha
 
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 Neo4JFlorent Biville
 
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 GANNAVER 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 2016Spencer 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 BeyondCarin 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 LearningUniversity 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-learnDataRobot
 
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 testingDIPEN SAINI
 
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
 
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 Neo4JFlorent 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 JVMDierk 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

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Recently uploaded (20)

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

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”