人工智能中的局部搜索算法
??在局部搜索算法中,我們不再關(guān)心從初始節(jié)點(diǎn)到目標(biāo)節(jié)點(diǎn)之間的路徑,而是考慮從當(dāng)前節(jié)點(diǎn)出發(fā),移動(dòng)到它的鄰近狀態(tài),直到到達(dá)合理的目標(biāo)狀態(tài)。相比于前面所說的無信息搜索算法和有信息搜索算法,局部搜索算法往往能以常數(shù)的空間復(fù)雜度(不用保存路徑)在很大甚至無限的狀態(tài)空間中找到合理解。
爬山法
爬山法不斷向值增加的方向移動(dòng),直到到達(dá)頂峰。
function HillClimbing(problem) returns a local maximum statecurrent_state = initial_stateloop donext_state = the highest neighborif (next_state is higher than current_state)current_state = next_stateelsereturn current_state爬山法的問題在于它只能保證到達(dá)局部最大值,卻不能保證到達(dá)全局最大值。
比如我們從C點(diǎn)出發(fā),那么我們會(huì)停在局部最大值A(chǔ)點(diǎn),因此沒辦法到達(dá)全局最大值B點(diǎn)。
模擬退火算法
??模擬退火算法與爬山法類似,只是我們不再一味地往值增加的方向移動(dòng),而是以一定的幾率容許往值減小的方向移動(dòng),從而使得我們有可能從局部最大值A(chǔ)點(diǎn)走出來,并到達(dá)全局最大值B點(diǎn)。
??只所以叫做模擬退火,是因?yàn)橐婚_始這個(gè)幾率相對較高,而隨著時(shí)間的增加,這個(gè)幾率則像溫度一樣慢慢減小。
遺傳算法
??遺傳算法模擬生物中的遺傳過程,從初始種群開始,迭代進(jìn)行一系列雜交和變異直到獲得合適的種群,并從中挑選出最佳個(gè)體。
function GeneticAlgorithm(population, fitin) returns a solution stateinputs: population, a set of individualsfitness, a function that measures fitness of an individualrepeatnew_population = empty_setfor i = 1 to sizeof(population) dox = RandomSelect(population, fitness)y = RandomSelect(population, fitness)new_individual = Reproduce(x, y)if (a probability) thennew_individual = Mutate(new_individual)add new_individual to new_populationuntil some individuals are fit enough or time has elapsedreturn the best individual in the population ---------------------------------------------------------------- function Reproduce(x, y) returns a new individualinputs: x, y, the parents of the new individuallength = Length(x)mutation_point = RandomSelectIn(1, length)new_individual = Sub(x, 1, mutation_point)+ Sub(y, mutation_point, length)return new_individual轉(zhuǎn)載于:https://www.cnblogs.com/zhangyubao/p/7016968.html
總結(jié)
以上是生活随笔為你收集整理的人工智能中的局部搜索算法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Elasticsearch学习之快速入门
- 下一篇: 代码风格建议