Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 11 SLS wrap up, Intro To Planning

Similar presentations


Presentation on theme: "Lecture 11 SLS wrap up, Intro To Planning"— Presentation transcript:

1 Lecture 11 SLS wrap up, Intro To Planning
Computer Science CPSC 322 Lecture 11 SLS wrap up, Intro To Planning

2 Lecture Overview Recap of Lecture 10 SLS algorithms
Comparing SLS algorithms SLS variants Planning Intro (time permitting)

3 Local Search Solving CSPs is NP-hard Idea: Useful method in practice
Search space for many CSPs is huge Exponential in the number of variables Even arc consistency with domain splitting is often not enough Idea: Consider the space of complete assignments of values to variables (all possible worlds) Neighbours of a current node are similar variable assignments Move from one node to another according to a function that scores how good each assignment is Extremely general! Works for problems other than CSPs E.g. arc consistency only works for CSPs Useful method in practice Best available method for many constraint satisfaction and constraint optimization problems

4 Example Only the current node is kept in memory at each step.
Given the set of variables {V1 ….,Vn }, each with domain Dom(Vi) The start node is any assignment {V1 / v1,…,Vn / vn } . The neighbors of node with assignment A= {V1 / v1,…,Vn / vn } are nodes with assignments that differ from A for one value only Example Only the current node is kept in memory at each step. Local search does NOT backtrack! V1 = v1 ,V2 = v1 ,.., Vn = v1 V1 = v2 ,V2 = v1 ,.., Vn = v1 V1 = v1 ,V2 = vn ,.., Vn = v1 V1 = v4 ,V2 = v1 ,.., Vn = v1 V1 = v4 ,V2 = v2 ,.., Vn = v1 V1 = v4 ,V2 = v1 ,.., Vn = v2 V1 = v4 ,V2 = v3 ,.., Vn = v1

5 Iterative Best Improvement
How to determine the neighbor node to be selected? Iterative Best Improvement: select the neighbor that optimizes some evaluation function Which strategy would make sense? Select neighbour with … Evaluation function: h(n): number of constraint violations in state n Greedy descent: evaluate h(n) for each neighbour, pick the neighbour n with minimal h(n) Hill climbing: equivalent algorithm for maximization problems Here: Maximize number of satisfied constraints Minimal number of constraint violations

6 Problems with Iterative Best Improvement
It gets misled by locally optimal points (Local Maxima/ Minima) Evaluation function One of the most obvious heuristics is to select the value that results in the minimum # of conflicts with the other variables - the min conflicts heuristics Ex, in case of eight queen, it is the number of attacking queens. Min conflict is surprising effective and can solve the million-queens problem in less than 50 steps. It has also been used to schedule the hubble telecope, reducing the time taken to schedule a week of observations from three weeks to around 10’ X1 Most research in local search is about finding effective mechanisms for escaping from local minima/maxima X2

7 Stochastic Local Search for CSPs
Uses greedy steps to find local minima, and randomness to avoid getting trapped in them Start node: random assignment Goal: assignment with zero unsatisfied constraints Heuristic function h: number of unsatisfied constraints Lower values of the function are better Stochastic local search is a mix of: Greedy descent: move to neighbor with lowest h Random walk: take some random steps i.e., move to a neighbour with some randomness Random restart: reassigning values to all variables

8 Lecture Overview Recap of Lecture 10 SLS algorithms
Comparing SLS algorithms SLS variants Planning Intro (time permitting)

9 Which randomized method would work best in each of the these two search spaces?
Evaluation function State Space (1 variable) State Space (1 variable) 1 2 A. Greedy descent with random steps best on 1 Greedy descent with random restart best on 2 B. Greedy descent with random steps best on 2 Greedy descent with random restart best on 1 C. equivalent

10 Which randomized method would work best in each of the these two search spaces?
Evaluation function State Space (1 variable) State Space (1 variable) 1 2 Greedy descent with random steps best on 2 Greedy descent with random restart best on 1 But these examples are simplified extreme cases for illustration in practice, you don’t know what your search space looks like Usually integrating both kinds of randomization works best

11 Greedy descent vs. Random sampling
Greedy descent is good for finding local minima bad for exploring new parts of the search space Random restart (aka Random sampling) is good for exploring new parts of the search space bad for finding local minima A mix of the two, plus some additional random choices, can work very well

12 General Local Search Algorithm
Sometime select the best neighbor during the local search Sometime select the neighbor at random (random step)

13 General Local Search Algorithm
Sometime do a random restart

14 General Local Search Algorithm
Sometime select the best neighbor during the local search Sometime do a random restart Sometime select the neighbor at random (random step)

15 Stochastic Local Search for CSPs: details
Examples of ways to add randomness to local search for a CSP One stage selection of variable and value: Sometime choose the best neighbour Sometime choose a random variable-value pair Two stage selection (first select variable V, then new value for V): Selecting variables: Sometimes choose the variable which participates in the largest number of conflicts Sometimes choose a random variable that participates in some conflict Sometimes choose a random variable Selecting values Sometimes choose the best value for the chosen variable Sometimes choose a random value for the chosen variable

16 Different ways of selecting neighbors
One stage selection: consider all assignments that differ in exactly one variable. How many of those are there for N variables and domain size d? A. O(Nd) C. O(Nd) B. O(dN) D. O(N+d)

17 Different ways of selecting neighbors
One stage selection: consider all assignments that differ in exactly one variable. How many of those are there for N variables and domain size d? Two stage selection: first choose a variable (e.g. the one involved in the most conflicts), then best value How many checks? A. O(Nd) A. O(Nd) C. O(Nd) B. O(dN) D. O(N+d)

18 Different ways of selecting neighbors
One stage selection: consider all assignments that differ in exactly one variable. How many of those are there for N variables and domain size d? Two stage selection: first choose a variable (e.g. the one involved in the most conflicts), then best value Lower computational complexity: O(N+d ) checks. But less progress per step A. O(Nd)

19 Random Walk (one-stage)
Neighbors are generated as assignments that differ in one variable's value How many neighbors there are given n variables with domains with d values? One way to add randomness to local search for a CSP Sometime chose the pair according to the scoring function Sometime chose a random one V1 V2 V3 V4 V5 V6 V7 V8 e.g. in 8-queen, given the assignment here How many neighbors? Chose ……. Chose: For 1, chose any var/value that has 12 as # of conflitcs

20 Random Walk (one-stage)
Neighbors are generated as assignments that differ in one variable's value How many neighbors there are given n variables with domains with d values? N(d-1) One way to add randomness to local search for a CSP Sometime chose the pair according to the scoring function Sometime chose a random one V1 V2 V3 V4 V5 V6 V7 V8 E.G in 8-queen, given the assignment here How many neighbors? 56 Chose v2 = 1, or v5 = 2 or v5 = 8 etc etc …….. Chose: any of the 56 neighbors For 1, chose any var/value that has 12 as # of conflitcs

21 Random Walk (two-stage selection)
Another strategy: select a variable first, then a value Selecting variable: alternate among selecting one that participates in the largest number of conflicts: A random variable that participates in some conflict. one of A random variable Selecting value: alternate among selecting one That minimizes # of conflicts at random 2 3 Sometimes choose the variable which participates in the largest number of conflicts. Sometimes choose, at random, any variable that participates in some conflict. Sometimes choose a random variable. Sometimes choose the best value for the chosen variable. Sometimes choose a random value for the chosen variable. Aispace 2 a: Greedy Descent with Min-Conflict Heuristic - Technique that tends to work well in practice

22 Random Walk (two-stage selection)
Another strategy: select a variable first, then a value Selecting variable: alternate among selecting one that participates in the largest number of conflicts. => V5 A random variable that participates in some conflict. one of V4, V5, V8 A random variable Selecting value: alternate among selecting one That minimizes # of conflicts => V5 = 1 at random 2 3 Sometimes choose the variable which participates in the largest number of conflicts. Sometimes choose, at random, any variable that participates in some conflict. Sometimes choose a random variable. Sometimes choose the best value for the chosen variable. Sometimes choose a random value for the chosen variable. Aispace 2 a: Greedy Descent with Min-Conflict Heuristic - Technique that tends to work well in practice

23 What you can look at in AIspace
One stage selection of variable and value: Sometime chose the best neighbour Sometime choose a random variable- value pair Two stage selection (first select variable V, then new value for V): Selecting variables: Sometimes choose the variable which participates in the largest number of conflicts Sometimes choose a random variable that participates in some conflict Sometimes choose a random variable Selecting values Sometimes choose the best value for the chosen variable Sometimes choose a random value for the chosen variable Can play with these alternatives in the Hill AI Space applet (there is a description for each algorithm) Random sampling Random walk Greedy Descent Greedy Descent Min conflict Greedy Descent with random walk Greedy Descent with random restart all options Sometimes choose the variable which participates in the largest number of conflicts. Sometimes choose, at random, any variable that participates in some conflict. Sometimes choose a random variable. Sometimes choose the best value for the chosen variable. Sometimes choose a random value for the chosen variable. Random Sampling At each step this algorithm randomly creates a new solution. For each variable a new value is randomly chosen. Random Walk At each step this algorithm randomly chooses a new solution from the set of neighbouring solutions. The set of neighbouring solutions is defined in this applet as the solutions where a single variable has a different value. Options: You may choose between a one or two stage heuristic. In the first case, the variable and value are chosen together; in the second case, the variable is chosen first and then the value. Greedy Descent At each step this algorithm chooses a value which improves the graph. Options: You may choose between a one or two stage heuristic. In a one stage heuristic the variable and value are chosen together. In the two stage heuristic the variable is chosen first and then the value. The variable with the greatest number of conflicts in its edges is chosen and then the value which resolves the highest number of conflicts is chosen from this variable's set of values. Greedy Descent with the Min Conflict Heuristic The Min Conflict Heuristic is one of the first heuristics used for constraint satisfaction problems. (Minton et Al, 1992). It chooses a variable randomly from the set of variables with conflicts (red edges). The value which results in the fewest conflicts is chosen from the possible assignments for this variable. This heuristic is almost identical to Greedy Descent with Random Walk with a two stage heuristic choosing any red node 100% and best value 100%. The only difference is the MCH may return to the previous assignment. Greedy Descent with Random Walk At each step this algorithm probabilistically decides whether or not to take a greedy step (change to the best neighbour) or to take a random walk (change to any neighbour) Options: You may choose between a one or two stage heuristic.  In the first case, the variable and value are chosen together; in the second case, the variable is chosen first and then the value. To increase the random walk percentage increase the "random ..." values. Greedy Descent with Random Restart This algorithm proceeds like the Greedy Descent algorithm but resets the variables to a new random solution at regular intervals. Options: Reset Graph specifies the number of steps between random resets of the graph. Greedy Descent with all Options …..

24 What you can look at in AIspace
One stage selection of variable and value: Sometime chose the best neighbour Sometime choose a random variable-value pair Two stage selection (first select variable V, then new value for V): Selecting variables: Sometimes choose the variable which participates in the largest number of conflicts Sometimes choose a random variable that participates in some conflict Sometimes choose a random variable Selecting values Sometimes choose the best value for the chosen variable Sometimes choose a random value for the chosen variable Sometimes choose the variable which participates in the largest number of conflicts. Sometimes choose, at random, any variable that participates in some conflict. Sometimes choose a random variable. Sometimes choose the best value for the chosen variable. Sometimes choose a random value for the chosen variable. Random Sampling At each step this algorithm randomly creates a new solution. For each variable a new value is randomly chosen. Random Walk At each step this algorithm randomly chooses a new solution from the set of neighbouring solutions. The set of neighbouring solutions is defined in this applet as the solutions where a single variable has a different value. Options: You may choose between a one or two stage heuristic. In the first case, the variable and value are chosen together; in the second case, the variable is chosen first and then the value. Greedy Descent At each step this algorithm chooses a value which improves the graph. Options: You may choose between a one or two stage heuristic. In a one stage heuristic the variable and value are chosen together. In the two stage heuristic the variable is chosen first and then the value. The variable with the greatest number of conflicts in its edges is chosen and then the value which resolves the highest number of conflicts is chosen from this variable's set of values. Greedy Descent with the Min Conflict Heuristic The Min Conflict Heuristic is one of the first heuristics used for constraint satisfaction problems. (Minton et Al, 1992). It chooses a variable randomly from the set of variables with conflicts (red edges). The value which results in the fewest conflicts is chosen from the possible assignments for this variable. This heuristic is almost identical to Greedy Descent with Random Walk with a two stage heuristic choosing any red node 100% and best value 100%. The only difference is the MCH may return to the previous assignment. Greedy Descent with Random Walk At each step this algorithm probabilistically decides whether or not to take a greedy step (change to the best neighbour) or to take a random walk (change to any neighbour) Options: You may choose between a one or two stage heuristic.  In the first case, the variable and value are chosen together; in the second case, the variable is chosen first and then the value. To increase the random walk percentage increase the "random ..." values. Greedy Descent with Random Restart This algorithm proceeds like the Greedy Descent algorithm but resets the variables to a new random solution at regular intervals. Options: Reset Graph specifies the number of steps between random resets of the graph. Greedy Descent with all Options Greedy Descent with all options This one allows one to define all the others

25 Lecture Overview Recap of Lecture 10 SLS algorithms
Comparing SLS algorithms SLS variants Planning Intro (time permitting)

26 Evaluating SLS algorithms
SLS algorithms are randomized The time taken until they solve a problem is a random variable It is entirely normal to have runtime variations of 2 orders of magnitude in repeated runs! E.g. 0.1 seconds in one run, 10 seconds in the next one, on the same problem instance Sometimes SLS algorithm doesn’t even terminate at all: stagnation If an SLS algorithm sometimes stagnates, what is its mean runtime (across many runs)? Infinity! In practice, one often counts timeouts as some fixed large value X Still, summary statistics, such as mean run time or median run time, don't tell the whole story E.g. would penalize an algorithm that often finds a solution quickly but sometime stagnates

27 Comparing SLS algorithms
A better way to evaluate empirical performance Runtime distributions Perform many runs (e.g. below left: 1000 runs)

28 Comparing SLS algorithms
A better way to evaluate empirical performance Runtime distributions Perform many runs (e.g. below left: 1000 runs) Consider the empirical distribution of the runtimes Sort the empirical runtimes Compute fraction (probability) of solved runs within each runtime Rotate graph 90 degrees. E.g. below: longest run took 12 seconds

29 Comparing runtime distributions
x axis: runtime (or number of steps) y axis: proportion (or number) of runs solved within that runtime Fraction of solved runs, i.e. P(solved within x # of steps/time) # of steps

30 Comparing runtime distributions
x axis: runtime (or number of steps) y axis: proportion (or number) of runs solved in that runtime Fraction of solved runs, i.e. P(solved within x # of steps/time) # of steps Which algorithm is most likely to solve the problem within 7 steps? A. blue B. red C. green

31 Comparing runtime distributions
x axis: runtime (or number of steps) y axis: proportion (or number) of runs solved in that runtime Fraction of solved runs, i.e. P(solved within x # of steps/time) # of steps Which algorithm is most likely to solve the problem within 7 steps? B. red

32 Comparing runtime distributions
Which algorithm has the best median performance? I.e., which algorithm takes the fewest number of steps to be successful in 50% of the cases? A. blue B. red C. green Fraction of solved runs, i.e. P(solved within x # of steps/time) # of steps

33 Comparing runtime distributions
Which algorithm has the best median performance? I.e., which algorithm takes the fewest number of steps to be successful in 50% of the cases? A. blue Fraction of solved runs, i.e. P(solved within x # of steps/time)

34 Comparing runtime distributions
x axis: runtime (or number of steps) y axis: proportion (or number) of runs solved in that runtime Typically use a log scale on the x axis Slow, but does not stagnate Crossover point: if we run longer than 80 steps, green is the best algorithm Fraction of solved runs, i.e. P(solved within x # of steps/time) 57% solved after 80 steps, then stagnate If we run less than 10 steps, red is the best algorithm 28% solved after 10 steps, then stagnate # of steps log scale is often used for the x axis

35 Runtime distributions in AIspace
Look at some algorithms and their runtime distribution in AIspace: Greedy Descent Random Sampling Random Walk Greedy Descent with random walk Simple scheduling problem 2 in AIspace: Select Batch Run in the top menu to see runtime distributions of each algorithm on this problem - You can change number of runs per batch, as well as length of each run

36 Runtime distributions in AIspace
Let’s look at runtime distributions: Greedy Descent Random Sampling Random Walk Greedy Descent with random walk Simple scheduling problem 2 in AIspace: here is a sample set of runtime distributions Select Batch Run in the top menu to see runtime distributions of each algorithm on this problem You can change number of runs per batch, as well as length of each run Greedy descent with random restart Random restart Random walk Greedy descent

37 Lecture Overview Recap of Lecture 10 SLS algorithms
Comparing SLS algorithms SLS variants Planning Intro (time permitting)

38 Simulated Annealing Key idea: Change the degree of randomness….
Annealing: a metallurgical process where metals are hardened by being slowly cooled. Analogy: start with a high “temperature'‘, i.e., a high tendency to take random steps Over time, cool down: more likely to follow the scoring function Temperature reduces over time, according to an annealing schedule

39 Simulated Annealing: algorithm
Here's how it works You are at a node n. Pick a variable at random and a new value at random. You generate n' If it is an improvement i.e., (A or B?) adopt it. A. h(n) – h(n’)> 0 B. h(n) – h(n’)< 0

40 Simulated Annealing: algorithm
Here's how it works You are at a node n. Pick a variable at random and a new value at random. You generate n' If it is an improvement i.e., h(n) – h(n’) , adopt it. If it isn't an improvement, adopt it probabilistically depending on the difference h(n) – h(n’) and a temperature parameter, T. move to n' with probability

41 Simulated Annealing: algorithm
if there is no improvement, move to n' with probability The higher T, the higher the probability of selecting a non improving node for the same h(n) – h(n’) The higher |h(n) – h(n’)|, the more negative The lower the probability of selecting a non improving node for the same T Difference between n’ and n h(n)-h(n’)

42 Properties of simulated annealing search
If T decreases slowly enough, then simulated annealing search will find a global optimum with probability approaching 1 But “slowly enough” usually means longer than the time required by an exhaustive search of the assignment space  Finding a good annealing schedule is “an art” and very much problem dependent Widely used in VLSI layout, airline scheduling, etc.

43 Tabu Search Mark partial assignments as tabu (taboo)
Prevents repeatedly visiting the same (or similar) local minima Maintain a queue of k variable/value pairs that are taboo E.g., when changing a variable V’s value from 2 to 4, we cannot change it back to 2 for the next k steps k is a parameter that needs to be optimized empirically

44 Population Based SLS Often we have more memory than the one required for maintaining just current node (e.g., best so far + tabu list) Key Idea: maintain a population of k individuals At every stage, update your population. Whenever one individual is a solution, report it. E.g., stochastic Bean Search, Genetic Algorithms Not required for this course but you can see how they work in Ch. 4.9 if interested

45 SLS for Constraint Optimization Problems
Constraint Satisfaction Problems Hard constraints: need to satisfy all of them All models are equally good Constraint Optimization Problems Soft constraints: need to satisfy them as well as possible Can have weighted constraints Minimize h(n) = sum of weights of constraints unsatisfied in n Hard constraints have a very large weight Some soft constraints can be more important than other soft constraints  larger weight All local search methods discussed work just as well for constraint optimization all they need is an evaluation function h

46 Example for constraint optimization problem
Exam scheduling Hard constraints: Cannot have an exam in too small a room Cannot have multiple exams in the same room in the same time slot Soft constraints Student should not have to write two exams back to back (important) Students should not have multiple exams on the same day It would be nice if students had their exams spread out

47 SLS limitations Typically no guarantee to find a solution even if one exists SLS algorithms can sometimes stagnate Get caught in one region of the search space and never terminate Very hard to analyze theoretically Not able to show that no solution exists SLS simply won’t terminate You don’t know whether the problem is infeasible or the algorithm has stagnated

48 SLS pros: anytime algorithms
When do you stop? When you know the solution found is optimal (e.g. no constraint violations) Or when you’re out of time: you have to act NOW Anytime algorithm: maintain the node with best h found so far (the “incumbent”) given more time, can improve its incumbent

49 SLS pros: dynamically changing problems
The problem may change over time Particularly important in scheduling E.g., schedule for airline: Thousands of flights and thousands of personnel assignments A storm can render the schedule infeasible Goal: Repair the schedule with minimum number of changes Often easy for SLS starting from the current schedule Other techniques usually: Require more time Might find solution requiring many more changes

50 Successful application of SLS
Scheduling of Hubble Space Telescope : reduced time to schedule 3 weeks of observations: from one week to around 10 sec. Generate feasible schedule that are not too suboptimal Soft constraints e.g., Minimize light from moon / sun SPIKE treats schedule construction as a constrained optimization problem and uses a heuristic repair-based scheduling search technique called multistart stochastic repair. This technique consists of the following steps: 1. Trial assignment: make a trial assignment (“initial guess”) of activities to times, based on heuristics to be discussed further below. Such a schedule will generally have temporal or other constraint violations, as well as resource capacity overloads; 2. Repair: apply heuristic repair techniques to try to eliminate constraint violations, until either a pre-established level of effort has been expended or there are no conflicts left; 3. Deconflict: eliminate conflicts by removing any activities with constraint violations, or by relaxing constraints, until a feasible schedule remains.

51 Example: SLS for RNA secondary structure design
RNA strand made up of four bases: cytosine (C), guanine (G), adenine (A), and uracil (U) Which 2D/3D structure an RNA strand folds into is important for its function Predicting structure for a strand is “easy”: O(n3) But what if we want a strand that folds into a certain structure? Local search over strands Search for one that folds into the right structure Evaluation function for a strand Run O(n3) prediction algorithm Evaluate how different the result is from our target structure RNA strand GUCCCAUAGGAUGUCCCAUAGGA Easy Hard Secondary structure Was Evaluation function for a strand - Run O(n3) prediction algorithm - Evaluate how different the result is from our target structure - Only defined implicitly, but can be evaluated by running the prediction algorithm One of best algorithm to date: Local search algorithm RNA-SSD developed at UBC [Andronescu, Fejes, Hutter, Condon, and Hoos, Journal of Molecular Biology, 2004]

52 Learning Goals for Local Search
Implement local search for a CSP. Implement different ways to generate neighbors Implement scoring functions to solve a CSP by local search through either greedy descent or hill-climbing. Implement SLS with random steps (1-step, 2-step versions) random restart Compare SLS algorithms with runtime distributions Explain functioning of Simulated Annealing


Download ppt "Lecture 11 SLS wrap up, Intro To Planning"

Similar presentations


Ads by Google