48
CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search : Tony Martinez, Eric Ringger, and some figures from Dasgupta This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License .

CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Embed Size (px)

Citation preview

Page 1: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

CS 312: Algorithm Analysis

Lecture #38: Approximation Algorithms and Local Search

Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et al.

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.

Page 2: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Announcements

Project #7: TSP Due: today by 5pm

Competition (“The Bake-Off”) - Required Big 3 problems in the “Competition” survey Also required: “Competition Test Set” survey

Submit only once to this survey

Any results submitted by Monday morning (early) will be considered

Open categories - Optional #1: parallel implementations #2: B&B without time bounds #3: non B&B

Hall of Fame (Bake-Off results) presented next Monday

Page 3: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Objectives

Understand the idea of an approximation algorithm

Understand local search and its variants, esp. with regard to solving the TSP

Page 4: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

NP-Complete

Recall our Definition: A decision problem is NP-complete iff

For all ,

Can you use this definition directly to prove that a problem is in NP-Complete?

Why not?

Page 5: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Proving a Problem is NP-Complete

Let be an NP-Complete problem e.g., 3CNF SAT

Consider a decision problem in NP such that Then?

Page 6: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Proving a Problem is NP-Complete

Let be an NP-Complete problem e.g., 3CNF SAT

Consider a decision problem in NP such that

Page 7: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Proving a Problem is NP-Complete

Let be an NP-Complete problem e.g., 3CNF SAT

Consider a decision problem in NP such that

Thus, is also NP-Complete

Then our strategy to prove is NP-Complete: 1. Show that is in NP

Easy 2. Show that a known NP-Complete problem can be reduced to !

More fun!

Page 8: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Hard Problems

What can we do if we have found a hard problem?

Page 9: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Options

Brute force: Enumerate all and check or score

State-space search: Back-tracking Branch & Bounc – for optimization

Approximation algorithms: , where is an optimal solution and is an approximate solution produced

by the algorithm Solution-space search for optimization:

Local search Local search + random restarts Deterministic annealing Simulated annealing Genetic algorithms (LS + fittness & cross-over)

Page 10: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Local Search

Page 11: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

TSP: 2-change

Page 12: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Local Optimality

Page 13: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

3-change

Page 14: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Local Search with 3-change

Page 15: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et
Page 16: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Local Search Landscape

Page 17: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Local Search + Random Restarts

Page 18: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Simulated Annealing

Plus some logic to lower the temperature and detect convergence.

Page 19: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Simulated Annealing Landscape

Page 20: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Assignment

No more homework

Finish Project #7!

Hall of Fame on Monday

Prepare for Final Review on Monday Prepare your one page of notes More review in help session on Tuesday at 5pm

Page 21: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Extra Slides

Page 22: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Bounded Approximation Algorithms

Solve an NP-complete problem with a polynomial-time algorithm that is guaranteed to return a solution within some specific bound of the optimal solution: within a constant c of the optimal within log n of optimal, etc.

E.g., Section 5.4 shows an efficient greedy algorithm for Set Cover which is guaranteed to find a solution within ln(n) of optimal

Page 23: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Clustering Example

In clustering we want to find a natural way to group a set of instances into reasonable clusters A type of unsupervised learning Put similar instances into the same class

Distance function Euclidean distance is common, but others can be

used One variation is k-Cluster

User specifies the number of clusters k to be found Often better if k can be discovered automatically

Page 24: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

k-Cluster

Input: Points X = {x1, …, xn}, integer k Output: A partition of X into k clusters C1,…, Ck Goal: Minimize the diameter of the clusters

Clusters are spheres all with the same diameter d such that all points are enclosed in the spheres

1,

max max ( , ) for a b j

a b kj x x C

Diameter d x x C C

Page 25: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

CS 312 – Approximation

k-Cluster Approximation Algorithm

Choose k of the data points as cluster centers Choose first point arbitrarily Choose each succeeding center to be the point furthest from the centers chosen so far Assign all other data points to their closest cluster center

Page 26: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

CS 312 – Approximation

k-Cluster Approximation Factor Definitely clusters, but is max diameter within a factor of optimal? Let x be the point furthest from the k cluster centers (i.e. x would be the next center that would

have been chosen) Let r be the distance of x to the closest k Then, every point must be within r of its cluster center. Why? Thus the maximum diameter of any cluster is ≤ 2r We have k+1 points that are all at a distance at least r from each other Any partition into k clusters must include 2 of these points in the same cluster with diameter at

least r. (lower bound) Thus, the optimal diameter is between r and 2r inclusive and we have an approximation factor of

2

Page 27: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Approximation Algorithms

Does this mean we can calculate the optimum once we have our approximation? If so, we would have a solution in P and could show that

P=NP What can we say about the optimum in this type of case?

This gives us another way to deal with NP problems Seek polynomial time algorithms that are guaranteed to

have a solution within some factor of optimal This approach can be used for many NP problems

Page 28: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Local Search A powerful approach which can be used for any optimization problem From a current state try a small move to a neighboring state which improves

the overall objective function

Notion of neighborhood will differ depending on problem For TSP a closest neighbor solution state could be a path which differs by just

two edges (impossible to differ by just one) and a small move would be swapping those edges

TSP approach would be to swap edges if it shortens the path length and keep doing this until no swap leads to improvement

Page 29: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Local Search Example: Solving a Linear Program

Page 30: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Properties of Local Search Can be relatively simple and often one of the most effective algorithms

across many applications How long will it take?

Depends on the number of iterations which is not usually exactly predictable Since each iteration improves the objective function the algorithm works in a

constrained space of the problem, but the number of iterations can still be large Often finds a solution relatively efficiently

Local Optima The good news is the algorithm improves the objective value with each iteration

and stops as soon as it can no longer improve The bad news is this could be a local optimum which is not a very good solution Can local search be optimal?

Yes when solution is convex (no local optima) and neighborhood size is sufficiently small

Page 31: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Dealing with Local Optima

The amount of local optima will depend on the problem Some good news coming for many situations

Note that the search is highly effected by the initial state (usually chosen randomly), since the search will be tied to that initial neighborhood, and often stay close to that neighborhood

Would if an algorithm has a 50% chance of hitting a local optima for a certain problem

Page 32: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Dealing with Local Optima

The amount of local optima will depend on the problem Some good news coming for many situations

Note that the search is highly effected by the initial state (usually chosen randomly), since the search will be tied to that initial neighborhood, and often stay close to that neighborhood

Would if an algorithm has a 50% chance of hitting a local optima for a certain problem Just run it multiple times with different random start states If chance of hitting a true optima is p, then running the problem k

times gives probability 1-(1-p)k of finding an optimal solution Another approach is to add some randomness to the algorithm

and occasionally allow it to move to a neighbor which increases the objective, allowing it to potentially escape local optima

Page 33: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

33

Gradient Descent – Common Powerful Tool

Slightly change the state in the direction which maximizes the improvement in the objective function – steepest gradient

Usually done by taking the partial derivative of the objective function with respect to the adjustable variables/parameters

Then we just change the variables in the direction (step size – not too big) of the derivative/gradient which gives the best local change

Greedy Search We then recalculate the gradient at the new point and repeat until we have reached a minimum (optima)

Page 34: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Brief Inductive Learning Introduction

Gather a set of input-output examples from some application: Training Set

i.e. Speech Recognition, financial forecasting Train the learning model (Neural network, etc.) on

the training set until it solves it well The Goal is to generalize on novel data not yet

seen Gather a further set of input-output examples

from the same application: Test Set Use the learning system on novel data

Page 35: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Example Application - Heart Attack Diagnosis

The patient has a set of symptoms - Age, type of pain, heart rate, blood pressure, temperature, etc.

Given these symptoms in an Emergency Room setting, a doctor must diagnose whether a heart attack has occurred.

How do you train a machine learning model to solve this problem using the inductive learning model?

Consistent approach Knowledge of machine learning approach not critical Need to select a reasonable set of input features

Page 36: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Motivation

Costs and Errors in Programming Our inability to program "subjective"

problems General, easy-to use mechanism for a

large set of applications Improvement in application accuracy -

Empirical

Page 37: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

CS 312 – Approximation 37

Gradient Descent Learning

TSS:TotalSum SquaredError

0

Error Landscape

Weight Values

Page 38: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

CS 312 – Approximation

Local Minima and Neural Networks

Neural Network can get stuck in local minima for small networks, but for most large networks (many weights), local minima rarely occur in practice

This is because with so many dimensions of weights it is unlikely that we are in a minima in every dimension simultaneously – almost always a way down

Page 39: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Genetic Algorithms

For some optimization problems it is desirable to search the space more broadly and not just focus on a good solution based on an initial start state

Genetic/Evolutionary Algorithms work well in many of these situations

Does a more diverse/broad search of the search space than standard local search variations

Page 40: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

CS 312 – Approximation 40

Evolutionary Computation/AlgorithmsGenetic Algorithms

Simulate “natural” evolution of structures via selection and reproduction, based on performance (fitness)

Type of Heuristic Search to optimize any set of parameters

Genetic Operators - Recombination (Crossover) and Mutation are most common

1 1 0 2 3 1 0 2 2 1 (Fitness = 10) 2 2 0 1 1 3 1 1 0 0 (Fitness = 12) 2 2 0 1 3 1 0 2 2 1 (Fitness = f(2 2 0 1 3 1 0 2 2 1 ))

Page 41: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Evolutionary Algorithms

Start with initialized population P(t) - random, domain- knowledge, etc. Each just like an initial parameter setting in local search

Typically have fixed population size (like beam search), large enough to maintain diversity

Selection Parent_Selection P(t) - Promising Parents more likely to be chosen

based on fitness to create new children using genetic operators Survive P(t) - Pruning of less promising candidates, Evaluate P(t) -

Calculate fitness of population members. Could be simple metrics to complex simulations.

Survival of the fittest - Find and keep best while also maintaining diversity

Page 42: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Evolutionary Algorithm

Procedure EA

t = 0;

Initialize Population P(t);

Evaluate P(t);

Until Done{ /*Sufficiently “good” individuals discovered or many iterations passed with no improvement, etc.*/

t = t + 1;

Parent_Selection P(t);

Recombine P(t);

Mutate P(t);

Evaluate P(t);

Survive P(t);}

Page 43: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

EA Example

Goal: Discover a new automotive engine to maximize performance, reliability, and mileage while minimizing emissions

Features: CID (Cubic inch displacement), fuel system, # of valves, # of cylinders, presence of turbo-charging

Assume - Test unit which tests possible engines and returns integer measure of goodness

Start with population of random engines

Page 44: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

CS 312 – Approximation 44

Page 45: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Knapsack Example?

Page 46: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Parent/Survival Selection

In general want the fittest parents to be involved in creating the next generation

However, also need to maintain diversity and avoid crowding so that the entire space gets explored (local minima vs global minima)

Most common approach is Fitness Proportionate Selection (aka roulette wheel selection)

Everyone has a chance but the fittest are more likely

| |

1

( )Pr( )

( )

ii population

jj

Fitness hh

Fitness h

Page 47: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Genetic Operators

Crossover variations - multi-point, uniform, averaging, etc.

Mutation - Random changes in features, adaptive, different for each feature, etc.

Others - many schemes mimicking natural genetics: dominance, selective mating, inversion, reordering, speciation, knowledge-based, etc.

Page 48: CS 312: Algorithm Analysis Lecture #38: Approximation Algorithms and Local Search Credit: Tony Martinez, Eric Ringger, and some figures from Dasgupta et

Evolutionary Computation Comments

Much current work and extensions – More detail in 478 Numerous application attempts. Can plug into many algorithms

requiring search. Has built-in heuristic. Could augment with domain heuristics.

If no better way, can always try evolutionary algorithms, with pretty good results ("Lazy man’s solution" to any problem)

Many different options and combinations of approaches, parameters, etc.

More work needed regarding adaptivity of population size selection mechanisms operators representation