Eleven, Powell algorithm (Powell algorithm) and the realization of the principle of

I. INTRODUCTION

  Powell algorithm is commonly used to accelerate image registration algorithm which can speed up the search, but also for the effect of low-dimensional function well, so this blog is mainly to introduce the principle of Powell algorithm and implementation.

  As the Internet has been explained to Powell algorithm, so I just put a link to put out (I feel there is not the ability to explain), all get to know.

  Here is the main place to save time you search. (All I worked so hard to search out ^ - ^).

Second, prior knowledge

  Learn one-dimensional search algorithm is: retreat method, elimination method, golden section

  Read the following blog: https://blog.csdn.net/shenziheng1/article/details/51088650

Third, Powell algorithm

  Read here specific principles:

  Reference blog: https://blog.csdn.net/shenziheng1/article/details/51028074

  Principles and Examples (an example of a calculation process): https://www.docin.com/p-956696217.html

Four, matlab code implementation to solve a simple function

  Source Code: http://blog.sina.com.cn/s/blog_743c53600100vhdn.html

  Program and ideas of this code is very simple, I think it was very well written.

  Original code in here:

  File: MyPowell.m 

function MyPowell()
syms x1 x2 x3 a;
f=10*(x1+x2-5)^4+(x1-x2+x3)^2 +(x2+x3)^6;
error=10^(-3);
D=eye(3);
x0=[0 0 0]'; 
for k=1:1:10^6
    MaxLength=0;x00=x0;m=0;
    if k==1,s=D;end
    for I = . 1 : . 3 
            X = X0 + A * S (:, I); 
            FF = SUBS (F, {X1, X2, X3}, {X ( . 1 ), X ( 2 ), X ( . 3 )}) ; 
            T = Divide (FF, a);% calls segmentation interval retreat method 
            AA = OneDemensionslSearch (FF, a, T);% calls 0.618 for one-dimensional search 
            XX = X0 + AA * S (:, I); 
            FX0 = SUBS (F, {X1, X2, X3}, {X0 ( . 1 ), X0 ( 2 ), X0 ( . 3 )}); 
            fXX = SUBS (F, {X1, X2, X3}, {XX ( . 1 ), XX ( 2 ), XX (3)});
            length=fx0-fxx;
            if length>MaxLength,MaxLength=length;m=m+1;end
            x0=xx;
    end
    ss=x0-x00;
    ReflectX=2*x0-x00;
    f1=subs(f,{x1,x2,x3},{x00(1),x00(2),x00(3)});
    f2=subs(f,{x1,x2,x3},{x0(1),x0(2),x0(3)});
    f3=subs(f,{x1,x2,x3},{ReflectX(1),ReflectX(2),ReflectX(3)});
    if f3<f1&&(f1+f3-2*f2)*(f1-f2-MaxLength)^2<0.5*MaxLength*(f1-f3)^2
        x=x0+a*ss;
        ff=subs(f,{x1,x2,x3},{x(1),x(2),x(3)});
        t=Divide(ff,a);
        aa=OneDemensionslSearch(ff,a,t);
        x0=x0+aa*ss;
        for j=m:(3-1),s(:,j)=s(:,j+1);end
        s(:,3)=SS;
     the else 
        IF F2> F3, X0 = ReflectX; End 
    End 
   IF NORM (xOO-X0) <error, BREAK ; End 
        K; 
        X0; 
End 
OPX = X0; 
Val = SUBS (F, {X1, X2, X3}, {OPX ( . 1 ), OPX ( 2 ), OPX ( . 3 )}); 
DISP ( ' the most advantages: ' ); OPX '
 DISP ( ' optimized values: ' ); Val 
DISP ( ' iterations: ' ); K

  File Divide.m:

% Retreat Method
 % for a one-dimensional function in any section division function, so a "high - low - high" type 

function Output = Divide (F, X, m, n-) 

IF the nargin < . 4 , n-1E-= . 6 ; End 

IF the nargin < . 3 , m = 0 ; End 

STEP = n-; 

T0 = m; FT0 = SUBS (F, {X}, {T0}); 

T1 = T0 + STEP; FT1 = SUBS (F, {X} , {T1}); 

IF FT0> = FT1 

    T2 = T1 + STEP; ft2 = SUBS (F, {X}, {T2}); 

    the while FT1> ft2 

        T0 = T1;

         % FT0 = FT1; 

        T1 = T2; FT1 =ft2;

        step=2*step;t2=t1+step;ft2=subs(f,{x},{t2});

    end

else 

    step=-step;

    t=t0;t0=t1;t1=t;ft=ft0;

    %ft0=ft1;

    ft1=ft;

    t2=t1+step;ft2=subs(f,{x},{t2});

    while ft1>ft2

        t0=t1;

        %ft0=ft1;

        t1=t2;ft1=ft2;

        step=2*step;t2=t1+step;ft2=subs(f,{x},{t2});

    end

end
output=[t0,t2];
View Code

  File: OneDemensionslSearch.m

% 0.618法
function output=OneDemensionslSearch(f,x,s,r)

if nargin<4,r=1e-6;end

a=s(1);b=s(2);

a1=a+0.382*(b-a);fa1=subs(f,{x},{a1});

a2=a+0.618*(b-a);fa2=subs(f,{x},{a2});

while abs((b-a)/b)>r && abs((fa2-fa1)/fa2)>r

  if fa1<fa2

     b=a2;a2=a1;fa2=fa1;a1=a+0.382*(b-a);fa1=subs(f,{x},{a1});

  else

     a=a1;a1=a2;fa1=fa2;a2=a+0.618*(b-a);fa2=subs(f,{x},{a2});

  end

end

op=(a+b)/2;

%fop=subs(f,{x},{op});

output=op;
View Code

  All into the same project directory, set to the current directory, and then enter Powell to run to get results.

  Thoughts and ideas Powell algorithm of this code is fully compliant, and very simple.

  

Guess you like

Origin www.cnblogs.com/fantianliang/p/12052264.html