22c:145 Artificial Intelligence

19
22c:145 Artificial Intelligence Fall 2005 Informed Search and Exploration III Cesare Tinelli The University of Iowa Copyright 2001-05 — Cesare Tinelli and Hantao Zhang. a a These notes are copyrighted material and may not be used in other course settings outside of the University of Iowa in their current or modified form without the express written permission of the copyright holders. 22c:145 Artificial Intelligence, Fall’05 – p.1/17

Transcript of 22c:145 Artificial Intelligence

Page 1: 22c:145 Artificial Intelligence

22c:145 Artificial IntelligenceFall 2005

Informed Search and Exploration III

Cesare Tinelli

The University of Iowa

Copyright 2001-05 — Cesare Tinelli and Hantao Zhang. a

a These notes are copyrighted material and may not be used in other course settings outside of the

University of Iowa in their current or modified form without the express written permission of the copyright

holders.22c:145 Artificial Intelligence, Fall’05 – p.1/17

Page 2: 22c:145 Artificial Intelligence

Readings

Chap. 4 of [Russell and Norvig, 2003]

22c:145 Artificial Intelligence, Fall’05 – p.2/17

Page 3: 22c:145 Artificial Intelligence

Iterative ImprovementAlgorithms

In many optimization problems the goal state itself is thesolution.

The state space is a set of complete configurations.

Search is about finding the optimal configuration (as in TSP) orjust a feasible configuration (as in scheduling problems).

In such cases, one can use iterative improvement (or localsearch) algorithms.

An evaluation (or objective) function h must be available thatmeasures the quality of each state.

Main Idea: Start with an initial configuration and make smallchanges to it that improve its quality.

22c:145 Artificial Intelligence, Fall’05 – p.3/17

Page 4: 22c:145 Artificial Intelligence

Local Search: The LandscapeMetaphor

Ideally, the evaluation function h should be monotonic: thecloser a state to an optimal goal state the better its h-value.

Each state can be seen as a point on a surface.

The search consists in moving on the surface, looking for itshighest peaks (or, lowest valleys): the optimal solutions.

evaluation

currentstate

22c:145 Artificial Intelligence, Fall’05 – p.4/17

Page 5: 22c:145 Artificial Intelligence

Local Search Example: TSP

TSP: Travelling Salesperson Problem

h = length of the tour

Strategy: Start with any complete tour, perform pairwiseexchanges

22c:145 Artificial Intelligence, Fall’05 – p.5/17

Page 6: 22c:145 Artificial Intelligence

Local Search Example: TSP

TSP: Travelling Salesperson Problem

h = length of the tour

Strategy: Start with any complete tour, perform pairwiseexchanges

Variants of this approach get within 1% of optimal very quickly withthousands of cities.

22c:145 Artificial Intelligence, Fall’05 – p.5/17

Page 7: 22c:145 Artificial Intelligence

Local Search Example:n-queens

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

h = number of conflicts

Strategy: Move a queen to reduce number of conflicts

h = 5 h = 2 h = 0

22c:145 Artificial Intelligence, Fall’05 – p.6/17

Page 8: 22c:145 Artificial Intelligence

Local Search Example:n-queens

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

h = number of conflicts

Strategy: Move a queen to reduce number of conflicts

h = 5 h = 2 h = 0

Almost always solves n-queens problems almost instantaneouslyfor very large n, e.g., n = 106.

22c:145 Artificial Intelligence, Fall’05 – p.6/17

Page 9: 22c:145 Artificial Intelligence

Hill-Climbing (or GradientDescent) Search

“Like climbing Everest in thick fog with amnesia”

function HILL-CLIMBING( problem) returns a state that is a local maximuminputs : 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

end

22c:145 Artificial Intelligence, Fall’05 – p.7/17

Page 10: 22c:145 Artificial Intelligence

Hill-Climbing: Shortcomings

Depending on the initial state, it can get stuck on local maxima.

It may converge very slowly.

In continuous spaces, choosing the step-size is non-obvious.

currentstate

objective function

state space

global maximum

local maximum

"flat" local maximum

shoulder

22c:145 Artificial Intelligence, Fall’05 – p.8/17

Page 11: 22c:145 Artificial Intelligence

Hill Climbing: Improvements

Various possible alternatives:

Restart from a random point in the space.

Expand up to m > 1 generations of descendants beforechoosing best node.

Allow down-hill moves sometimes.

Keep n > 1 nodes in the fring at each step.

22c:145 Artificial Intelligence, Fall’05 – p.9/17

Page 12: 22c:145 Artificial Intelligence

Beyond Hill Climbing:Simulated Annealing Search

Allows occasional down-hill steps, to minimize the probability ofgetting stuck in a local maximum.

Down-hill steps taken randomly but with probability thatdecreases with time.

Probability controlled by a given annealing schedule for atemperature parameter T .

If schedule lowers T slowly enough, search will end in a globalmaximum.

It may take several tries with test problems to devise a goodannealing schedule.

22c:145 Artificial Intelligence, Fall’05 – p.10/17

Page 13: 22c:145 Artificial Intelligence

Simulated AnnealingAlgorithm

function SIMULATED-ANNEALING( problem, schedule) returns a solution stateinputs : problem, a problem

schedule, a mapping from time to “temperature”local variables : current, a node

next, a nodeT, a “temperature” controlling prob. 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 e∆ E/T

Erratum: In first if , replace “T = 0” with “T = 0 or IS-GOAL-STATE(current)”.22c:145 Artificial Intelligence, Fall’05 – p.11/17

Page 14: 22c:145 Artificial Intelligence

Properties of SimulatedAnnealing

The smaller |∆E|, the greater e∆E

T ; the greater T , the greatere

∆E

T .

At fixed “temperature” T , state occupation probability reachesBoltzman distribution

p(x) = αeE(x)kT

T decreased slowly enough⇒ always reach best state.

This is not necessarily an interesting guarantee.

Devised by Metropolis et al., 1953, for physical processmodelling.

Widely used in VLSI layout, airline scheduling, etc.

22c:145 Artificial Intelligence, Fall’05 – p.12/17

Page 15: 22c:145 Artificial Intelligence

Beyond Hill Climbing: LocalBeam Search

Idea: keep k states instead of 1; choose top k of all theirsuccessors.

Not the same as k searches run in parallel!Searches that find good states recruit other searches to jointhem.

Problem: quite often, all k states end up on same localmaximum.

Solution: choose k successors randomly, biased towards goodones.

Observe the close analogy to natural selection.

22c:145 Artificial Intelligence, Fall’05 – p.13/17

Page 16: 22c:145 Artificial Intelligence

Beyond Hill Climbing: GeneticAlgorithms

Inspired by Darwin’s theory of natural selection.

Each state is seen as an individual in a population.

A genetic algorithm applies selection and reproductionoperators to an initial population.

The aim is to generate individuals that are most successful,according to a given fitness function.

It is basically a stochastic local beam search, but withsuccessors generated from pairs of states.

Local maxima are avoided by giving a nonzero chance ofreproduction to low-scoring individuals.

22c:145 Artificial Intelligence, Fall’05 – p.14/17

Page 17: 22c:145 Artificial Intelligence

The Basic Genetic Algorithm

function GENETIC-ALGORITHM( population, FITNESS-FN) returns an individualinputs: population, a set of individuals

FITNESS-FN, a function that measures the fitness of an individual

repeatparents SELECTION( population, FITNESS-FN)population REPRODUCTION( parents)

until some individual is fit enoughreturn the best individual in population, according to FITNESS-FN

22c:145 Artificial Intelligence, Fall’05 – p.15/17

Page 18: 22c:145 Artificial Intelligence

Genetic Algorithms: ClassicApproach

Each state is represented by a finite string over a finitealphabet.

Each character in the string is a gene.

The selection mechanism is randomized, with the probability ofselection proportional to the fitness measure.

Reproduction is accomplished by cross-over and mutation.

32252124

(a)Initial Population

(b)Fitness Function

(c)Selection

(d)Cross−Over

(e)Mutation

24748552

32752411

24415124

24

23

20

32543213 11

29%

31%

26%

14%

32752411

24748552

32752411

24415124

32748552

24752411

32752124

24415411

24752411

32748152

24415417

22c:145 Artificial Intelligence, Fall’05 – p.16/17

Page 19: 22c:145 Artificial Intelligence

Encodings for GeneticAlgorithms

Choosing the right encoding of state configurations to strings iscrucial.

Crossover helps only if substrings are meaningful components thatcan be reassembled into a new meaningful configuration.

+ =

Note: GAs are not evolution: e.g., real genes encode replicationmachinery!

22c:145 Artificial Intelligence, Fall’05 – p.17/17