18
) ( 25 . 1 ) tan( ) sin( y x y x z Imagine that I am in a good mood Imagine that I am going to give you some money! In particular I am going to give you z dollars, after you tell me the value of x and y x and y in the range of 0 to 10

Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

  • View
    212

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

)(25.1)tan()sin( yxyxz

Imagine that I am in a good mood

Imagine that I am going to give you some money!

In particular I am going to give you z dollars, after you tell me the value of x and y

x and y in the range of 0 to 10

Page 2: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

x y

z

Page 3: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

Optimizing Search(Iterative Improvement Algorithms)

I.e Hill climbing, Simulated Annealing Genetic Algorithms

Optimizing search is different to the path finding search we have studied in many ways.

• The problems are ones for which exhaustive and heuristic search are NP-hard. • The path is not important (for that reason we typically don’t bother to keep a tree around) (thus we are CPU bound, not memory bound).• Every state is a “solution”.• The search space is (often) continuous. • Usually we abandon hope of finding the best solution, and settle for a very good solution.• The task is usually to find the minimum (or maximum) of a function.

Page 4: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

Example Problem I(Continuous)

y = f(x)

Finding the maximum (minimum) of some function (within a defined range).

Page 5: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

The Traveling Salesman Problem (TSP)

A salesman spends his time visiting n cities. In one tour he visits each city just once, and finishes up where he started. In what order should he visit them to minimize the distance traveled?

There are (n-1)!/2 possible tours.

A B CA 0 12 34 ...B 12 0 76 ...C 34 76 0 ...... ... ... ... ...

Example Problem II(Discrete)

Page 6: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

Function Fitting

Depending on the way the problem is setup this, could be continuous

and/or discrete.

Discrete partFinding the form of the function

is it X2 or X4 or ABS(log(X)) + 75

Continuous part Finding the value for X

is it X= 3.1 or X= 3.2

Example Problem III (Continuous and/or discrete)

Page 7: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

Assume that we can

• Represent a state.• Quickly evaluate the quality of a state.• Define operators to change from one state to another.

y = log(x) + sin(tan(y-x))x = 2;y = 7;

log(2) + sin(tan(7-2)) = 2.00305

x = add_10_percent(x)y = subtract_10_percent(y)….

A C F K W…..Q A

A to C = 234C to F = 142…Total 10,231

A B CA 0 12 34 ...B 12 0 76 ...C 34 76 0 ...... ... ... ... ...

A C F K W…..Q A

A C K F W…..Q A

Function Optimizing Traveling Salesman

Page 8: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

Hill-Climbing Ifunction Hill-Climbing (problem) returns a solution state

inputs : problem // a problem.

local variables : current // a node.

next // a node.

current Make-Node ( Initial-State [ problem ]) // make random

loop do // initial state.

next a highest-valued successor of current

if Value [next] < Value [current] then return current

current next

end

Page 9: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

How would Hill-Climbing do on the following problems?

How can we improve Hill-Climbing?

Random restarts!

Intuition: call hill-climbing as many times as you can afford, choose the best answer.

Page 10: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

function Simulated-Annealing ( problem, schedule ) returns a solution state

inputs : problem // a problem

schedule // a mapping from time to "temperature"

local variables : current // a node

next // a node

T // a "temperature" controlling the probability of downward steps

current Make-Node ( Initial-State [ problem ])

for t 1 to do

T schedule [ t ]

if T = 0 then return current

next a randomly selected successor of current

E Value [ next ] - Value [ current ]

if E > 0 then current next

else current next only with probability eE/T

Page 11: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

Genetic Algorithms I (R and N, pages 619-621)

• Variation (members of the same species are differ in some ways).• Heritability (some of variability is inherited).• Finite resources (not every individual will live to reproductive age).

Given the above, the basic idea of natural selection is this.

Some of the characteristics that are variable will be advantageous to survival. Thus, the individuals with the desirable traits are more likely to reproduce and have offspring with similar traits ...

And therefore the species evolve over time…

Richard Dawkins

Since natural selection is known to have solved many important optimizations problems it is natural to ask can we exploit the power of natural selection?

Page 12: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

Genetic Algorithms IIThe basic idea of genetic algorithms (evolutionary programming).

•Initialize a population of n states (randomly)

While time allows

• Measure the quality of the states using some fitness function.• “kill off” some of the states.• Allow the surviving states to reproduce (sexually or asexually or..)

end• Report best state as answer.

All we need do is ...(A) Figure out how to represent the states. (B) Figure out a fitness function. (C) Figure out how to allow our states to reproduce.

Page 13: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

Genetic Algorithms IIIlog(xy) + sin(tan(y-x))

y x

-

tan

sin

+

log

y

pow

x

One possible representation of the states is a tree structure…

Another is a bitstring…

100111010101001

For problems where we are trying to find the best order to do some thing (TSP), a linked list might work...

C A E F BD A

Page 14: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

Genetic Algorithms IIII

y x

-

tan

sin

+

log

y

pow

x

Usually the fitness function is fairly trivial.

For the function maximizing problem we can evaluate the given function with the state (the values for x, y, z... etc)

For the function finding problem we can evaluate the function and see how close it matches the data.

For TSP the fitness function is just the length of the tour represented by the linked list

C A E F BD A23 12 56 77 36 83

Page 15: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

Genetic Algorithms V

y x

-

tan

sin

+

log

y

pow

x

5

+

cos

y

/

x

y x

-

tan

sin

+

cos

y

/

x

Parent state A Parent state B

Child of A and B

10011101

1110100010011000

Parent state A

Parent state B Child of A and B

Sexual Reproduction(crossover)

Page 16: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

Genetic Algorithms VI

10011101 10011111

Parent state A

Child of A

Asexual Reproduction

Mutation

5

+

cos

y

/

x

5

+

tan

y

/

x

Mutation

Parent state A Child of A

C A E F BD A

C A E D BF A

Parent state A

Child of A

Page 17: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

Discussion of Genetic Algorithms

• It turns out that the policy of “keep the best n individuals” is not the best idea…

• Genetic Algorithms require many parameters... (population size, fraction of the population generated by crossover; mutation rate, number of sexes... ) How do we set these?

• Genetic Algorithms are really just a kind of hill-climbing search, but seem to have less problems with local maximums…

• Genetic Algorithms are very easy to parallelize...

Applications

Protein Folding, Circuit Design, Job-Shop Scheduling Problem, Timetabling, designing wings for aircraft….

Page 18: Imagine that I am in a good mood Imagine that I am going to give you some money ! In particular I am going to give you z dollars, after you tell me the

y x

-

tan

sin

+

log

y

pow

x

5

+

cos

y

/

x