需要自组织映射中 U 矩阵的具体示例

发布于 2024-11-17 09:15:41 字数 748 浏览 2 评论 0原文

我正在尝试开发一个使用 SOM 来分析数据的应用程序。但是,完成训练后,我找不到可视化结果的方法。我知道U-Matrix是其中一种方法,但我无法正确理解它。因此,我要求提供一个如何构建 U 矩阵的具体且详细的示例。

我还在 U 矩阵和自组织映射 上阅读了答案,但它只是指的是1行地图,3x3地图怎么样?我知道对于 3x3 地图:

m(1) m(2) m(3)
m(4) m(5) m(6)
m(7) m(8) m(9)

必须创建 5x5 矩阵:

u(1)   u(1,2)     u(2)   u(2,3)     u(3)
u(1,4) u(1,2,4,5) u(2,5) u(2,3,5,6) u(3,6)
u(4)   u(4,5)     u(5)   u(5,6)     u(6)
u(4,7) u(4,5,7,8) u(5,8) u(5,6,8,9) u(6,9)
u(7)   u(7,8)     u(8)   u(8,9)     u(9)

但我不知道如何计算 u 权重 u(1,2,4,5), u(2,3,5,6), u( 4,5,7,8) 和 u(5,6,8,9)。

最后,在构建了U-Matrix之后,有没有办法使用颜色来可视化它,例如热图?

非常感谢您抽出时间。

干杯

I'm trying to develop an application using SOM in analyzing data. However, after finishing training, I cannot find a way to visualize the result. I know that U-Matrix is one of the method but I cannot understand it properly. Hence, I'm asking for a specific and detail example how to construct U-Matrix.

I also read an answer at U-matrix and self organizing maps but it only refers to 1 row map, how about 3x3 map? I know that for 3x3 map:

m(1) m(2) m(3)
m(4) m(5) m(6)
m(7) m(8) m(9)

a 5x5 matrix must me created:

u(1)   u(1,2)     u(2)   u(2,3)     u(3)
u(1,4) u(1,2,4,5) u(2,5) u(2,3,5,6) u(3,6)
u(4)   u(4,5)     u(5)   u(5,6)     u(6)
u(4,7) u(4,5,7,8) u(5,8) u(5,6,8,9) u(6,9)
u(7)   u(7,8)     u(8)   u(8,9)     u(9)

but I don't know how to calculate u-weight u(1,2,4,5), u(2,3,5,6), u(4,5,7,8) and u(5,6,8,9).

Finally, after constructing U-Matrix, is there any way to visualize it using color, e.g. heat map?

Thank you very much for your time.

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

-柠檬树下少年和吉他 2024-11-24 09:15:41

我不知道你是否仍然对此感兴趣,但我找到了这个链接
http://www.uni-marburg.de/fb12/datenbionik /pdf/pubs/1990/UltschSiemon90
它非常具体地解释了如何计算 U 矩阵。
希望有帮助。

顺便说一句,我发现该网站的链接有几个涉及 SOM 的资源,我将其留在这里以防有人感兴趣:
http://www.ifs.tuwien.ac.at/dm/somtoolbox /可视化.html

I don't know if you are still interested in this but I found this link
http://www.uni-marburg.de/fb12/datenbionik/pdf/pubs/1990/UltschSiemon90
which explains very speciffically how to calculate the U-matrix.
Hope it helps.

By the way, the site were I found the link has several resources referring to SOMs I leave it here in case anyone is interested:
http://www.ifs.tuwien.ac.at/dm/somtoolbox/visualisations.html

风向决定发型 2024-11-24 09:15:41

Kohonen 地图的基本思想是将数据点映射到
晶格,通常是二维矩形网格。

在最简单的实现中,晶格通过创建 3D 来初始化
具有以下尺寸的数组:

width * height * number_features

这是 U 矩阵

宽度和高度由用户选择; number_features 只是数字
数据中的特征(列或字段)。

直观上,这只是创建一个尺寸为 w * h 的 2D 网格
(例如,如果 w = 10 且 h = 10,则您的晶格有 100 个单元格),那么
到每个单元格中,放置一个随机的一维数组(有时称为“参考元组”)
其大小和值受您的数据限制。

参考元组也称为权重

U 矩阵是如何渲染的?

在下面的示例中,数据由 RGB 元组组成,所以参考元组
长度为 3,并且这三个值中的每一个都必须位于 0 到 255 之间)。

您可以通过这个 3D 数组(“晶格”)开始主迭代循环
该算法迭代地定位每个数据点,使其最接近其他相似的数据点。

如果您随时间(迭代次数)绘制它,那么您可以可视化集群
形成。

我为此使用的绘图工具是出色的 Python 库 Matplotlib
它直接绘制晶格,只需将其传递到 imshow 函数。

下面是 SOM 算法进度的八个快照,从初始化到 700 次迭代。新初始化的(iteration_count = 0)晶格渲染在左上方面板中;最终迭代的结果位于右下面板中。

或者,您可以使用较低级别的成像库(Python 中的,例如 PIL)并将参考元组一次一个地传输到 2D 网格上:

for y in range(h):
    for x in range(w):
        img.putpixel( (x, y), (
            SOM.Umatrix[y, x, 0], 
            SOM.Umatrix[y, x, 1], 
            SOM.Umatrix[y, x, 2]) 
        )

这里 img 是 PIL 的 的一个实例>图像类。这里的图像是通过一次一个像素迭代网格来创建的;对于每个像素,putpixel 会在 img 上调用三次,这三次调用当然对应于 RGB 元组中的三个值。

图像1 图像2

The essential idea of a Kohonen map is that the data points are mapped to a
lattice, which is often a 2D rectangular grid.

In the simplest implementations, the lattice is initialized by creating a 3D
array with these dimensions:

width * height * number_features

This is the U-matrix.

Width and height are chosen by the user; number_features is just the number
of features (columns or fields) in your data.

Intuitively this is just creating a 2D grid of dimensions w * h
(e.g., if w = 10 and h = 10 then your lattice has 100 cells), then
into each cell, placing a random 1D array (sometimes called "reference tuples")
whose size and values are constrained by your data.

The reference tuples are also referred to as weights.

How is the U-matrix rendered?

In my example below, the data is comprised of rgb tuples, so the reference tuples
have length of three and each of the three values must lie between 0 and 255).

It's with this 3D array ("lattice") that you begin the main iterative loop
The algorithm iteratively positions each data point so that it is closest to others similar to it.

If you plot it over time (iteration number) then you can visualize cluster
formation.

The plotting tool i use for this is the brilliant Python library, Matplotlib,
which plots the lattice directly, just by passing it into the imshow function.

Below are eight snapshots of the progress of a SOM algorithm, from initialization to 700 iterations. The newly initialized (iteration_count = 0) lattice is rendered in the top left panel; the result from the final iteration, in the bottom right panel.

Alternatively, you can use a lower-level imaging library (in Python, e.g., PIL) and transfer the reference tuples onto the 2D grid, one at a time:

for y in range(h):
    for x in range(w):
        img.putpixel( (x, y), (
            SOM.Umatrix[y, x, 0], 
            SOM.Umatrix[y, x, 1], 
            SOM.Umatrix[y, x, 2]) 
        )

Here img is an instance of PIL's Image class. Here the image is created by iterating over the grid one pixel at a time; for each pixel, putpixel is called on img three times, the three calls of course corresponding to the three values in an rgb tuple.

Image1 Image2

那小子欠揍 2024-11-24 09:15:41

从您创建的矩阵中:

u(1)     u(1,2)     u(2)   u(2,3)    u(3)
u(1,4) u(1,2,4,5) u(2,5) u(2,3,5,6) u(3,6)
u(4)     u(4,5)     u(5)   u(5,6)    u(6)
u(4,7) u(4,5,7,8) u(5,8) u(5,6,8,9) u(6,9)
u(7)   u(7,8)       u(8)   u(8,9)    u(9)

具有单个数字的元素,如 u(1)、u(2)、...、u(9) 以及具有两个以上数字的元素,如 u(1,2,4,5) ), u(2,3,5,6), ... , u(5,6,8,9) 使用邻域值的平均值、中值、最小值或最大值等计算。

首先用两个数字计算元素是一个好主意,一个可能的代码是:

 for i in range(self.h_u_matrix):
  for j in range(self.w_u_matrix):

    nb = (0,0)

    if not (i % 2) and (j % 2):
      nb = (0,1)

    elif (i % 2) and not (j % 2):
      nb = (1,0)

    self.u_matrix[(i,j)] = np.linalg.norm(
        self.weights[i //2, j //2] - self.weights[i //2 +nb[0], j // 2 + nb[1]],
        axis = 0
    )

self.h_u_matrix = self.weights.shape[0]*2 - 1上面的代码中>self.w_u_matrix = self.weights.shape[1]*2 - 1 是 U 矩阵的维度。话虽如此,为了计算其他元素,有必要获取它们邻居的列表并应用平均值。下面的代码实现了这个想法:

for i in range(self.h_u_matrix):
  for j in range(self.w_u_matrix):

    if not (i % 2) and not (j % 2):
       nodelist = []
       if i > 0:
           nodelist.append((i-1,j))
       if i < 4:
           nodelist.append((i+1, j))
       if j > 0:
           nodelist.append((i,j -1))
       if j < 4:
           nodelist.append((i,j+1))

       meanlist = [self.u_matrix[u_node] for u_node in nodelist]
       self.u_matrix[(i,j)] = np.mean(meanlist)
  
     elif (i % 2) and (j % 2):
       meanlist = [
                    (i - 1, j),
                    (i + 1, j),
                    (i, j - 1),
                    (i, j + 1)]
       self.u_matrix[(i,j)] = np.mean(meanlist)
       
  
  

From the matrix that you create:

u(1)     u(1,2)     u(2)   u(2,3)    u(3)
u(1,4) u(1,2,4,5) u(2,5) u(2,3,5,6) u(3,6)
u(4)     u(4,5)     u(5)   u(5,6)    u(6)
u(4,7) u(4,5,7,8) u(5,8) u(5,6,8,9) u(6,9)
u(7)   u(7,8)       u(8)   u(8,9)    u(9)

The elements with single numbers like u(1), u(2), ..., u(9) as just the elements with more than two numbers like u(1,2,4,5), u(2,3,5,6), ... , u(5,6,8,9) are calculated using something like the mean, median, min or max of the values in the neighborhood.

It's a nice idea calculate the elements with two numbers first, one possible code for that is:

 for i in range(self.h_u_matrix):
  for j in range(self.w_u_matrix):

    nb = (0,0)

    if not (i % 2) and (j % 2):
      nb = (0,1)

    elif (i % 2) and not (j % 2):
      nb = (1,0)

    self.u_matrix[(i,j)] = np.linalg.norm(
        self.weights[i //2, j //2] - self.weights[i //2 +nb[0], j // 2 + nb[1]],
        axis = 0
    )

In the code above the self.h_u_matrix = self.weights.shape[0]*2 - 1and self.w_u_matrix = self.weights.shape[1]*2 - 1 are the dimensions of the U-Matrix. With that said, for calculate the others elements it's necessary obtain a list with they neighboors and apply a mean for example. The following code implements that's idea:

for i in range(self.h_u_matrix):
  for j in range(self.w_u_matrix):

    if not (i % 2) and not (j % 2):
       nodelist = []
       if i > 0:
           nodelist.append((i-1,j))
       if i < 4:
           nodelist.append((i+1, j))
       if j > 0:
           nodelist.append((i,j -1))
       if j < 4:
           nodelist.append((i,j+1))

       meanlist = [self.u_matrix[u_node] for u_node in nodelist]
       self.u_matrix[(i,j)] = np.mean(meanlist)
  
     elif (i % 2) and (j % 2):
       meanlist = [
                    (i - 1, j),
                    (i + 1, j),
                    (i, j - 1),
                    (i, j + 1)]
       self.u_matrix[(i,j)] = np.mean(meanlist)
       
  
  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文