开发者

how to compare similarity between two Multi Dimensional Arrays in Java

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 c开发者_Go百科onnected 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.


Hopefully I got you right. You have a graph, and your array MatrixOfOriginalGraph would be a presentation of the following adjacency matrix:

1111
0100
0010
0001

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

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};

would lead to something like

int node1 = computeDistance({0,1,0,0}, {0,1,1,0});
int node2 = computeDistance({1,1,1,1}, {1,0,0,1});

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜