编程语言
首页 > 编程语言> > 群智能算法标准测试函数集

群智能算法标准测试函数集

作者:互联网

为了测试群智能算法的性能,我们整理了以下标准测试函数。

function [fobj, bound] = Optimizer(select)
    %% 目标函数
    switch select
        case 1
            fobj = @ Sphere;  % 效果很好  [-100, 100]
            bound = [-100, 100];
        case 2
            fobj = @ Ackley;  % 效果比较好 [-32, 32]
            bound = [-32.768, 32.768];
        case 3
            fobj = @ Rastrigin;  % 效果好 [-5.12, 5.12]
            bound = [-5.12, 5.12];
        case 4
            fobj = @ Alpine;  % 效果好 [-10,10]
            bound = [-10, 10];
        case 5
            fobj = @ Squares; % 效果好 [-10,10]
            bound = [-10, 10];
        case 6
            fobj = @ Griewank; % 效果好 [-600, 600]
            bound = [-600, 600];
        case 7
            fobj = @ Powell;  % 效果好  [-4, 5]
            bound = [-4, 5];
        case 8
            fobj = @ Zakharov; % 效果好 [-5, 10]
            bound = [-5, 10];
        case 9
            fobj = @ Sumpow;  % 效果好 [-1, 1]
            bound = [-1, 1];
        case 10
            fobj = @ Rothyp;  % 效果好 [-65, 65]
            bound = [-65, 65];
        case 11
            fobj = @ Schaffer; % [-100, 100]
            bound = [-100, 100];
    end

    function [y] = Sphere(xx)
        d = length(xx);
        sum = 0;
        for ii = 1:d
	        xi = xx(ii);
	        sum = sum + xi^2;
        end
        y = sum;
    end

    function [y] = Ackley(xx)
        d = length(xx);
        sum1 = 0;
        sum2 = 0;
        for ii = 1:d
	        xi = xx(ii);
	        sum1 = sum1 + xi^2;
	        sum2 = sum2 + cos(2*pi*xi);
        end
        term1 = -20*exp(-0.2*sqrt(sum1/d));
        term2 = -exp(sum2/d);
        
        y = term1 + term2 + 20 + exp(1);
    end

    function [y] = Rastrigin(xx)
        d = length(xx);
        sum = 0;
        for ii = 1:d
            xi = xx(ii);
            sum = sum + (xi^2 - 10*cos(2*pi*xi));
        end
    
        y = 10*d + sum;
    end

    function [y] = Alpine(xx)
        d = length(xx);
        sum = 0; 
        for i=1:d
           sum = sum + abs(xx(i)*sin(xx(i))+0.1*xx(i)); 
        end
        y = sum;
    end

    function [y] = Squares(xx)
        d = length(xx);
        sum = 0;
        for i = 1:d
            xi = xx(i);
            sum = sum + i*xi^2;
        end
        y = sum;
    end

    function [y] = Griewank(xx)
        d = length(xx);
        sum = 0;
        prod = 1;
        
        for ii = 1:d
	        xi = xx(ii);
	        sum = sum + xi^2/4000;
	        prod = prod * cos(xi/sqrt(ii));
        end
        
        y = sum - prod + 1;
    end

    function [y] = Powell(xx)
        d = length(xx);
        sum = 0;
        
        for ii = 1:(d/4)
	        term1 = (xx(4*ii-3) + 10*xx(4*ii-2))^2;
	        term2 = 5 * (xx(4*ii-1) - xx(4*ii))^2;
	        term3 = (xx(4*ii-2) - 2*xx(4*ii-1))^4;
	        term4 = 10 * (xx(4*ii-3) - xx(4*ii))^4;
	        sum = sum + term1 + term2 + term3 + term4;
        end
        
        y = sum;
    end

    function [y] = Zakharov(xx)
        d = length(xx);
        sum1 = 0;
        sum2 = 0;

        for ii = 1:d
            xi = xx(ii);
            sum1 = sum1 + xi^2;
            sum2 = sum2 + 0.5*ii*xi;
        end
    
        y = sum1 + sum2^2 + sum2^4;
    end

    function [y] = Sumpow(xx)
        d = length(xx);
        sum = 0;
        for ii = 1:d
            xi = xx(ii);
            new = (abs(xi))^(ii+1);
            sum = sum + new;
        end
    
        y = sum;
    end

    function [y] = Rothyp(xx)
        d = length(xx);
        outer = 0;
        
        for ii = 1:d
            inner = 0;
            for jj = 1:ii
                xj = xx(jj);
                inner = inner + xj^2;
            end
            outer = outer + inner;
        end
        
        y = outer;
    end

    function [y] = Schaffer(xx)
        x1 = xx(1);
        x2 = xx(2);
    
        fact1 = (sin(x1^2-x2^2))^2 - 0.5;
        fact2 = (1 + 0.001*(x1^2+x2^2))^2;
    
        y = 0.5 + fact1/fact2;
    end
end

标签:10,xi,end,sum,ii,标准,xx,测试函数,智能算法
来源: https://www.cnblogs.com/mysterygust/p/16213348.html