如何在Java中比较两个多维数组之间的相似度
我编写了一个构建 3 个图(弧和节点)的程序。 这些图表是基于 1 和 0 的二维数组构建的。 第一张图是理想图,将与其他两张图进行比较。我在想是否有一种方法可以比较两个图之间的相似性,即图 2 中的有多少顶点与图 1 中的顶点相似。
替代问题: 这些图是基于 1 和 0 的 2D 数组构建的,因此如果有一种方法可以将图 1 的 2D 数组与图 2 的数组进行比较,那么这将解决我的问题。
我不希望你们都贴出代码,但我只是想了解是否有一种方法可以做到这一点。如果可以的话,该怎么做。 非常感谢任何帮助!
大家好,
只是为了更清楚一点: 我有两个二维数组,如下所示:
双 [][] MatrixOfOriginalGraph= {{1,1,1,1}, {0,1,0,0}, {0,0,1,0}, {0,0,0,1}}; 双 [][] MatrixToBeComparedWithOriginal= {{1,0,0,1}, {0,1,1,0}, {0,0,1,1}, {0,0,0,1};
第一个数组用于绘制第一个图形,第二个数组用于绘制第二个图形。第一个图基本上是一个 4 节点图,其中第一个节点连接到所有其他节点。其他节点不相互连接。第二张图是混合的。我想知道图 2 中的顶点中有多少个节点与图 1 中的节点相同。
谢谢, 杰特诺里。
I have made a program which builds 3 graphs(arc and node).
The graphs were built based on 2D arrays of 1 and 0.
The first graph is the Ideal Graph which the other two are going to be compared to. I was wandering if there is a way of comparing similarity between two graphs ie How many of the vertices in graph 2 are similar to the vertices in graph 1.
Alternative question:
The graphs were built based on 2D arrays of 1 and 0 so if there is a way of comparing the 2D array for Graph 1 with the array for graph 2 instead than this would solve my problem.
I don't expect you all to put codes up but I'm just trying to understand if there is a method that can do this. And if so how it can be done.
Any help is appreciated greatly!
Hi All,
Just to make it a bit more clear:
I have two 2Dimensional arrays like so:
double [][] MatrixOfOriginalGraph= {{1,1,1,1},
{0,1,0,0},
{0,0,1,0},
{0,0,0,1}};
double [][] MatrixToBeComparedWithOriginal= {{1,0,0,1},
{0,1,1,0},
{0,0,1,1},
{0,0,0,1};
The first array is used to draw the first graph and the second is used to draw the second graph. The first graph is basically a 4 node graph where the first node is connected to all the other nodes. The other nodes are not connected to each other. The second graph is mixed. I want to know how many of the nodes in vertices in graph two are the same as the ones in graph 1.
Thanks,
jetnori.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望我的理解是对的。您有一个图,您的数组 MatrixOfOriginalGraph 将是以下邻接矩阵的表示:
相似性是由相似的连接定义的?
也许一个好的起点可能是节点对之间的汉明距离,每个节点都来自一个图表?
所以
会导致类似的事情
。但请记住,使用汉明距离时,两个比较结构中必须有相同数量的变量。我不知道这是否是您问题的限制。如果这是一个限制,您可以尝试 Levenshtein 距离。
距离越小,节点相似。然后,您可以总结所有节点的汉明距离(实际上您可以计算整个 1 和 0 序列上的距离)或计算平均值和偏差等,具体取决于您需要什么或如何定义相似性。
Hopefully I got you right. You have a graph, and your array MatrixOfOriginalGraph would be a presentation of the following adjacency matrix:
And similarity is defined by similar connections?
Maybe a good starting point could be the Hamming distance between pairs of the nodes, each from one graph?
So
would lead to something like
and so on. But keep in mind using the Hamming distance there have to be an equal amount of variables in both compared structures. I don't know whether this is an limitation for your problem. If this would be a limitation you could instead try the Levenshtein distance.
The lesser the distance the similar the nodes. Then you may sum up the Hamming distances of all nodes (well actually you could have just computed the distance over the whole sequence of ones an zeros) or compute mean and deviation and so on, depending what you need or how you define similarity.