som.py
def update(self, sample):
        '''
        if the whole map has been initialized - go to ubiSOM
        else use the new sample as a prototype.
        ubiSOM consists of ordering phase that lasts for T samples 
        and the learning phase that continues until the newly computed error exeeds the deafult value
        '''
        
        sample = sample.astype('float64')

        if self.iteration%100==0: #just for the purpouse of visualizing the nodes
            self.maps_log[str(self.iteration)]=np.copy(self.somap.reshape((self.size,self.size,self.dim)))
            
        if self.iteration < self.size**2:
            
            self.somap[self.iteration] = sample
            self.generalization_errors.append(0)
        
        elif self.ordering:                  #the ordering step
            
            self.eta =  self.eta_annealing[self.iteration_ordering]
            self.sigma = self.sigma_annealing[self.iteration_ordering]
            self.iteration_ordering += 1
            
            if self.iteration_ordering == self.T-1:
                self.ordering = False
                self.learning_index = 0
                self._update_drift()
                
            self.samples.append(sample)
            min_error = np.min(np.sum((sample - self.somap)**2, axis=1))
            self.generalization_errors.append(min_error)
            self._update(sample)
            
        else:                                #the learning step
            
            #set up learning parameters
            if self.drift_values[0] > self.drift_values[-1]:
                self.eta =  self.eta_f * self.drift_values[-1]/self.drift_values[0]
                self.sigma = self.sigma_f * self.drift_values[-1]/self.drift_values[0]
            else:
                self.eta =  self.eta_f
                self.sigma = self.sigma_f    
                
            self.samples.append(sample)
            min_error = np.min(np.sqrt(np.sum((sample - self.somap)**2, axis=1)))
            self.generalization_errors.append(min_error)
            self._update(sample)
            self._update_drift()
            
            # check for drastical distribution changes
            if self.iteration_learning > self.T-1 and np.sum(self.drift_values[-self.T:]>self.T):
                self.ordering = True
                self.ordering_index = 0
                    
        self.iteration += 1

        if the whole map has been initialized - go to ubiSOM
        else use the new sample as a prototype.
        ubiSOM consists of ordering phase that lasts for T samples 
        and the learning phase that continues until the newly computed error exeeds the deafult value
        
if the whole map has been initialized - go to ubiSOM
else use the new sample as a prototype.
ubiSOM consists of ordering phase that lasts for T samples
and the learning phase that continues until the newly computed error exeeds the deafult value
if the whole map has been initialized - go to ubiSOM else use the new sample as a prototype . ubiSOM consists of ordering phase that lasts for T samples and the learning phase that continues until the newly computed error exeeds the deafult value
def update(self, sample):
        sample = sample.astype('float64')
        if self.iteration%100==0: 
            self.maps_log[str(self.iteration)]=np.copy(self.somap.reshape((self.size,self.size,self.dim)))
        if self.iteration < self.size**2:
            self.somap[self.iteration] = sample
            self.generalization_errors.append(0)
        elif self.ordering:                  
            self.eta =  self.eta_annealing[self.iteration_ordering]
            self.sigma = self.sigma_annealing[self.iteration_ordering]
            self.iteration_ordering += 1
            if self.iteration_ordering == self.T-1:
                self.ordering = False
                self.learning_index = 0
                self._update_drift()
            self.samples.append(sample)
            min_error = np.min(np.sum((sample - self.somap)**2, axis=1))
            self.generalization_errors.append(min_error)
            self._update(sample)
        else:                                
            if self.drift_values[0] > self.drift_values[-1]:
                self.eta =  self.eta_f * self.drift_values[-1]/self.drift_values[0]
                self.sigma = self.sigma_f * self.drift_values[-1]/self.drift_values[0]
            else:
                self.eta =  self.eta_f
                self.sigma = self.sigma_f    
            self.samples.append(sample)
            min_error = np.min(np.sqrt(np.sum((sample - self.somap)**2, axis=1)))
            self.generalization_errors.append(min_error)
            self._update(sample)
            self._update_drift()
            if self.iteration_learning > self.T-1 and np.sum(self.drift_values[-self.T:]>self.T):
                self.ordering = True
                self.ordering_index = 0
        self.iteration += 1
def update ( self , sample ) : sample = sample . astype ( 'float64' ) if self . iteration % 100 == 0 : self . maps_log [ str ( self . iteration ) ] = np . copy ( self . somap . reshape ( ( self . size , self . size , self . dim ) ) ) if self . iteration < self . size ** 2 : self . somap [ self . iteration ] = sample self . generalization_errors . append ( 0 ) elif self . ordering : self . eta = self . eta_annealing [ self . iteration_ordering ] self . sigma = self . sigma_annealing [ self . iteration_ordering ] self . iteration_ordering += 1 if self . iteration_ordering == self . T - 1 : self . ordering = False self . learning_index = 0 self . _update_drift ( ) self . samples . append ( sample ) min_error = np . min ( np . sum ( ( sample - self . somap ) ** 2 , axis = 1 ) ) self . generalization_errors . append ( min_error ) self . _update ( sample ) else : if self . drift_values [ 0 ] > self . drift_values [ - 1 ] : self . eta = self . eta_f * self . drift_values [ - 1 ] / self . drift_values [ 0 ] self . sigma = self . sigma_f * self . drift_values [ - 1 ] / self . drift_values [ 0 ] else : self . eta = self . eta_f self . sigma = self . sigma_f self . samples . append ( sample ) min_error = np . min ( np . sqrt ( np . sum ( ( sample - self . somap ) ** 2 , axis = 1 ) ) ) self . generalization_errors . append ( min_error ) self . _update ( sample ) self . _update_drift ( ) if self . iteration_learning > self . T - 1 and np . sum ( self . drift_values [ - self . T : ] > self . T ) : self . ordering = True self . ordering_index = 0 self . iteration += 1
if the whole map has been initialized - go to ubiSOM
else use the new sample as a prototype.
if the whole map has been initialized - go to ubiSOM else use the new sample as a prototype .
'''
        if the whole map has been initialized - go to ubiSOM
        else use the new sample as a prototype.
        ubiSOM consists of ordering phase that lasts for T samples 
        and the learning phase that continues until the newly computed error exeeds the deafult value
        ''' #just for the purpouse of visualizing the nodes #the ordering step #the learning step #set up learning parameters # check for drastical distribution changes
self
sample