function [OP_Cost,GOP]=MTOA(Fcn_Name,Par_Interval,No_GTs,No_LTs,RM,Rm,Max_Itr,Beta,Lambda,Theta,Graphic_on) % initialization %=============================================================== [Dim,m]=size(Par_Interval); OP_Cost=zeros(1,Max_Itr); LP=zeros(Dim,No_GTs); LP_Cost=ones(1,No_GTs)*inf; GTs=rand(Dim,No_GTs).*repmat(Par_Interval(:,2)-Par_Interval(:,1),1,No_GTs)+repmat(Par_Interval(:,1),1,No_GTs); GTs_Cost=Ev_Fcn(GTs,Fcn_Name); [Gts_Sorted,RKs]=sort(GTs_Cost); GOP=GTs(:,RKs(1)); GOP_Cost=Gts_Sorted(1); nop=No_GTs; OP_Cost(1)=GOP_Cost; 把这段MATLAB代码转换为python代码
时间: 2023-08-06 09:25:36 浏览: 159
GoP.rar_GOP _Scalable Color _color descriptor_descriptor_scd
Here is the Python code equivalent of the given MATLAB code:
import numpy as np
def MTOA(Fcn_Name, Par_Interval, No_GTs, No_LTs, RM, Rm, Max_Itr, Beta, Lambda, Theta, Graphic_on):
# initialization
# ===============================================================
Dim, m = Par_Interval.shape
OP_Cost = np.zeros((1, Max_Itr))
LP = np.zeros((Dim, No_GTs))
LP_Cost = np.ones((1, No_GTs)) * np.inf
GTs = np.random.rand(Dim, No_GTs) * np.tile(Par_Interval[:, 1] - Par_Interval[:, 0], (No_GTs, 1)).T + np.tile(Par_Interval[:, 0], (No_GTs, 1)).T
GTs_Cost = Ev_Fcn(GTs, Fcn_Name)
Gts_Sorted, RKs = np.sort(GTs_Cost), np.argsort(GTs_Cost)
GOP, GOP_Cost, nop = GTs[:, RKs[0]], Gts_Sorted[0], No_GTs
OP_Cost[0] = GOP_Cost
# rest of the code goes here
阅读全文