當前位置: 首頁>>代碼示例>>Python>>正文


Python MiniSom.train_batch方法代碼示例

本文整理匯總了Python中minisom.MiniSom.train_batch方法的典型用法代碼示例。如果您正苦於以下問題:Python MiniSom.train_batch方法的具體用法?Python MiniSom.train_batch怎麽用?Python MiniSom.train_batch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在minisom.MiniSom的用法示例。


在下文中一共展示了MiniSom.train_batch方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: SOM

# 需要導入模塊: from minisom import MiniSom [as 別名]
# 或者: from minisom.MiniSom import train_batch [as 別名]
def SOM(data,leninput,lentarget,alpha_som,omega_som):
    som = MiniSom(16,16,leninput,sigma=omega_som,learning_rate=alpha_som)
    som.random_weights_init(data)
    print("Training...")
    som.train_batch(data,20000) # training with 10000 iterations
    print("\n...ready!")
    
    numpy.save('weight_som',som.weights)
   
    bone()
    pcolor(som.distance_map().T) # distance map as background
    colorbar()
    
    t = zeros(lentarget,dtype=int)
    
    # use different colors and markers for each label
    markers = ['o','s','D']
    colors = ['r','g','b']
    outfile = open('cluster-result.csv','w')
    for cnt,xx in enumerate(data):
        w = som.winner(xx) # getting the winner
        
        
        for z in xx:
            outfile.write("%s " % str(z))
        outfile.write("%s-%s \n" % (str(w[0]),str(w[1])))
        
        
    outfile.close()
開發者ID:NurFaizin,項目名稱:Combining-Web-Content-and-Usage-Mining,代碼行數:31,代碼來源:batch_2.py

示例2: SOM

# 需要導入模塊: from minisom import MiniSom [as 別名]
# 或者: from minisom.MiniSom import train_batch [as 別名]
def SOM(data,leninput,lentarget):
    som = MiniSom(5,5,leninput,sigma=1.0,learning_rate=0.5)
    som.random_weights_init(data)
    print("Training...")
    som.train_batch(data,10000) # training with 10000 iterations
    print("\n...ready!")
    
    numpy.save('weight_som.txt',som.weights)
   
    bone()
    pcolor(som.distance_map().T) # distance map as background
    colorbar()
    
    t = zeros(lentarget,dtype=int)
    
    # use different colors and markers for each label
    markers = ['o','s','D']
    colors = ['r','g','b']
    outfile = open('cluster-result.csv','w')
    for cnt,xx in enumerate(data):
        w = som.winner(xx) # getting the winner
        #print cnt
        #print xx
        #print w
        
        for z in xx:
            outfile.write("%s " % str(z))
        outfile.write("%s-%s \n" % (str(w[0]),str(w[1])))
        
        #outfile.write("%s %s\n" % str(xx),str(w))
        # palce a marker on the winning position for the sample xx
        #plot(w[0]+.5,w[1]+.5,markers[t[cnt]],markerfacecolor='None',
        #     markeredgecolor=colors[t[cnt]],markersize=12,markeredgewidth=2)
    outfile.close()
開發者ID:NurFaizin,項目名稱:Combining-Web-Content-and-Usage-Mining,代碼行數:36,代碼來源:PreprocessLog.py

示例3: _minisombatch

# 需要導入模塊: from minisom import MiniSom [as 別名]
# 或者: from minisom.MiniSom import train_batch [as 別名]
    def _minisombatch(self):
        """Clusters sentence vectors using minisombatch algorithm
        
        Returns
        -------
        numpy ndarray
            codebook (weights) of the trained SOM
        """

        H = int(self.opts['size'])
        W = int(self.opts['size'])
        N = self.X.shape[1]
        som = MiniSom(H, W, N, sigma=1.0, random_seed=1)
        if self.opts['initialization']:
            som.random_weights_init(self.X)
        som.train_batch(self.X, self.opts['niterations'])
        return som.get_weights()
開發者ID:avsilva,項目名稱:sparse-nlp,代碼行數:19,代碼來源:sentencecluster.py

示例4: test_train_batch

# 需要導入模塊: from minisom import MiniSom [as 別名]
# 或者: from minisom.MiniSom import train_batch [as 別名]
 def test_train_batch(self):
     som = MiniSom(5, 5, 2, sigma=1.0, learning_rate=0.5, random_seed=1)
     data = np.array([[4, 2], [3, 1]])
     q1 = som.quantization_error(data)
     som.train_batch(data, 10)
     assert q1 > som.quantization_error(data)
開發者ID:vitorhirota,項目名稱:minisom,代碼行數:8,代碼來源:test.py


注:本文中的minisom.MiniSom.train_batch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。