+ All Categories
Home > Documents > Hill Climbing 1st in Class

Hill Climbing 1st in Class

Date post: 10-Apr-2015
Category:
Upload: api-3705912
View: 4,499 times
Download: 2 times
Share this document with a friend
32
When A* doesn’t work CIS 391 – Intro to Artificial Intelligence A few slides adapted from CS 471, Fall 2004, UBMC (which were adapted from notes by Charles R. Dyer, University of Wisconsin-Madison)
Transcript
Page 1: Hill Climbing 1st in Class

When A* doesn’t work

CIS 391 – Intro to Artificial Intelligence

A few slides adapted from CS 471, Fall 2004, UBMC

(which were adapted from notes by Charles R. Dyer, University of Wisconsin-Madison)

Page 2: Hill Climbing 1st in Class

CIS 391 - Intro to AI 2

Outline

Local Search: Hill Climbing Escaping Local Maxima: Simulated Annealing Genetic Algorithms (if time allows)

Page 3: Hill Climbing 1st in Class

CIS 391 - Intro to AI 3

Local search and optimization

Local search:• Use single current state and move to neighboring states.

Idea: start with an initial guess at a solution and incrementally improve it until it is one

Advantages:• Use very little memory• Find often reasonable solutions in large or infinite state

spaces.

Also useful for pure optimization problems.• Find best state according to some objective function.• e.g. survival of the fittest as a metaphor for optimization.

Page 4: Hill Climbing 1st in Class

Hill Climbing

Page 5: Hill Climbing 1st in Class

CIS 391 - Intro to AI 5

Hill climbing on a surface of states

Height Defined by Evaluation Function

Page 6: Hill Climbing 1st in Class

CIS 391 - Intro to AI 6

Hill-climbing search: Take I & III. While ( uphill points):

• Move in the direction of increasing value, lessening distance to goal

II. If ( a successor si for the current state n such that

—h(si) < h(n)

—h(si) h(sj) for all successors sj of n, ji,):

• then move from n to si.

• Otherwise, halt at n. Properties:

• Terminates when a peak is reached.• Does not look ahead of the immediate neighbors of the current state.• Chooses randomly among the set of best successors, if there is more than

one.• Doesn’t backtrack, since it doesn’t remember where it’s been

a.k.a. greedy local search

"Like climbing Everest in thick fog with amnesia"

Page 7: Hill Climbing 1st in Class

CIS 391 - Intro to AI 7

Hill-climbing search: Take IIIfunction HILL-CLIMBING( problem) return a state that is a local maximum

input: problem, a problemlocal variables: current, a node.

neighbor, a node.

current MAKE-NODE(INITIAL-STATE[problem])loop do

neighbor a highest valued successor of currentif VALUE [neighbor] ≤ VALUE[current] then return STATE[current]current neighbor

Page 8: Hill Climbing 1st in Class

CIS 391 - Intro to AI 8

Hill climbing Example I

23 4 56 7 8

1start goal

5 h = 4

h = 3

h = 2

h = 1

h = 0

h = 5

5

4

45

2

h(n) = (number of tiles out of place)

2 4 56 7 8

1

3 24 56 7 8

1

3

3 24 5 6 7 8

1

3 24 5 86 7

1

3 24 5 8 6 7

1

Page 9: Hill Climbing 1st in Class

CIS 391 - Intro to AI 9

Hill-climbing Example: n-queens

Put n queens on an n × n board with no two queens on the same row, column, or diagonal

Page 10: Hill Climbing 1st in Class

CIS 391 - Intro to AI 10

Hill-climbing example: 8-queens

h = number of pairs of queens that are attacking each other

a) A state with h=17 and the h-value for each possible successor.

b) A local minimum of h in the 8-queens state space (h=1).

a) b)

Page 11: Hill Climbing 1st in Class

CIS 391 - Intro to AI 11

Search Space features

Page 12: Hill Climbing 1st in Class

CIS 391 - Intro to AI 12

Drawbacks of hill climbing Problems:

• Local Maxima (foothills): peaks that aren’t the highest point in the space

• Plateaus: the space has a broad flat region that gives the search algorithm no direction (random walk)

• Ridges: flat like a plateau, but with dropoffs to the sides; steps to the North, East, South and West may go down, but a step to the NW may go up.

Page 13: Hill Climbing 1st in Class

CIS 391 - Intro to AI 13

Example of a local maximum

1 23 4 56 7 8

1

2

2

2

0

start goal

4 1 23 56 7 8

4 1 23 5 6 7 8

4 1 23 7 56 8

4 23 1 56 7 8

Page 14: Hill Climbing 1st in Class

CIS 391 - Intro to AI 14

The Shape of an Easy Problem

Page 15: Hill Climbing 1st in Class

CIS 391 - Intro to AI 15

The Shape of a Harder Problem

Page 16: Hill Climbing 1st in Class

CIS 391 - Intro to AI 16

The Shape of a Yet Harder Problem

Page 17: Hill Climbing 1st in Class

CIS 391 - Intro to AI 17

Remedies to drawbacks of hill climbing

Random restart

Problem reformulation

In the end: Some problem spaces are great for hill climbing and others are terrible.

Page 18: Hill Climbing 1st in Class

Simulated Annealing

Page 19: Hill Climbing 1st in Class

CIS 391 - Intro to AI 19

Simulated annealing (SA)

Annealing: the process by which a metal cools and freezes into a minimum-energy crystalline structure (the annealing process)

SA exploits an analogy between annealing and the search for a minimum [or maximum] in a more general system.

Page 20: Hill Climbing 1st in Class

CIS 391 - Intro to AI 20

Simulated annealing Idea:

• Escape local maxima by allowing “bad” moves.

• But gradually decrease their size and frequency. Bouncing ball analogy:

• Shaking hard (= high temperature).• Shaking less (= lower the temperature).

Control parameter T• By analogy with the original application is known as the system

“temperature.”

• T starts out high and gradually decreases toward 0.

• If T decreases slowly enough, then finds a global optimum with probability approaching 1.

Applied for VLSI layout, airline scheduling, etc.

Page 21: Hill Climbing 1st in Class

CIS 391 - Intro to AI 21

The Simulated Annealing Algorithmfunction SIMULATED-ANNEALING( problem, schedule) return a solution state

input: problem, a problemschedule, 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 currentnext a randomly selected successor of current∆E VALUE[next] - VALUE[current]if ∆E > 0 then current next else current next only with probability e∆E /T

Page 22: Hill Climbing 1st in Class

CIS 391 - Intro to AI 22

Local beam search Keep track of k states instead of one

• Initially: k random states• Next: determine all successors of k states• If any of successors is goal finished• Else select k best from successors and repeat.

Major difference with random-restart search• Information is shared among k search threads.

Can suffer from lack of diversity.• Stochastic variant: choose k successors at proportionally to

state success.

Page 23: Hill Climbing 1st in Class

Genetic Algorithms (only if time allows)

Page 24: Hill Climbing 1st in Class

CIS 391 - Intro to AI 24

Genetic algorithms

Start with k random states (the initial population) New states are generated by either

1. “Mutation” of a single state or

2. “Sexual Reproduction” (combining) of two parent states (selected according to their fitness)

Encoding used for the “genome” of an individual strongly affects the behavior of the search

Similar (in some ways) to stochastic beam search

Page 25: Hill Climbing 1st in Class

CIS 391 - Intro to AI 25

Representation: Strings of genes

Each chromosome • represents a possible solution• made up of a string of genes

Each gene encodes some property of the solution There is a fitness metric on phenotypes of

chromosomes• Evaluation of how well a solution with that set of properties

solves the problem.

New generations are formed by• Crossover: sexual reproduction• Mutation: asexual reproduction

Page 26: Hill Climbing 1st in Class

CIS 391 - Intro to AI 26

Encoding of a Chromosome

The chromosome encodes characteristics of the solution which it represents, often as a string of binary digits. Chromosome 1 1101100100110110

Chromosome 2 1101111000011110

Each bit or set of bits in this string represents some aspect of the solution.

Page 27: Hill Climbing 1st in Class

CIS 391 - Intro to AI 27

Example: Genetic Algorithm for Drive Train

Genes for: Number of Cylinders RPM: 1st -> 2nd

RPM 2nd -> 3rd

RPM 3rd -> Drive Rear end gear ratio Size of wheels

A Chromosome specifies a full drive train design

Page 28: Hill Climbing 1st in Class

CIS 391 - Intro to AI 28

Reproduction Reproduction by crossover selects genes from two parent

chromosomes and creates two new offspring. To do this, randomly choose some crossover point

(perhaps none). For the first child, everything before this point comes from

the first parent and everything after a from the second parent.

Crossover can then look like this ( | is the crossover point):

Chromosome 1 11001 | 00100110110Chromosome 2 10011 | 11000011110

Offspring 1 11001 | 11000011110Offspring 2 10011 | 00100110110

Page 29: Hill Climbing 1st in Class

CIS 391 - Intro to AI 29

Mutation

Mutation randomly changes genes in the new offspring.

For binary encoding we can switch a few randomly chosen bits from 1 to 0 or from 0 to 1.

Original offspring 1101111000011110

Mutated offspring 1100111000001110

Page 30: Hill Climbing 1st in Class

CIS 391 - Intro to AI 30

The Basic Genetic Algorithm

1. Generate random population of chromosomes

2. Until the end condition is met, create a new population by repeating following steps1. Evaluate the fitness of each chromosome

2. Select two parent chromosomes from a population, weighed by their fitness

3. With probability pc cross over the parents to form a new offspring.

4. With probability pm mutate new offspring at each position on the chromosome.

5. Place new offspring in the new population

3. Return the best solution in current population

Page 31: Hill Climbing 1st in Class

CIS 391 - Intro to AI 31

Genetic algorithmfunction GENETIC_ALGORITHM( population, FITNESS-FN) return an individual

input: population, a set of individualsFITNESS-FN, a function which determines the quality of the

individualrepeat

new_population empty setloop for i from 1 to SIZE(population) do

x RANDOM_SELECTION(population, FITNESS_FN)y RANDOM_SELECTION(population,

FITNESS_FN)child REPRODUCE(x,y)if (small random probability) then child MUTATE(child )add child to new_population

population new_populationuntil some individual is fit enough or enough time has elapsedreturn the best individual

Page 32: Hill Climbing 1st in Class

CIS 391 - Intro to AI 32

Genetic algorithms:8-queens


Recommended