如何组织一个列表,保持相似性矩阵中相邻元素之间的最小相似性?

发布于 2025-01-17 23:16:01 字数 1003 浏览 3 评论 0原文

我有 24 个样本的清单。对于每个样本,我都有一个向量,其中包含与其他样本的距离。这构成了 24 x 24 相似度矩阵。在该矩阵中,相似度值的范围从0到100,其中100是样本与其自身的相似度值。

这是相似性矩阵的图像(带有树状图)和矩阵的子集

HeatMap + dendrogram

> similarity_matrix[1:10,1:10]
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]  100   10   15    0   15   50   25   10   25    10
 [2,]   10  100    0   20    0   30   10   30   50    70
 [3,]   15    0  100    0   15    0   15    0   15     0
 [4,]    0   20    0  100   50   20    0   20    0    20
 [5,]   15    0   15   50  100    0   15    0   15     0
 [6,]   50   30    0   20    0  100   10   30   10    30
 [7,]   25   10   15    0   15   10  100   50   25    10
 [8,]   10   30    0   20    0   30   50  100   10    30
 [9,]   25   50   15    0   15   10   25   10  100    50
[10,]   10   70    0   20    0   30   10   30   50   100

从该相似性矩阵中并选择起始样本 我希望能够生成一个列表,最大限度地减少样本与其两个相邻样本的相似性。

到目前为止我还没有想到一个有效的方法来做到这一点。通过数学运算或使用循环。

I have a list of 24 samples. For each sample I have a vector with the distances to the other samples. This constitutes a 24 by 24 similarity matrix. In this matrix the similarity values range from 0 to 100, where 100 is the similarity value of a sample to itself.

Here's An image of the similarity matrix (with dendrogram) and a subset of the matrix

HeatMap + dendrogram

> similarity_matrix[1:10,1:10]
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]  100   10   15    0   15   50   25   10   25    10
 [2,]   10  100    0   20    0   30   10   30   50    70
 [3,]   15    0  100    0   15    0   15    0   15     0
 [4,]    0   20    0  100   50   20    0   20    0    20
 [5,]   15    0   15   50  100    0   15    0   15     0
 [6,]   50   30    0   20    0  100   10   30   10    30
 [7,]   25   10   15    0   15   10  100   50   25    10
 [8,]   10   30    0   20    0   30   50  100   10    30
 [9,]   25   50   15    0   15   10   25   10  100    50
[10,]   10   70    0   20    0   30   10   30   50   100

From this similarity matrix and choosing a starting sample I would like to be able to generate a list that minimises the similarity of a sample to its two adjacent samples.

So far I have not been able to think of an efficient way to do this. Either through mathematical operations or using loops.

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

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

发布评论

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

评论(1

陌生 2025-01-24 23:16:01

我不知道r,但是我猜想您可以做矩阵的第一个索引,然后将模拟性带到其后值和之后。

for(int i = 0; i < row.count; i++)
{
   leftIndex = i - 1;
   rightIndex = i + 1;
   totalCost = 0;
   if (leftIndex >= 1)
   {
      totalCost += matrix[i][leftIndex]
   }
   if (rightIndex < column.count)
   {
       totalCost += matrix[i][leftIndex]
   }     
    list.add(totalCost)
}

之后,您只需要对值进行排序,同时跟踪索引获得该值的值。

I dont know R but im guessing you could do just loop the first index of the matrix and get the simularitys to the value befor and after it.

for(int i = 0; i < row.count; i++)
{
   leftIndex = i - 1;
   rightIndex = i + 1;
   totalCost = 0;
   if (leftIndex >= 1)
   {
      totalCost += matrix[i][leftIndex]
   }
   if (rightIndex < column.count)
   {
       totalCost += matrix[i][leftIndex]
   }     
    list.add(totalCost)
}

After that you just need to sort the values while keeping track of what index got that value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文