pythonnumpyclassmachine-learningsmo

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


im working with smo algorithm and received an error as float object cannot be interpreted as a integer.. since im new to python i got confused please help me with this...

    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]

this is the traceback of the error :

    ---------------------------------------------------------------------------
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

im confused why this error came ..please guide me i have tried to change the values as in aslo but its not working


Solution

  • It should be numpy.zeros( (int(batch_size_RBM), int(n_iter_RBM)) )