以下程序是采用WOA对混合核极限学习机参数进行优化，我现在想用PSO替代WOA进行优化，我该如何改写以下代码？% 定义寻优边界
%由于隐含层层数与核函数类型会影响寻优维度，所以下面我们分段进行寻优范围设置
xmin=[];xmax=[];
% 首先是各层节点数,范围是1-100，整数
xmin=[xmin ones(1,layers)];
xmax=[xmax 100*ones(1,layers)];
% 然后是ELM-AE的正则化系数与 hkelm的惩罚系数 与kernel1的权重系数
xmin=[xmin 1e-3 1e-3 0];
xmax=[xmax 1e3  1e3  1];
% 最后是hkelm的核参数
% 核参数设置  详情看kernel_matrix
if strcmp(kernel1,'RBF_kernel') && strcmp(kernel2,'RBF_kernel')
    xmin=[xmin 1e-3 1e-3 ];xmax=[xmax 1e3 1e3];%两个 RBF_kernel的 各一个核参数 范围都是1e-3到1e3
elseif strcmp(kernel1,'RBF_kernel') && strcmp(kernel2,'lin_kernel')
    xmin=[xmin 1e-3 ];xmax=[xmax 1e3];%线性核没有核参数
elseif strcmp(kernel1,'RBF_kernel') && strcmp(kernel2,'poly_kernel')
    xmin=[xmin 1e-3 1e-3 1 ];xmax=[xmax 1e3 1e3 10 ];%RBF_kernel一个核参数 而poly_kernel一共2个，第一个和rbf一样是1e-3到1e3。而第二个参数是幂指数，我们定义他的范围是1-10
elseif strcmp(kernel1,'RBF_kernel') && strcmp(kernel2,'wav_kernel')%
    xmin=[xmin 1e-3 1e-3 1e-3 1e-3 ];xmax=[xmax 1e3 1e3 1e3 1e3 ];%RBF_kernel一个核参数 wav_kernel有3个核参数
elseif strcmp(kernel1,'lin_kernel') && strcmp(kernel2,'lin_kernel')
    xmin=xmin;xmax=xmax;
elseif strcmp(kernel1,'lin_kernel') && strcmp(kernel2,'poly_kernel')
    xmin=[xmin 1e-3 1 ];xmax=[xmax 1e3 10];
elseif strcmp(kernel1,'lin_kernel') && strcmp(kernel2,'wav_kernel')
    xmin=[xmin 1e-3 1e-3 1e-3 ];xmax=[xmax 1e3 1e3 1e3 ];
elseif strcmp(kernel1,'poly_kernel') && strcmp(kernel2,'poly_kernel')
    xmin=[xmin 1e-3 1 1e-3 1 ];xmax=[xmax 1e3 10 1e3 10 ];
elseif strcmp(kernel1,'poly_kernel') && strcmp(kernel2,'wav_kernel')
    xmin=[xmin 1e-3 1 1e-3 1e-3 1e-3 ];xmax=[xmax 1e3 10 1e3 1e3 1e3 ];
elseif strcmp(kernel1,'wav_kernel') && strcmp(kernel2,'wav_kernel')
    xmin=[xmin 1e-3 1e-3 1e-3 1e-3 1e-3 1e-3 ];xmax=[xmax 1e3 1e3 1e3 1e3 1e3 1e3 ];
end
dim=length(xmin);
SearchAgents_no=6;%种群数量
Max_iter=50;%寻优代数

%% 初始化
Leader_pos=zeros(1,dim);
Leader_score=inf;

for i=1:SearchAgents_no%随机初始化速度,随机初始化位置
    for j=1:dim
       Positions( i, j ) = (xmax(j)-xmin(j))*rand+xmin(j);

    end
end

Convergence_curve=zeros(1,Max_iter);
%% 主循环
for t=1:Max_iter
    a=2-t*((2)/Max_iter);
    a2=-1+t*((-1)/Max_iter);
    lambda=3;
    mu=2;
    adapative_p= 1-(1/(lambda+mu)*(lambda*t^lambda+mu*mu^lambda)/(Max_iter^lambda));
    for i=1:size(Positions,1)
        r1=rand();
        r2=rand();
        A=2*a*r1-a;
        C=2*r2;
        b=1;
        l=(a2-1)*rand+1;
        p = rand();
        for j=1:size(Positions,2)
            if p<0.5
                if abs(A)>=1
                    rand_leader_index = floor(SearchAgents_no*rand()+1);
                    X_rand = Positions(rand_leader_index, :);
                    D_X_rand=abs(C*X_rand(j)-Positions(i,j));
                    Positions(i,j)=X_rand(j)-A*D_X_rand;
                elseif abs(A)<1
                    D_Leader=abs(C*Leader_pos(j)-Positions(i,j));
                    Positions(i,j)=Leader_pos(j)-A*D_Leader;
                end
            elseif p>=0.5
                distance2Leader=abs(Leader_pos(j)-Positions(i,j));
                Positions(i,j)=distance2Leader*exp(b.*l).*cos(l.*2*pi)+Leader_pos(j);
            end
        end
         Positions(i, : ) = Bounds( Positions(i, : ), xmin, xmax );%对超过边界的变量进行去除
        fit=fitness(Positions(i,:),p_train,t_train,p_test,t_test,layers,TF,kernel1,kernel2);
        %  更新
        if fit<Leader_score
            Leader_score=fit;
            Leader_pos=Positions(i,:);
        end
    end
    Convergence_curve(t)=1-Leader_score;
    process(t,:)=Leader_pos;