-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpattern_search.m
60 lines (51 loc) · 1.16 KB
/
pattern_search.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function [x,f_x,count]=pattern_search(x,dim,fobj)
%最后考察参数的具体赋值
count=0;
I=eye(dim); %生成dim阶的单位阵,方便后续单位向量的提取
delta=0.5;%初始步长
alpha=1e-10;%允许误差
a=0.5;%缩减率
b=1.2;%加速系数
j=1;
n=dim;
y=x;%初始点,应该是一个1乘以dim的行向量
%内循环为探测移动,外循环为模式移动
while delta>alpha
while j<=n
f1=fobj(y+delta*I(j,:));
count=count+1;
if f1<fobj(y)
y=y+delta*I(j,:);
j=j+1;
continue;
end
f2=fobj(y-delta*I(j,:));
count=count+1;
if f2<fobj(y)
y=y-delta*I(j,:);
j=j+1;
continue;
else
j=j+1;
end
end
f3=fobj(y);
count=count+1;
if f3<fobj(x)
x1=x;%x1相当于算法中的x_k
x=y;
y=x+b*(x-x1);
j=1;%之后进行探测移动
continue;%转步骤2
else %移动失败,缩小步长,继续移动
if delta<=alpha
break
else
delta=delta*a;
y=x;
j=1;
% continue;%转步骤2
end
end
end
f_x=fobj(x);