23
Evolving Solutions Machine Learning Programs that Search for Solutions Searching Random Points Recursive Descent / Ascent Sub-Optimization Faulty Analogies Fitness Genetic Algorithms Particle Swarm Optimization Simulated Annealing 1 Monday, January 14, 13

Genetic algorithms

Embed Size (px)

DESCRIPTION

Presentation for CraftmansGuild on 15-Jan-2013. Genetic Algorithms, Simulated Annealing, Particle Swarm Optimization.

Citation preview

Page 1: Genetic algorithms

Evolving SolutionsMachine Learning

Programs that Search for SolutionsSearching Random Points

Recursive Descent / AscentSub-Optimization

Faulty AnalogiesFitness

Genetic AlgorithmsParticle Swarm Optimization

Simulated Annealing

1Monday, January 14, 13

Page 2: Genetic algorithms

Basic Concepts

2Monday, January 14, 13

Page 3: Genetic algorithms

Learning ==> Improvement

Some quality is being improved.

There is some measure of good / bad.

There is some way to move toward good.

Change position

Change behavior

3Monday, January 14, 13

Page 4: Genetic algorithms

Learning ==>Some quality is being improved.

Implies / Assumes:

There is consensus about good versus bad.

There is some way to measure good / bad.

Give that measure a name: “Fitness”

Analogy to nature and evolution concept.

4Monday, January 14, 13

Page 5: Genetic algorithms

Searching for BetterRandom Search

Randomize values in degrees of freedom.

Compare resulting fitness.

Pick the best results.

And then what?

Recursive Descent / Ascent

Assumes that solution space has a gradient.

Assumes there are minima / maxima.5Monday, January 14, 13

Page 6: Genetic algorithms

Seeker:When do you quit searching?

Infinite Loop versus “Stopping Condition”

Eventually we run out of time / resource / energy.

Complications:

Sometimes “Best” is not well-defined.

The solution space is continuously changing.

The shape (gradient qualities) of space is unknown.

6Monday, January 14, 13

Page 7: Genetic algorithms

Faulty Analogs

7Monday, January 14, 13

Page 8: Genetic algorithms

EvolutionThere is some way to measure “fitness”

Fitness is a function of a set of objects that can vary over individual instances.

Call the objects “genes” to use genetic analogy.

Mutation ==> Changing the values of “genes”.

Sexual Reproduction ==> Merging gene “sequences.”

Next Generation <== keep most fit, cull least fit.8Monday, January 14, 13

Page 9: Genetic algorithms

Genetic AlgorithmDefine degrees of freedom ==> genes.

Produce first generation with randomized genes.

Evaluate fitness of each individual

Calculate / Run a simulation of environment.

Keep most fit <==> Cull least fit.

Populate the next generation. ( mutate and/or splice )

Repeat until “done”

Note: Real environments change over time. 9Monday, January 14, 13

Page 10: Genetic algorithms

Main Loop In Smalltalk

10Monday, January 14, 13

Page 11: Genetic algorithms

Next Generation

11Monday, January 14, 13

Page 12: Genetic algorithms

Mutation

12Monday, January 14, 13

Page 13: Genetic algorithms

Degrees Of Freedom

13Monday, January 14, 13

Page 15: Genetic algorithms

Insect (Swarm) Behavior

Swarms search for “food” / Encounter “intruders”-- mostly random search.

Insects communicate with their buddies.

Their buddies re-direct their paths to gather / fight.

15Monday, January 14, 13

Page 16: Genetic algorithms

Particle Swarm OptimizationMixed Analogy: Particle <==> Flying insect.

Particles have “position” in multi-dimensional space.

Assign each particle to a group “swarm” (at random).

After fitness is evaluated, particles move toward the most fit particle in their swarm.

The most fit particle in the swarm can stay where it is, ascend, or dither (random move).

Recursive ascent / descent may guide movesif the space is believed to be reasonably continuous.

16Monday, January 14, 13

Page 17: Genetic algorithms

http://vimeo.com/17407010

17Monday, January 14, 13

Page 18: Genetic algorithms

Stopping ConditionsHow good is good enough?

Genetic Algorithms and Particle Swarm Optimizationcan provide multiple solutions.

Stop when best fitness is no longer improving.

Stop when move method is no longer moving anything.

Stop at some arbitrary limit:

Number of generations.

Time limit.

18Monday, January 14, 13

Page 19: Genetic algorithms

Simulated AnnealingConcept: Temperature ==> Energy Available.

Energy ==> speed of movement.

Speed == How much change from step to step?

Annealing == Cooling at controlled rate ==> The allowed change decreases from step to step.

Stopping Condition:

Temperature (Change/Step) goes to zero.

Other stopping conditions may also apply.

19Monday, January 14, 13

Page 20: Genetic algorithms

Gotcha’sExperts refuse to say “optimum / optimal / optimized”

No way to verify solution is best possible.

Parameters selected may not cover everything.

Say “sub-optimal” or “satisfices” (good enough)

Solution is only good inside your simulation.

Real world is certainly different.

Don’t over-train: Solution may lack flexibility.20Monday, January 14, 13

Page 21: Genetic algorithms

VisualizationHow do you visualize position in hyperspace?

Assign each degree of freedom to some geometry.

3 degrees (x,y,z) ==> position

2 degrees (angle, angle) ==> orientation of “axis”

additional degrees ==> shape dimensions

Example: Torus (donut) Shape -- 9 shape dimensions

Radius, Eccentricity, Angle (?), r, e, a

frequency of: twist, wave, bulge21Monday, January 14, 13

Page 22: Genetic algorithms

http://megaswf.com/serve/

22Monday, January 14, 13

Page 23: Genetic algorithms

Lessons LearnedI did not and do not expect this to work.It is just something I always wanted to tinker.

Best fitness for 2007-2008: Stay out of the market!

“When-to-buy” was competing with “when-to-sell” and producing counter-productive results.==> Need more complex strategy ==> more parameters.

Very compute intensive (generation takes way too long)==> Need faster data structure ==> Refactor database.==> Squeak VM is single-thread ==> Port to Erlang ???==> Potential GPU application.

23Monday, January 14, 13