Pseudocode
Discrete Space Hill Climbing Algorithm currentNode = startNode; loop do L = NEIGHBORS(currentNode); nextEval = -INF; nextNode = NULL; for all x in L if (EVAL(x) > nextEval) nextNode = x; nextEval = EVAL(x); if nextEval <= EVAL(currentNode) //Return current node since no better neighbors exist return currentNode; currentNode = nextNode; Continuous Space Hill Climbing Algorithm currentPoint = initialPoint; // the zero-magnitude vector is common stepSize = initialStepSizes; // a vector of all 1's is common acceleration = someAcceleration; // a value such as 1.2 is common candidate = -acceleration; candidate = -1 / acceleration; candidate = 0; candidate = 1 / acceleration; candidate = acceleration; loop do before = EVAL(currentPoint); for each element i in currentPoint do best = -1; bestScore = -INF; for j from 0 to 4 // try each of 5 candidate locations currentPoint = currentPoint + stepSize * candidate; temp = EVAL(currentPoint); currentPoint = currentPoint - stepSize * candidate; if(temp > bestScore) bestScore = temp; best = j; if candidate is not 0 currentPoint = currentPoint + stepSize * candidate; stepSize = stepSize * candidate; // accelerate if (EVAL(currentPoint) - before) < epsilon return currentPoint;Contrast genetic algorithm; random optimization.
Read more about this topic: Hill Climbing
Related Phrases
Related Words