[docs]defstabilization_it(self,parts=None,nit=None,threshold=None):ifthreshold==None:threshold=max(max(self["velocity1"]))/100pass_info("No threshold in parameters, set to Vpart1max/100 = ",threshold)# One particleiftype(parts)==int:ifnitisNone:nit=self.nitforiinrange(nit-1,0,-1):ifnotself.is_stabilized(parts,i,threshold):returnireturnNone# A particle listelifnp.iterable(parts):list_it=[]foriinparts:list_it+=[self.stabilization_it(parts=int(i),nit=nit,threshold=threshold)]returnnp.array(list_it)# The whole swramelse:swarm=1+np.arange(self["optimization_parameters"]["n_particles"])returnself.stabilization_it(swarm,nit=nit,threshold=threshold)
[docs]deffindbestpart(self,decimals=10,verbose=False,lim_it=None):ifdecimals<-15:rise_warning("Best results not founded returning -1")return-1n_particles=self["optimization_parameters"]["n_particles"]nit=self.nitbestpos=self["best_position"]ibestpart=0iflim_itisNone:lim_it=nitforjinrange(lim_it):foriinrange(1,1+n_particles):pos=self["position"+str(i)]ifall(np.around(pos[j],decimals)==np.around(bestpos,decimals)):ifverbose:print("it=",j)returniifverbose:pass_info("not found with decimals =",decimals)returnself.findbestpart(decimals-1,verbose=verbose,lim_it=lim_it)