Machine Learning for Software Engineering

Similar documents
Single Candidate Methods

Introduction to Design Optimization: Search Methods

Algorithm Design (4) Metaheuristics

Lecture 4. Convexity Robust cost functions Optimizing non-convex functions. 3B1B Optimization Michaelmas 2017 A. Zisserman

Local Search and Optimization Chapter 4. Mausam (Based on slides of Padhraic Smyth, Stuart Russell, Rao Kambhampati, Raj Rao, Dan Weld )

Local Search and Optimization Chapter 4. Mausam (Based on slides of Padhraic Smyth, Stuart Russell, Rao Kambhampati, Raj Rao, Dan Weld )

Local Search and Optimization Chapter 4. Mausam (Based on slides of Padhraic Smyth, Stuart Russell, Rao Kambhampati, Raj Rao, Dan Weld )

Non-deterministic Search techniques. Emma Hart

Machine Learning for Software Engineering

Algorithms & Complexity

Optimization Techniques for Design Space Exploration

INF Biologically inspired computing Lecture 1: Marsland chapter 9.1, Optimization and Search Jim Tørresen

n Informally: n How to form solutions n How to traverse the search space n Systematic: guarantee completeness

Artificial Intelligence

Artificial Intelligence

CMU-Q Lecture 8: Optimization I: Optimization for CSP Local Search. Teacher: Gianni A. Di Caro

CS 331: Artificial Intelligence Local Search 1. Tough real-world problems

GRASP. Greedy Randomized Adaptive. Search Procedure

Escaping Local Optima: Genetic Algorithm

Term Paper for EE 680 Computer Aided Design of Digital Systems I Timber Wolf Algorithm for Placement. Imran M. Rizvi John Antony K.

Heuristic Optimization Introduction and Simple Heuristics

Beyond Classical Search

3.6.2 Generating admissible heuristics from relaxed problems

An evolutionary annealing-simplex algorithm for global optimisation of water resource systems

Artificial Intelligence

Simulated Annealing. Slides based on lecture by Van Larhoven

Introduction to Artificial Intelligence 2 nd semester 2016/2017. Chapter 4: Beyond Classical Search

An Evolutionary Algorithm for Minimizing Multimodal Functions

Artificial Intelligence p.1/49. n-queens. Artificial Intelligence p.2/49. Initial state: the empty board or a board with n random

Heuristic Optimisation

Artificial Intelligence (Heuristic Search)

Artificial Intelligence

Essentials of Metaheuristics

Evolutionary Computation Algorithms for Cryptanalysis: A Study

Random Search Report An objective look at random search performance for 4 problem sets

Introduction to optimization methods and line search

Predicting Diabetes using Neural Networks and Randomized Optimization

BEYOND CLASSICAL SEARCH

SIMULATED ANNEALING TECHNIQUES AND OVERVIEW. Daniel Kitchener Young Scholars Program Florida State University Tallahassee, Florida, USA

Today. Golden section, discussion of error Newton s method. Newton s method, steepest descent, conjugate gradient

Beyond Classical Search

Simple mechanisms for escaping from local optima:

Tuning. Philipp Koehn presented by Gaurav Kumar. 28 September 2017

Hill Climbing. Assume a heuristic value for each assignment of values to all variables. Maintain an assignment of a value to each variable.

Outline. Informed Search. Recall: Uninformed Search. An Idea. Heuristics Informed search techniques More on heuristics Iterative improvement

mywbut.com Informed Search Strategies-II

Lecture: Iterative Search Methods

N-Queens problem. Administrative. Local Search

Fall 09, Homework 5

Artificial Intelligence

CS:4420 Artificial Intelligence

REAL-CODED GENETIC ALGORITHMS CONSTRAINED OPTIMIZATION. Nedim TUTKUN

Simplex of Nelder & Mead Algorithm

10703 Deep Reinforcement Learning and Control

x n+1 = x n f(x n) f (x n ), (1)

Introduction to Stochastic Optimization Methods (meta-heuristics) Modern optimization methods 1

Recap Hill Climbing Randomized Algorithms SLS for CSPs. Local Search. CPSC 322 Lecture 12. January 30, 2006 Textbook 3.8

Artificial Intelligence Prof. Deepak Khemani Department of Computer Science and Engineering Indian Institute of Technology, Madras

TABU search and Iterated Local Search classical OR methods

Genetic Algorithms and Genetic Programming Lecture 7

Lecture 6: The Building Block Hypothesis. Genetic Algorithms and Genetic Programming Lecture 6. The Schema Theorem Reminder

A COMPARATIVE STUDY OF HEURISTIC OPTIMIZATION ALGORITHMS

Outline. TABU search and Iterated Local Search classical OR methods. Traveling Salesman Problem (TSP) 2-opt

Evolutionary Algorithms: Perfecting the Art of Good Enough. Liz Sander

March 19, Heuristics for Optimization. Outline. Problem formulation. Genetic algorithms

Administrative. Local Search!

Simulated annealing/metropolis and genetic optimization

Outline. Best-first search. Greedy best-first search A* search Heuristics Local search algorithms

Solving Problems: Intelligent Search

An Overview of Search Algorithms With a Focus in Simulated Annealing

Ar#ficial)Intelligence!!

Chapter 14 Global Search Algorithms

Theoretical Concepts of Machine Learning

Chapter Multidimensional Gradient Method

Global Optimization Simulated Annealing and Tabu Search. Doron Pearl

Introduction to Computer Science and Programming for Astronomers

Bayesian Methods in Vision: MAP Estimation, MRFs, Optimization

AI Programming CS S-08 Local Search / Genetic Algorithms

Local Search (Ch )

Beyond Classical Search: Local Search. CMPSCI 383 September 23, 2011

LECTURE NOTES Non-Linear Programming

IMPLEMENTATION OF A FIXING STRATEGY AND PARALLELIZATION IN A RECENT GLOBAL OPTIMIZATION METHOD

Hardware-Software Codesign

Interactive segmentation, Combinatorial optimization. Filip Malmberg

Introduction to Design Optimization: Search Methods

Classical Gradient Methods

4 INFORMED SEARCH AND EXPLORATION. 4.1 Heuristic Search Strategies

Artificial Intelligence Methods (G52AIM)

Exploration vs. Exploitation in Differential Evolution

Ellipsoid Algorithm :Algorithms in the Real World. Ellipsoid Algorithm. Reduction from general case

ARTIFICIAL INTELLIGENCE. Informed search

CHAPTER 2 CONVENTIONAL AND NON-CONVENTIONAL TECHNIQUES TO SOLVE ORPD PROBLEM

CHAPTER 6 ORTHOGONAL PARTICLE SWARM OPTIMIZATION

Introduction (7.1) Genetic Algorithms (GA) (7.2) Simulated Annealing (SA) (7.3) Random Search (7.4) Downhill Simplex Search (DSS) (7.

TDDC17. Intuitions behind heuristic search. Recall Uniform-Cost Search. Best-First Search. f(n) =... + h(n) g(n) = cost of path from root node to n

Data Mining Chapter 8: Search and Optimization Methods Fall 2011 Ming Li Department of Computer Science and Technology Nanjing University

25. NLP algorithms. ˆ Overview. ˆ Local methods. ˆ Constrained optimization. ˆ Global methods. ˆ Black-box methods.

Hybrid Particle Swarm-Based-Simulated Annealing Optimization Techniques

(Refer Slide Time: 02:59)

Transcription:

Machine Learning for Software Engineering Single-State Meta-Heuristics Prof. Dr.-Ing. Norbert Siegmund Intelligent Software Systems 1

2 Recap: Goal is to Find the Optimum Challenges of general optimization problems (not combinatorial for the moment): Search space is too big Too many solutions to compute Even good heuristics for a systematic search are too costly in terms of performance and memory consumption Note that we consider combinatorial optimization problems in later lectures based on the optimization approaches we learn next But, how to do optimization in a good-case scenario?

3 Gradient-based Optimization Given a cost function f(x), we can find the optimum via gradient ascent as long as we can compute the first derivative f (x) Idea: Compute the slope at any given x and move up x x + α f (x) With: α is a very small positive number controlling the extent of the change Generalization with Ԧx as the input vector: Ԧx Ԧx + α f( Ԧx) The gradient is a vector containing the derivative of each element of that dimension

Algorithm and Problems Ԧx random initial vector repeat Ԧx Ԧx + α f Ԧx until Ԧx is optimum or out of time return Ԧx When do we know Ԧx is the optimum? Slope is 0 Be ware of saddle points and minima! What is the convergence time? Tuning α for convergence and against overshooting What else can we do? Newton s Method: Directly compute extreme points with f (x) Machine Learning for Software Engineering Prof. Dr.-Ing. Norbert Siegmund 4

5 One-dimensional case: Newton s Method I Dampens α as we get closer to zero slope But, heads to any kind of zero slope (minima, maxima, saddle) Multi-dimensional version of the f (x) is more complex: Called: Hessian H f Ԧx = Ԧx Ԧx α f Ԧx f Ԧx δ δf δ δf δx 1 δx 1 δx 1 δx n δ δf δ δf δx n δx 1 δx n δx n Partial second derivative along each dimension

6 Newton s Method II Ԧx random initial vector repeat Ԧx Ԧx α H f Ԧx 1 f Ԧx until Ԧx is optimum or out of time return Ԧx Converges faster than regular gradient ascent Problems: Caught in local optima, but goal is global optima Local optimization algorithm!

Toward Global Optimization Two options: increase α or repeat gradient ascent in a loop and always start from a different random position Ԧx random initial vector Ԧx Ԧx repeat repeat Ԧx Ԧx + α f Ԧx until f Ԧx = 0 if f Ԧx > f Ԧx then Ԧx Ԧx Ԧx random vector until out of time return Ԧx Finds local optimum Finds the best local optimum, which is hopefully the global optimum Problem: f Ԧx = 0 might never be exactly 0, so use a threshold: ε < f Ԧx < ε Machine Learning for Software Engineering Prof. Dr.-Ing. Norbert Siegmund 7

8 Shortcomings of Gradient Ascent Assumptions: Ability to compute the first derivative Often, we even don t know the function (e.g., in black-box scenarios)! We only know how to create, modify, and test a solution Does not work for non-differentiable functions

9 Solution: Thoughtfull Random Probing Idea: Randomly select a starting point in the search space and search based on a given strategy for the optimal solution The given strategy represents the meta-heuristic This lecture: Know pros and cons of gradient-based optimization Learn about single-state meta-heuristics Local search Global search Hill climbing, simulated annealing, etc.

10 Heuristics Heuristic (greek: to find) involving or serving as an aid to learning, discovery, or problem-solving by experimental and especially trial-and-error methods Merriam-Webster dicitionary Why heuristics? NP-hard problems including decision variables with many interdependencies Nonlinear cost functions and constraints, even no mathematical functions (e.g., a cost function might be the execution of a program or asking an expert) So, near-optimal solution might be just good enough

11 Meta-Heuristic Algorithms employing some degree of randomness to find optimal solutions to hard problems Applied to: I know it when I see it problems In case when: You don t know beforehand how the optimal solution looks like You don t know how to find the optimal solution The search space is too large and there is no domain heuristic You can quantify the quality of a solution when you see it Two extremes: Random search Hill climbing

12 Assumptions of Meta-Heuristic Optimization We need to be able to do four steps: Initialization procedure: Provide one or more initial candidate solutions Assessment procedure: Assess the quality of a candidate solution Make a copy of a candidate solution Modification procedure: Tweak a candidate solution to produce a randomly slightly different candidate solution A selection procedure decides, which candidate solution to retain

13 Hill Climbing (Local Search) Idea: Use only your local solution and evaluate your neighbors to find a better one Repeat this step until no better neighbor exists Similar to gradient ascent, but does not compute gradient Pros: Requires few resources (current state and neighbors) Finds local optimum (global is possible) Useful if the search space is huge (even unlimited)

14 Hill-Climbing Algorithm S random initial solution repeat R Tweak(Copy(S )) if Quality(R ) > Quality(S ) then S R until S is optimum or out of time return S Initialization procedure Modification procedure Assessment and selection procedure Observations: Hill climbing is more general than gradient ascent Tweak operation must rely on a stochastic/random process to find better candidate solutions Strongly depends on good initialization

15 Variant: Steepest Ascent Hill Climbing Idea: Be more aggressive and parallelize by creating n tweaks to a candidate solution (like sampling the gradient) n number of tweaks S random initial solution repeat R Tweak(Copy(S )) for n -1 times do W Tweak(Copy(S )) if (Quality(W ) > Quality(R ) then R W if (Quality(R ) > Quality(S ) then S R until S is optimum or out of time return S With replacement: n number of tweaks S random initial solution Best S repeat R Tweak(Copy(S )) for n -1 times do W Tweak(Copy(S )) if (Quality(W ) > Quality(R ) then R W S R if (Quality(S ) > Quality(Best ) then Best S until Best is optimum or out of time return Best

16 Problems with Hill Climbing Local optimum: usually won t find global optimum Plateaus: algorithm gets stuck

17 How to Realize the Operations? Find a suitable representation of a candidate solution Vector of numbers, list or set of objects, a tree, a graph, etc. Representation must allow for implementing the operations for Initialization, Tweak, Copy, and Quality Example: fixed-length vector of real numbers as candidate solution Initialization operation: min minimum desired vector element value max maximum desired vector element value Ԧx a new vector xۦ 1,, x l for i from 1 to l do x i random number taken uniformly between min and max return Ԧx

How to Realize the Operations? (Cont.) Idea of Tweak operation: Add random noise as small value to each number in the vector But only for a given probability (often, we set p 1) Ԧx vector x 1,, x l to be convolved p probability of adding noise to an element in the vector r half range of uniform noise min minimum desired vector element value max maximum desired vector element value for i from 1 to l do if p random number chosen uniformly from 0.0 to 1.0 then repeat n random number chosen uniformly from r to r inclusive until min x i + n max x i x i + n return Ԧx Machine Learning for Software Engineering Prof. Dr.-Ing. Norbert Siegmund 18

Exploration vs. Exploitation Exploration: Explore the search space and avoid being trapped in a local maximum (very fast to find a locally good solution) Exploitation: Exploiting local information to reliably move to (local) maximum (very important if the search space has many local optima) How to balance or even manipulate both aspects? Parameter r allows as to tweak exploration vs. exploitation Small r will fully exploit the locality to reach the local optimum Large r will result in bounces through the search space (random search in the extreme case) Machine Learning for Software Engineering Prof. Dr.-Ing. Norbert Siegmund 19

20 Single-State Global Optimization Algorithms

21 About Global Optimization An algorithm is guaranteed to find the global optimum, at least in theory Often requires running the algorithm an infinite amount of time Realized by having a chance to visit every possible solution in the solution space Why are the aforementioned approaches not global? Tweak operation is bounded so that it stays in a local area

Global Machine Learning for Software Engineering Prof. Dr.-Ing. Norbert Siegmund 22 Random Search Concept: full explorative and no exploitation Idea: Randomly select a candidate solution Best random initial candidate solution repeat S a random candidate solution if Quality S > Quality Best then Best S until Best is optimum or out of time return Best Random Search Exploration Hill Climbing with random restarts (global) Hill Climbing with small r Exploitation Local

Hill Climbing with Random Restarts Idea: Do Hill Climbing for some time and then start all over again from a different initial candidate solution T distribution of possible time intervals S random initial candidate solution Best S repeat time random time in the near future, chosen from T repeat S Tweak Copy S if Quality R > Quality S then S R until S is optimum or time is up or out of time if Quality S > Quality Best then Best S S some random candidate solution until Best is optimum or out of time return Best Machine Learning for Software Engineering Prof. Dr.-Ing. Norbert Siegmund 23

25 Best Practices I Adjust the modification procedure Tweak makes large, random changes Global, because if long running, randomness will cause Tweak to try every solution The more large, random changes, the more exploration Adjust the selection procedure Change the algorithm so that you go downhills at least some time Global, because if long running, you ll go down enough hills so that you can go up again at the global optimum hill The more often going down hills, the more exploration

26 Best Practices II Jump to something new Start from a new location every once in a while Global, because if trying enough new locations, the optimum hill will be visited The more frequent restarts, the more exploration Use a large sample Try many candidate solutions in parallel Global, because if enough parallel candidate solutions, one of them will be the optimum hill More parallel candidate solutions, the more exploration Currently: Single state optimization -> very small sample

Machine Learning for Software Engineering Single-State Meta-Heuristics Prof. Dr.-Ing. Norbert Siegmund Intelligent Software Systems 27

28 Recap What are heuristics and why do we need meta-heuristics for finding optimal solutions to a problem? Standard approaches, such as gradient ascent do not work when function to be optimized is unknown Scaling issues arise if search space is too large We need heuristics that tell us how to search in an unknown search space What is the difference between exploration and exploitation? Exploration aims at finding the global optimum by making random jumps throughout the whole search space Exploitation aims at finding a local optimum (might be the global optimum) in sampling the local gradient using neighbor solutions

29 Recap II What is the relationship between exploration and exploitation and local search and global search? What is a local and what is a global search algorithm? Local: Hill climbing Global: Random search / walk How do they work? What are the essential parts? Initialization procedure, assessment procedure, modification procedure, and selection procedure

30 Adjusting Modification Procedure: (1+1), (1+λ), (1,λ) Goal: Tweak operation tending toward small tweaks with occasionally large tweaks and can potentially make any possibly change Idea: Use Gaussian/Normal distributions as noise overlaid to the numbers in the vector representing a candidate solution Most changes are close to zero, but some changes are huge This is called Gaussian Convolution

31 (1+1) = Hill Climbing + Gaussian Modification procedure: Convolution Ԧx vector x 1,, x l to be convolved p probability of adding noise to an element in the vector σ 2 variance of the Normal distribution min minimum desired vector element value max maximum desired vector element value for i from 1 to l do if p random number chosen uniformly from 0.0 to 1.0 then repeat n random number chosen from the Normal distribution N (0, σ 2 ) until min x i + n max x i x i + n return Ԧx

Continued (1+λ) = Steepest Ascent Hill Climbing + Gaussian Convolution (1,λ) = Steepest Ascent Hill Climbing with Replacement + Gaussian Convolution Knobs we get via Gaussian Convolution: σ 2 adjusting exploration vs. exploitation Interacting with parameter n (number of parallel candidate solutions) of (1,λ) If σ 2 large, we have noisy candidate solutions and look into many different solutions If n is high simultaneously, the algorithm wipes out the poor candidates of such solutions aggressively In this case, n is pushing toward exploitation whereas σ 2 toward exploration Machine Learning for Software Engineering Prof. Dr.-Ing. Norbert Siegmund 32

33 Simulated Annealing

Origin of Simulated Annealing (SA) SA is a probabilistic technique for approximating a global optimum Origin: Name and inspiration come from annealing in metallurgy, a technique involving heating and controlled cooling of a material to increase the size of its crystals and reduce their defects For obtaining low energy states of a solid metal Approach: Temperature of a solid metal is increased till it melts Metal is cooled until its crystals are rearranged Physical properties have changed Machine Learning for Software Engineering Prof. Dr.-Ing. Norbert Siegmund 34

35 What is Simulated Annealing? Simulation of the annealing process Solution to a combinatorial problem ~ states in a physical system Cost of a solution ~ energy of a state Difference to Hill Climbing in its decision on when to replace S (original candidate solution) with R (newly tweaked one) Avoid local optima by jumping randomly to a new state Decrease the probability of jumping to a new state over time By Kingpin13 - Own work, CC0, https://commons.wikimedia.org /w/index.php?curid=25010763

36 When to Replace a Candidate Solution? Three rules: If a neighbor solution is better, always switch If not, check the following: How much worse are the neighboring solutions? How high is the temperature of our system? If the temperature is high -> more likely to switch to a worse solution Probability of switching the state: P = e (currentenergy neighborenergy ) temperature Switch: P > random number chosen uniformly 0.0 to 1.0

Transferred to our Problem Probability of switch is a function Where t 0 P t, R, S = e t temperature with an initial high number S random initial solution Best S repeat R Tweak(Copy(S )) Quality R Quality(S) t if (Quality(R ) > Quality(S ) or if random nb btw. 0 to 1 < e S R Decrease t if (Quality(S ) > Quality(Best ) then Best S until Best is optimum or out of time or t 0 return Best Machine Learning for Software Engineering Prof. Dr.-Ing. Norbert Siegmund Fraction is negative, because R is worse than S If Quality R << Quality(S) or if t close to 0 -> P goes to 0 Quality R Quality(S) t then 37

38 Parameters What is a good starting temperature and how to reduce it? Should be as big as biggest distance Keeping t a long time high, we do more exploration Reduce with: t new = αt current with α < 1 Shall I reduce the neighborhood to avoid jumping to heavily around? Yes! See Adaptive Simulated Annealing In general: Experience & Experimentation All values are problem dependent and there is no silver bullet

39 Adaptive Simulated Annealing (ASA) Algorithm controls temperature schedule and random step selection based on the algorithm s progress Idea: temperature is not reduced if there is little progress on the quality Many sophisticated adaptations possible

40 Tabu Search Idea: Keep a list (the tabu list L) of already visited candidate solutions and refuse to visit them again until some time has gone In essence, we wander up hill, do not stay there (as this is not prohibited) and wander down the other side of the hill List is implemented as priority queue (if maximum capacity of L is reach, the oldest element will be removed) Realized by adapting Steepest Ascent with Replacement

Tabu Search Algorithm l Destired maximum tabu list length n number oftweaks desired to sample the gradient S random initial solution Best S L a tabu list of maximum length l repeat if Length L > l then Remove oldest element from L R Tweak(Copy(S )) for n -1 times do W Tweak(Copy(S )) if W L and (Quality(W ) > Quality(R ) or R L) then R W if R L and Quality(R ) > Quality(S ) then S R Enqueue R into L if (Quality(S ) > Quality(Best ) then Best S until Best is optimum or out of time return Best Machine Learning for Software Engineering Prof. Dr.-Ing. Norbert Siegmund 41

42 Limitations Works only in discrete spaces If applied to real-valued spaces, we need to refuse similar solutions that are already in the tabu list When search space has many dimensions, it still will stay at the same hill (easy to find a nonvisited neighbor) Instead of saving the candidate solutions, we might save the changes we have made to a candidate solution For ex. save deleting and adding edges in the TSP scenario Result: Feature-Based Tabu Search

Iterated Local Search (ILS) Improved version of Hill Climbing with Random Restarts Idea: Restart at a position where it likely finds a new local optimum Tries to search the space of local optima Approach: Find a local optimum, then searches for a nearby local optimum, and so on Heuristic: Find better local optimum in the neighborhood of your current local optimum (better than complete random) Restart positions not entirely random, but random in a certain distance to a home base local optimum If a new local optimum has been found, decide whether it becomes the new home base Machine Learning for Software Engineering Prof. Dr.-Ing. Norbert Siegmund 43

44 ILS Algorithm T distribution of possible time intervals S random initial solution Best S H S (the current home base) repeat time random time in the near future chosen from T repeat R Tweak(Copy(S )) if (Quality(R ) > Quality(S ) then S R until S is optimum or time is up or out of time if (Quality(S ) > Quality(Best ) then Best S H NewHomeBase(H, S) S Perturb(H) until Best is optimum or out of time return Best Difficult to tune Decides whether to change the home base Make a large Tweak to search farther away from the home base

45 Take Home Message: Many approaches possible to tune the search between local optimization by exploiting the gradient of neighbor solutions and global optimization by exploring the whole configuration space using random jumps Which approach and how to balance exploration and exploitation is problem dependent Start with a good encoding of the problem and then try out some techniques and probably adjust some settings

46 Next Lecture & Literature Multi-State optimization algorithms (population methods) Evolution strategies Genetic algorithms Differential Evolution