当前位置: 首页>>代码示例>>Python>>正文


Python MiniSom.win_map方法代码示例

本文整理汇总了Python中minisom.MiniSom.win_map方法的典型用法代码示例。如果您正苦于以下问题:Python MiniSom.win_map方法的具体用法?Python MiniSom.win_map怎么用?Python MiniSom.win_map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在minisom.MiniSom的用法示例。


在下文中一共展示了MiniSom.win_map方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import win_map [as 别名]
t[target == 0] = 0
t[target == 1] = 1
t[target == 2] = 2
t[target == 3] = 3
t[target == 4] = 4
t[target == 5] = 5
t[target == 6] = 6
t[target == 7] = 7
t[target == 8] = 8
t[target == 9] = 9
# use differet colors and markers for each label
#markers = []
colors = ['r','g','b','y','w','orange','black','pink','brown','purple']

som.win_map(data)
with open('bm.txt', 'w') as f:    #making bm file
     f.write(str(len(data))+'\n')
     for cnt,xx in enumerate(data):
         win = som.winner(xx) # getting the winner
     # palce a marker on the winning position for the sample xx
         plot(win[0]+.5,win[1]+.5,'.',markerfacecolor='None',markeredgecolor=colors[t[cnt]],markersize=1,markeredgewidth=1)
         f.write(str(win[0])+'\t'+str(win[1])+'\t'+str(t[cnt])+'\n')


with open('umx.txt', 'w') as f:    #making umx file
    for cnt,xx in enumerate(data):
     win = som.winner(xx) # getting the winner
     # palce a marker on the winning position for the sample xx
     plot(win[0]+.5,win[1]+.5,'.',markerfacecolor='None',
           markeredgecolor=colors[t[cnt]],markersize=1,markeredgewidth=1)
开发者ID:heeju00627,项目名称:heeju,代码行数:32,代码来源:mytest(som).py

示例2: setUp

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import win_map [as 别名]
class TestMinisom:

    def setUp(self):
        self.som = MiniSom(5, 5, 1)
        for w in self.som.weights:  # checking weights normalization
            assert_almost_equal(1.0, np.linalg.norm(w))
        self.som.weights = np.zeros((5, 5))  # fake weights
        self.som.weights[2, 3] = 5.0
        self.som.weights[1, 1] = 2.0

    def test_fast_norm(self):
        assert minisom.fast_norm(np.array([1, 3])) == sqrt(1 + 9)

    def test_gaussian(self):
        bell = minisom.gaussian((2, 2), 1, self.som.neigx, self.som.neigy)
        assert bell.max() == 1.0
        assert bell.argmax() == 12  # unravel(12) = (2,2)

    def test_win_map(self):
        winners = self.som.win_map([5.0, 2.0])
        assert winners[(2, 3)][0] == 5.0
        assert winners[(1, 1)][0] == 2.0

    def test_activation_reponse(self):
        response = self.som.activation_response([5.0, 2.0])
        assert response[2, 3] == 1
        assert response[1, 1] == 1

    def test_activate(self):
        assert self.som.activate(5.0).argmin() == 13.0  # unravel(13) = (2,3)

    def test_quantization_error(self):
        self.som.quantization_error([5, 2]) == 0.0
        self.som.quantization_error([4, 1]) == 0.5

    def test_quantization(self):
        q = self.som.quantization(np.array([4, 2]))
        assert q[0] == 5.0
        assert q[1] == 2.0

    # def test_random_seed(self):
    #     som1 = MiniSom(5, 5, 2, sigma=1.0, learning_rate=0.5, random_seed=1)
    #     som2 = MiniSom(5, 5, 2, sigma=1.0, learning_rate=0.5, random_seed=1)
    #     # same initialization
    #     assert_array_almost_equal(som1.weights, som2.weights)
    #     data = np.random.rand(100, 2)
    #     som1 = MiniSom(5, 5, 2, sigma=1.0, learning_rate=0.5, random_seed=1)
    #     som1.train_random(data, 10)
    #     som2 = MiniSom(5, 5, 2, sigma=1.0, learning_rate=0.5, random_seed=1)
    #     som2.train_random(data, 10)
    #     # same state after training
    #     assert_array_almost_equal(som1.weights, som2.weights)

    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)

    # def test_train_random(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_random(data, 10)
    #     assert q1 > som.quantization_error(data)

    def test_random_weights_init(self):
        som = MiniSom(2, 2, 2, sigma=0.1, random_seed=1)
        som.random_weights_init(np.array([[1.0, .0]]))
        for w in som.weights:
            assert_array_equal(w[0], np.array([1.0, .0]))
开发者ID:vitorhirota,项目名称:minisom,代码行数:74,代码来源:test.py

示例3: MinMaxScaler

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import win_map [as 别名]
sc = MinMaxScaler(feature_range = (0, 1))
X = sc.fit_transform(X)

# Training the SOM
from minisom import MiniSom
som = MiniSom(x = 10, y = 10, input_len = 15, sigma = 1.0, learning_rate = 0.5)
som.random_weights_init(X)
som.train_random(data = X, num_iteration = 100)

# Visualizing the results
from pylab import bone, pcolor, colorbar, plot, show
bone()
pcolor(som.distance_map().T)
colorbar()
markers = ['o', 's']
colors = ['r', 'g']
for i, x in enumerate(X):
    w = som.winner(x)
    plot(w[0] + 0.5,
         w[1] + 0.5,
         markers[y[i]],
         markeredgecolor = colors[y[i]],
         markerfacecolor = 'None',
         markersize = 10,
         markeredgewidth = 2)
show()

# Finding the frauds
mappings = som.win_map(X)
frauds = np.concatenate((mappings[(8,1)], mappings[(6,8)]), axis = 0)
frauds = sc.inverse_transform(frauds)
开发者ID:kmrskt,项目名称:fraud_detection_using_som,代码行数:33,代码来源:som.py

示例4: SomPage

# 需要导入模块: from minisom import MiniSom [as 别名]
# 或者: from minisom.MiniSom import win_map [as 别名]
class SomPage(tk.Frame):
    
    ## UI 생성
    def __init__(self, parent, controller):
     
        ## tk.Frame 초기화
        tk.Frame.__init__(self, parent)
        
        style.use("ggplot")

        self.figure = pl.figure(1)
        self.a = self.figure.add_subplot(111)

        self.canvas = FigureCanvasTkAgg(self.figure, self)
        self.canvas.get_tk_widget().grid(sticky="news")
        self.canvas._tkcanvas.grid(sticky="news")
        
        ## Initialization
        self.som = MiniSom(10,10,136,sigma=1.0,learning_rate=0.5)
    
    ####---------------------------------------------   
    ## THREAD 생성
    def callback_threaded(self, status):
        
        self.queue = Queue()    # 크기가 1인 버퍼
        
        self.thread = Thread(target=self.training, args=(status,))
        self.thread.daemon = True
        self.thread.start()
        
        self.queue.put(object()) ## 첫번째
        print("Start")
        self.queue.join() ## 네번째
        self.thread.join()
        self.plotting(status)
        
    
    ## size, learning_rate, training_count, target_count)
    def training(self, status):
        
        self.figure.clear()
        self.queue.get() ## 두번째
        
        ## reading the dataset in the csv format  
        self.data = genfromtxt('iris6.csv', delimiter=',',dtype = float)
        self.data = numpy.nan_to_num(self.data)
        ## data normalization
        self.data = apply_along_axis(lambda x: x/linalg.norm(x),1,self.data) 
        
        self.som.random_weights_init(self.data)
        
        print("Training...")
        
        self.som.train_random(self.data,100) # random training
        
        bone()
        ## plotting the distance map as background
        pcolor(self.som.distance_map().T)
        colorbar()
        
        ## loadingthe labels
        target = genfromtxt('iris4_2.csv', delimiter=',', usecols=(0), dtype=int)
        self.t = zeros(len(target),dtype=int)
        
        print("...ready to plot...")
        
        for i in range(len(target)):
            self.t[target == i] = i
        
        self.som.win_map(self.data)
        
        self.queue.task_done() ## 세번째
        
    def plotting(self, status):
        
        self.figure = pl.figure(1)
        self.a = self.figure.add_subplot(111)
        
        print("Plotting...")
        
        ## use differet colors and markers for each label
        ## markers = []
        colors = ['r','g','b','y','w','orange','black','pink','brown','purple']
        
        ## making bm file
        with open('bm.txt', 'w') as f:
             f.write(str(len(self.data))+'\n')
             for cnt,xx in enumerate(self.data):
                 win = self.som.winner(xx) # getting the winner
             # palce a marker on the winning position for the sample xx
                 self.a.plot(win[0]+.5,win[1]+.5,'.', markerfacecolor='None', markeredgecolor=colors[self.t[cnt]], markersize=1, markeredgewidth=1)
                 f.write(str(win[0])+'\t'+str(win[1])+'\t'+str(self.t[cnt])+'\n')
        
        ## making umx file
        with open('umx.txt', 'w') as f:
            for cnt,xx in enumerate(self.data):
             win = self.som.winner(xx) # getting the winner
             # palce a marker on the winning position for the sample xx
             self.a.plot(win[0]+.5,win[1]+.5,'.',markerfacecolor='None',
                   markeredgecolor=colors[self.t[cnt]], markersize=1, markeredgewidth=1)
#.........这里部分代码省略.........
开发者ID:heeju00627,项目名称:heeju,代码行数:103,代码来源:class_som.py


注:本文中的minisom.MiniSom.win_map方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。