当前位置: 首页>>代码示例>>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;未经允许,请勿转载。