how to reslove TypeError: 'float' object cannot be interpreted as an integer

how to reslove TypeError: 'float' object cannot be interpreted as an integer

我正在使用 smo 算法并收到一个错误,因为浮点对象不能被解释为整数..因为我是 python 的新手,我很困惑请帮我解决这个问题...

    class SMO():
        def __init__(self,regularization_nn,learning_rate_RBM,learning_rate_nn,n_iter_RBM,batch_size_RBM,batch_size_nn,n_iter_nn):
            self.learning_rate_RBM=0.006
            self.learning_rate_nn=0.1
            self.n_iter_RBM=20
            self.batch_size_RBM=100
            self.batch_size_nn=100
            self.n_iter_nn=5000
            self.PopSize=batch_size_RBM
            self.dim=n_iter_RBM
            self.acc_err=batch_size_nn
            self.lb=learning_rate_RBM
            self.ub=learning_rate_nn
            self.objf=regularization_nn
            self.pos=numpy.zeros((batch_size_RBM,n_iter_RBM))
            self.fun_val = numpy.zeros(batch_size_RBM)
            self.fitness = numpy.zeros(batch_size_RBM)
            self.gpoint = numpy.zeros((batch_size_RBM,2))
            self.prob=numpy.zeros(batch_size_RBM)
            self.LocalLimit=n_iter_RBM*batch_size_RBM;
            self.GlobalLimit=batch_size_RBM;
            self.fit = numpy.zeros(batch_size_RBM)
            self.MinCost=numpy.zeros(n_iter_nn)
            self.Bestpos=numpy.zeros(n_iter_RBM)
    
    
def initialize(self):
global GlobalMin, GlobalLeaderPosition, GlobalLimitCount, LocalMin, LocalLimitCount, LocalLeaderPosition
S_max=int(self.PopSize/2)
LocalMin = numpy.zeros(S_max)
LocalLeaderPosition=numpy.zeros((S_max,self.dim))
LocalLimitCount=numpy.zeros(S_max)
for i in range(self.PopSize):
    print(i)
    for j in range(self.dim):
        if type(self.ub)==int:
            self.pos[i,j]=random.random()*(self.ub-self.lb)+self.lb
        else:
            self.pos[i,j]=random.random()*(self.ub[j]-self.lb[j])+self.lb[j]

这是错误的回溯:

    ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-98-1b2f665e0321> in <module>()
      1 if __name__ == '__main__':
----> 2     chimp_optimizer(X,Y,X_train,X_test)

2 frames
<ipython-input-23-1b18b438af48> in chimp_optimizer(X, Y, X_train, Y_train)
     16     #print(fopt)
     17 
---> 18     x,succ_rate,mean_feval = main(Deep_belief_network,X,Y,regularization_nn,learning_rate_RBM,learning_rate_nn,n_iter_RBM,batch_size_RBM,batch_size_nn,n_iter_nn)
     19     return x,succ_rate,mean_feval

<ipython-input-97-906c6850e06b> in main(regularization_nn, learning_rate_RBM, learning_rate_nn, n_iter_RBM, batch_size_RBM, n_iter_nn, batch_size_nn, obj_val, succ_rate, mean_feval)
    252 
    253   # =========================== Calling: initialize() =========================== #
--> 254   smo.initialize()
    255 
    256   # ========================== Calling: GlobalLearning() ======================== #

<ipython-input-97-906c6850e06b> in initialize(self)
     51         S_max=int(self.PopSize/2)
     52         LocalMin = numpy.zeros(S_max)
---> 53         LocalLeaderPosition=numpy.zeros((int(S_max),self.dim))
     54         LocalLimitCount=numpy.zeros(S_max)
     55         for i in range(self.PopSize):

TypeError: 'float' object cannot be interpreted as an integer

我很困惑为什么会出现这个错误..请指导我我已经尝试像在 aslo 中那样更改值但它不起作用

应该是numpy.zeros( (int(batch_size_RBM), int(n_iter_RBM)) )