SlideShare uma empresa Scribd logo
1 de 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)

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 

Último (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 

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.  

Notas do Editor

  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”