爬山对焦算法Matlab版

6,765次阅读
没有评论

共计 1462 个字符,预计需要花费 4 分钟才能阅读完成。

概念

爬山算法是一种局部择优的方法,采用启发式方法,是对深度优先搜索的一种改进,它利用反馈信息帮助生成解的决策。 属于人工智能算法的一种。

算法优缺点

优点
避免遍历,通过启发选择部分节点,从而达到提高效率的目的。
缺点
因为不是全面搜索,所以结果可能不是最佳。
爬山算法一般存在以下问题:
1)、局部最大:某个节点比周围任何一个邻居都高,但是它却不是整个问题的最高点。
2)、高地:也称为平顶,搜索一旦到达高地,就无法确定搜索最佳方向,会产生随机走动,使得搜索效率降低。
3)、山脊:搜索可能会在山脊的两面来回震荡,前进步伐很小。
function  result=findlocation(new_location,step,flag,new_method,is_reverse)

num=size(new_method,1);

tmp_init=new_location;
if step==0
    result=new_location;
    return ;
end
if is_reverse
    num=0;
    step=0-step;
end
if flag==0
    for i=tmp_init:step:num
        
        if new_method(i+step,1)-new_method(i,1)<=0
            if i-step<=0                 
             startnum=1;             
            else                 
             startnum=i-step;            
            end             
        if new_method(startnum,1)-new_method(i,1)>0
                is_reverse=1;
                flag=1;
                new_location=i-step;
                step=floor(step/2);
                if step==0
                    result=new_location;
                    return ;
                end
                
                result=findlocation(new_location,step,flag,new_method,is_reverse);
                return;
            else
                flag=1;
                new_location=i;
                step=floor(step/2);
                if step==0
                    result=new_location;
                    return ;
                end
                result=findlocation(new_location,step,flag,new_method,is_reverse);
                return;
                
            end
        else
            new_location=i+step;
        end
        
    end
    
end


if flag==1
    for i=tmp_init:step:num
        if new_method(i+step,1)-new_method(i,1)>0
            new_location=i+step;
        else
            flag=0;
            new_location=i;
            step=floor(step/2);
            if step==0
                result=new_location;
                return ;
            end
            result=findlocation(new_location,step,flag,new_method,is_reverse);
            return;
        end
        
    end
    
end


clc
clear all
close all
global new_location

load('new_method.mat');

num=size(new_method,1);
% two step for climb
init_location=10;
new_location=init_location;
step=20;
flag=1;
is_reverse=0;
result=findlocation(new_location,step,flag,new_method,is_reverse);
正文完
请博主喝杯咖啡吧!
post-qrcode
 
admin
版权声明:本站原创文章,由 admin 2015-11-10发表,共计1462字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码