680 likes | 961 Views
Local Search and Optimization. 2014.04.02 부산대학교 인공지능연구실 김민호 (karma@pusan.ac.kr). Outline. Local search techniques and optimization Hill-climbing Simulated annealing Genetic algorithms Issues with local search. Local search and optimization.
E N D
Local Search and Optimization 2014.04.02 부산대학교 인공지능연구실 김민호 (karma@pusan.ac.kr)
Outline • Local search techniques and optimization • Hill-climbing • Simulated annealing • Genetic algorithms • Issues with local search
Local search and optimization • Previously: systematic exploration of search space. • Path to goal is solution to problem • YET, for some problems path is irrelevant. • E.g 8-queens • Different algorithms can be used • Local search
Local search and optimization • Local search • Keep track of single current state • Move only to neighboring states • Ignore paths • Advantages: • Use very little memory • Can often find reasonable solutions in large or infinite (continuous) state spaces. • “Pure optimization” problems • All states have an objective function • Goal is to find state with max (or min) objective value • Does not quite fit into path-cost/goal-state formulation • Local search can do quite well on these problems.
Hill-climbing search function HILL-CLIMBING( problem) return a state that is a local maximum input:problem, a problem local variables: current, a node. neighbor, a node. current MAKE-NODE(INITIAL-STATE[problem]) loop do neighbor a highest valued successor of current if VALUE[neighbor] ≤ VALUE[current] then return STATE[current] current neighbor
5 8 3 1 6 4 7 2 4 8 1 4 7 6 5 2 3 1 3 5 2 8 5 7 5 6 3 8 4 7 6 3 1 8 1 7 6 4 5 1 3 8 4 7 6 2 2 2 Hill-climbing search start h = 0 goal h = -4 -2 -5 -5 h = -3 h = -1 -3 -4 h = -2 h = -3 -4 f (n) = -(number of tiles out of place)
Hill-climbing search • “a loop that continuously moves in the direction of increasing value” • terminates when a peak is reached • Aka greedy local search • Value can be either • Objective function value • Heuristic function value (minimized) • Hill climbing does not look ahead of the immediate neighbors of the current state. • Can randomly choose among the set of best successors, if multiple have the best value • Characterized as “trying to find the top of Mount Everest while in a thick fog”
When local maxima exist, hill climbing is suboptimal Simple (often effective) solution Multiple random restarts Hill climbing and local maxima
Hill-climbing example • 8-queens problem, complete-state formulation • All 8 queens on the board in some configuration • Successor function: • move a single queen to another square in the same column. • Example of a heuristic function h(n): • the number of pairs of queens that are attacking each other (directly or indirectly) • (so we want to minimize this)
Current state: h=17 Shown is the h-value for each possible successor in each column Hill-climbing example
A local minimum in the 8-queens state space (h=1) A local minimum for 8-queens
1 2 7 1 2 5 8 7 4 6 3 1 2 3 8 4 5 8 7 6 8 6 3 3 4 7 5 4 2 1 5 A local minimum for 8-puzzle f = -7 move up start goal f = 0 move right f = -6 f = -7 f = -(manhattan distance) 6
Ridge = sequence of local maxima difficult for greedy algorithms to navigate Plateau = an area of the state space where the evaluation function is flat. Other drawbacks
Possible solution…sideways moves • If no downhill (uphill) moves, allow sideways moves in hope that algorithm can escape • Need to place a limit on the possible number of sideways moves to avoid infinite loops • For 8-queens • Now allow sideways moves with a limit of 100 • Raises percentage of problem instances solved from 14 to 94% • However…. • 21 steps for every successful solution • 64 for each failure
Hill-climbing variations • Stochastic hill-climbing • Random selection among the uphill moves. • The selection probability can vary with the steepness of the uphill move. • First-choice hill-climbing • stochastic hill climbing by generating successors randomly until a better one is found • Useful when there are a very large number of successors • Random-restart hill-climbing • Tries to avoid getting stuck in local maxima.
Hill-climbing with random restarts • Different variations • For each restart: run until termination v. run for a fixed time • Run a fixed number of restarts or run indefinitely • Analysis • Say each search has probability p of success • E.g., for 8-queens, p = 0.14 with no sideways moves • Expected number of restarts? • Expected number of steps taken?
Search using Simulated Annealing • Simulated Annealing = hill-climbing with non-deterministic search • Basic ideas: • like hill-climbing identify the quality of the local improvements • instead of picking the best move, pick one randomly • say the change in objective function is d • if d is positive, then move to that state • otherwise: • move to this state with probability proportional to d • thus: worse moves (very large negative d) are executed less often • however, there is always a chance of escaping from local maxima • over time, make it less likely to accept locally bad moves • (Can also make the size of the move random as well, i.e., allow “large” steps in state space)
Physical Interpretation of Simulated Annealing • A Physical Analogy: • imagine letting a ball roll downhill on the function surface • this is like hill-climbing (for minimization) • now imagine shaking the surface, while the ball rolls, gradually reducing the amount of shaking • this is like simulated annealing • Annealing = physical process of cooling a liquid or metal until particles achieve a certain frozen crystal state • simulated annealing: • free variables are like particles • seek “low energy” (high quality) configuration • get this by slowly reducing temperature T, which particles move around randomly
Simulated annealing function SIMULATED-ANNEALING( problem, schedule) return a solution state input:problem, a problem schedule, 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] ifT = 0then returncurrent next a randomly selected successor of current ∆E VALUE[next] - VALUE[current] if∆E > 0 then current next elsecurrent next only with probability e∆E /T
More Details on Simulated Annealing • Lets say there are 3 moves available, with changes in the objective function of d1 = -0.1, d2 = 0.5, d3 = -5. (Let T = 1). • pick a move randomly: • if d2 is picked, move there. • if d1 or d3 are picked, probability of move = exp(d/T) • move 1: prob1 = exp(-0.1) = 0.9, • i.e., 90% of the time we will accept this move • move 3: prob3 = exp(-5) = 0.05 • i.e., 5% of the time we will accept this move • T = “temperature” parameter • high T => probability of “locally bad” move is higher • low T => probability of “locally bad” move is lower • typically, T is decreased as the algorithm runs longer • i.e., there is a “temperature schedule”
Simulated Annealing in Practice • method proposed in 1983 by IBM researchers for solving VLSI layout problems (Kirkpatrick et al, Science, 220:671-680, 1983). • theoretically will always find the global optimum (the best solution) • useful for some problems, but can be very slow • slowness comes about because T must be decreased very gradually to retain optimality • In practice how do we decide the rate at which to decrease T? (this is a practical problem with this method)
초기 토끼집단 • 느리고 영리하지 못한 토끼 진화된 토끼집단 • 빠르고 영리한 토끼 다윈의 진화론 • 다산 생존경쟁 변이 자연선택 진화 e.g.) 똑똑한 토끼가 살아 남는다?
History of Genetic Algorithm (1/3) • 1965년 Rechenberg(독일) • 진화전략(Evolutionary Strategy) 발표 • 단 두개의 해로 이루어진 해 집단 사용 • 교차 연산자 사용 안함 • 1966년 Fogel, Owens, Walsh • 진화 프로그램 제안 • 교차 연산이 없는 변이만을 사용
History of Genetic Algorithm (2/3) • Developed by John Holland in the early 70’s • 유전 알고리즘의 대부 • 해 집단에 근거, 교차와 변이를 포함한 GA의 골격 마련 • 1975년 역사적 저서 [Adaptation in Natural and Artificial Systems] 발표 • 1984년 산타페 연구소에 합류, 연구 방향을 [Complex System]에서 [Adaptive Complex System]으로 선회
History of Genetic Algorithm (3/3) • 1985년 제 1회 International Conference on Genetic Algorithms 개최 • 90년대 많은 주목을 받은 Artificial Life의 주된 도구로 활용됨 • 1997년 IEEE Transactions on Evolutionary Computing 개설
유전자 알고리즘 (GA: Genetic Algorithm) • 진화의 원리를 문제 풀이 또는 모의 실험에 이용하는 연구의 한 방법 • Solutions are encoded as chromosomes • Search proceeds through maintenance of a population of solutions • Reproduction favors “better” chromosomes • New chromosomes are generated during reproduction through processes of mutation and cross over, etc.
Genetic Algorithm • GA가 필요 없는 문제 • 잘 정의된 Algorithm이 존재하는 문제 • 최단 경로 탐색 문제, Sorting 등 • GA의 적용이 효과적인 문제 • Traveling salesman problem (TSP) • 함수 값을 최대화하는 변수 • NP Complete 문제
Basic Terminology in Biology • DNA, Chromosome : 염색체, 유전물질 • 유전자(gene) : 염색체 상의 각 인자 • 유전자형(genotype) : 유전자의 조합 • 표현형(phenotype) : 관찰되는 형질 • 생물학적 진화 • 개체는 교차에 의해 염색체를 부분 결합과 돌연변이에 의해 새로운 염색체를 가진 새로운 개체 생성 • 환경에 적응하기 유리한 개체만이 선택적으로 번성
Basic Terminology in GA • 염색체 (chromosome) : 임의의 solution • 해집단 (population) : 정해진 개수의 염색체 집단 • 유전자 (gene) : 염색체의 인자 하나 • 유전자 형 : 염색체 자체 • 표현형 : 유전자형에 대응하는 해의 모양
A B C D 1 1 1 1 0 0 1 1 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 1 1 0 1 1 population 1 0 0 1 1 selection 0 1 1 1 0 Fitness evaluation 1 0 0 1 1 0 1 1 1 0 유전자 알고리즘의 구조 cross over Search space mutation reproduction Substitution
유전자 알고리즘 function GENETIC-ALGORITHM(population, FITNESS-FN) returns an individual input: population, a set of individuals FITNESS-FN, a function that measures the fitness of an individual repeat parents SELECTION(population,FITNESS-FN) population REPRODUCTION(parents) until some individual is fit enough return the best individual in population, according to FITNESS-FN % REPRODUCTION = cross-over + mutation
유전자 알고리즘의 구성요소 • 개체 표현 방법 (Encoding Scheme) • 문제의 해가 될 가능성이 있는 것의 유전자적 표현 방법 • 적합도 함수 (Fitness Function) • 유전자를 평가하는 함수 • Solution에 가까운 유전자일 수록 높게 평가 • 유전 연산자 (Genetic Operators) • 자손의 합성을 변화시키는 유전 연산자들 • 알고리즘 제어 파라미터 (Parameter Setting) • 유전자 알고리즘이 사용하는 여러 가지 매개변수의 값 • 개체 집단의 크기, 유전 연산자를 적용시키는 확률 등
개체 표현 방법 (Encoding Scheme) • 문제의 해가 될 가능성이 있는 것을 유전자로 표현하는 것 • 전형적인 표현 양식은 이진수 0과 1을 이용한 일차원적 표현 • 표현 양식이 결정된 후 이에 맞는 교차 연산자 및 변이 연산자 결정
스키마 (Schema) • 염색체에 들어 있는 패턴 • 1101에는 1***, *1**,…11**, 1*0*, …, 110*, *101, ..., 1101, ****의 16개 스키마가 포함됨 • * : don’t care symbol • 1 또는 0 : specific symbol • 유전 알고리즘이란 초기의 작은 스키마가 결합하여 점점 더 큰 스키마를 이루어가는 과정 • 마지막 return value는 하나의 거대한 스키마
1. 이진수 표현, k진수 표현 • Binary Encoding, n-ary Encoding • 010101100010101100001001 vs. 562409 • 이진수 표현할 경우 교차시 자름 선 위치가 많아져 추가 변이 효과 발생 • 교차의 다양성 제공 • k진수의 경우 의미 있는 스키마 보존 가능성 높음 • 교차의 다양성은 시뮬레이션으로 가능
2. Gray Coding • 0000, 0001, 0011, 0010, 0110, 0111, 0101, 0100, 1100, … • 2진수 표현의 한 변형 • 인접한 수는 단 한 비트만 차이가 나도록 하는 코드 체계 • 의미상으로 유사한 두 해가 문제 공간에서 가까이 위치하도록 만든 코드 체계 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111 1110 1010 1011 1001 1000
3. 순열 표현 (Permutation Encoding) • 1234, 1243, 1324, 1342, 1423, 1432, 2134, 2143, 2314, … • 순열을 유전자형으로 가짐 • 순서 기반형 표현 • Traveling salesman problem (TSP)
4. 실수 표현 (Value Encoding) • 독일의 진화 전략 그룹 • 교차 연산자를 사용 안 함 • 이진연산자 사용 불필요, 실수 사용 • Bremermann이 교차 연산에 실수를 처음 사용 • 실수 하나를 하나의 유전자로 사용 • 크기의 개념을 연산자에 적용 가능 • 부모의 값을 평균하여 자식의 값에 적용시키는 산술 교차를 사용할 수 있음 • Finding weights for neural network
5. 가변 표현 • 대부분의 GA는 수행이 완료될 때까지 표현 방식을 바꾸지 않음 • 표현상의 비효율로 인한 한계 극복 불가능 • 표현 방식을 미리 고정하지 않고 알고리즘 수행 중 표현 방식을 변화하는 방법 고안 • 역치, 메시 유전 알고리즘, 유전 프로그래밍 • 유전자 재배열
A 1 B 5 D 3 J 2 6 E 8 D 4 I 7 B 1 1 0 0 1 1 1 1 1.2 5.3 0.4 2.3 5 3.1 06 7.2 e.g.) e.g.) e.g.) 개체 표현 방법 정리 • 여러가지 표현형태들 • Binary Encoding • Permutation Encoding • Value Encoding • 주로 0과 1의 Binary encoding을 많이 사용
0 0 1 1 1 0 1 1 0 0 1 0 1 0 0 0 0 1 0 1 적합도 염색체 64 361 169 576 적합도 함수 (Fitness Function) • 염색체의 해(solution)로서의 적합도를 평가 e.g.)
유전 연산자 유전 연산자 (Operators of GA) • 선택 연산자 (Selection) • 교차를 위해 해집단(population)에서 2개의 염색체를 선택 • 우수한 해에게 선택 가능성을 높게 해 준다 • 교차 연산자 (Crossover) • 선택된 두개의 parent로부터 하나의 offspring을 생성 • GA의 대표적 연산자 • 변이 연산자 (Mutation) • 해를 임의로 변환 • 대치 연산자 (Substitution) • 부모의 염색체를 생성된 염색체로 대치
선택 연산자 (1/2) • Roulette wheel selection • 각 염색체의 적합도에 비례하는 만큼 roulette의 영역을 할당한 다음, roulette을 돌려 화살표가 가리키는 영역의 염색체를 선택 • 적합도가 높은 것은 선택될 확률이 그만큼 많고 적합도가 낮을 것은 선택될 확률이 상대적으로 낮다 • Elitist preserving selection e.g.) Roulette Wheel
선택 연산자 (2/2) • Expected-value selection : 적합도에 대한 각 개체의 확률적인 재생 개체수를 구하여 선택 • Ranking selection : 적합도의 크기 순서에 따라 순위를 매기고 순위에 따라 확률을 결정
1 1 0 0 1 0 1 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 0 0 1 0 1 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 0 1 1 교배 연산자 (1/4) • 두 부모의 염색체를 부분적으로 바꾸어 자식의 염색체를 생성 • Single point crossover • Two point crossover
교배 연산자 (2/4) • Uniform crossover (균등 교차) • 자름 선을 이용하지 않음 • 스키마의 결합 형태가 다양 • 스키마 내의 특정 기호의 위치가 거의 영향을 미치지 않음 • 교란의 정도가 크므로 수렴 시간이 오래 걸림 Initialize threshold P0 ; for each gene in chromosome { generate random number t ; if (t < P0) copy the gene from S1 ; else copy the gene from S2 ; }
유전 연산자 교배 연산자 (3/4) • 균등 교차의 예 S1 : a b c d e f g h i j S2 : k l m n o p q r s t t : .83 .27 .33 .89 .91 .66 .44 .72 .42 .19 P0 = 0.6 O : a l m d e f q h s t
교배 연산자 (4/4) • Arithmetic crossover (산술적 교차) • 실수 표현(Value Encoding)일 경우 사용 가능 • 염색체의 각 위치에 대해 두 부모 염색체의 유전자의 평균값을 내어 자식 유전자로 삼는다. • 매우 빠른 수렴을 보이므로, 변이 등을 적절히 조절하여 설익은 수렴이 되지 않도록 주의하여야 한다. s1 : 1.98 3.31 20.43 12.01 -2.34 8.34 98.86 s2 : 11.28 2.21 12.39 1.44 2.45 3.55 87.44 offspring : 6.63 2.76 16.41 6.73 0.06 5.95 93.15
1 1 0 0 1 0 1 1 1 0 0 0 1 0 1 1 GA Search Method Hill-climbing Method 변이 연산자 (1/2) • 유전자를 일정한 확률로 변화시키는 조작 • 개체군의 다양성 유지 • 돌연변이가 없는 경우 초기 유전자 조합 이외의 공간을 탐색할 수 없어 초기 조합에 적절한 해가 없을 경우 원하는 해를 구할 수 없다. local optimum 방지 cf.