Orange Forum • View topic - Orange SOM U-Matrix

Orange SOM U-Matrix

A place to ask questions about methods in Orange and how they are used and other general support.

Orange SOM U-Matrix

Postby Kristo36 » Thu May 10, 2012 19:27

Is there some tutorial how to get U-Matrix with python. There is a tutorial to get SOMMap but nothing for U-Matrix. In visualizer I can see the U-Matrix but I don't know how to print it out in Python.

Here is my code to print the nodes into file:
Code: Select all
#!C:/Python27

import Orange
import random

random.seed(0)
r = 4
c = 4
som = Orange.projection.som.SOMLearner(map_shape=(r, c), initialize=Orange.projection.som.InitializeRandom)
map = som(Orange.data.Table("input.tab"))
print map[0,0].instances
str = ''
filename = "output.tab"
FILE = open(filename,"w")

for i in range(0, r):
   for j in range(0, c):
      for e in map[i, j].instances:
         str = '%s' % e
         FILE.writelines(str + '\n')
FILE.close()


Is this the right way to making a U-Matrix object ?
Code: Select all
test = Orange.projection.som.get_u_matrix(map)


I need a for loop to print the values from the U-Matrix into the file so I can later show it on a webpage.

Re: Orange SOM U-Matrix

Postby Ales » Fri May 11, 2012 10:04

Kristo36 wrote:Is this the right way to making a U-Matrix object ?
Code: Select all
test = Orange.projection.som.get_u_matrix(map)


Yes.

Re: Orange SOM U-Matrix

Postby Kristo36 » Fri May 11, 2012 12:17

But after I make the U-Matrix object how can I iterate through the Nodes like in the SOMLearner object?

Re: Orange SOM U-Matrix

Postby Kristo36 » Wed May 16, 2012 1:21

Does someone know how to get Nodes from U-Matrix object ?

Re: Orange SOM U-Matrix

Postby Ales » Thu May 17, 2012 9:25

You can't get the nodes from the U-matrix (it is a plain numpy.ndarray). You have to map the corresponding nodes from the SOMMap to the U-matrix yourself (i.e. every map[i, j] node corresponds to u_matrix[i*2, j*2] entry in the U-matrix).

Re: Orange SOM U-Matrix

Postby Kristo36 » Thu May 17, 2012 15:02

Thank you for the help Ales. It's so simple, but I just started to learn this and didn't have a clue.


Return to Questions & Support



cron