[Java] simrank

Source: Internet
Author: User

for more information about simrank, see Article http://www.cnblogs.com/youwang/archive/2010/02/06/1665105.html. The following is a Java Code implementation that uses the webgraph library.

/** To change this template, choose tools | templates * and open the template in the editor. */package cn.edu. dlut. wisdom; import it. unimi. DSI. fastutil. ints. *; import it. unimi. DSI. webgraph. *;/***** @ author you wang */public class simrank {private immutablegraph; private immutablegraph igraph; private double dampening = 0.85; private int2objectarraymap <int2doublearraymap> scores; public double getdampening () {return dampening;} public void setdampening (double dampening) {This. dampening = dampening;} public simrank (immutablegraph graph) {This. graph = graph; this. igraph = transform. transpose (graph);} public simrank (immutablegraph graph, immutablegraph igraph) {This. graph = graph; this. igraph = igraph;} public void computesimrank () {int n = graph. numnodes (); int iter = (INT) math. ABS (math. log (double) N)/math. log (double) 10) + 1; computesimrank (ITER);} public int2learraymap getsimrank (int I) {return scores. get (I);} public int2objectarraymap getsimrank () {return scores;} public double getsimrank (int I, Int J) {return scores. get (I ). get (j);} public void computesimrank (int iter) {// initialize int numnodes = graph. numnodes (); this. scores = new int2objectarraymap <int2doublearraymap> (numnodes); For (INT I = 0; I <numnodes; I ++) {int2doublearraymap aux = new int2doublearraymap (numnodes ); for (Int J = 0; j <numnodes; j ++) {if (I = J) Aux. put (J, 1); else aux. put (J, 0);} scores. put (I, AUX);} // while (ITER --> 0) for Iterative Computing {for (INT I = 0; I <numnodes; I ++) {int numinneighborsi = igraph. outdegree (I); If (numinneighborsi = 0) continue; int [] inneighborsi = igraph. successorarray (I); int2doublearraymap rimap = scores. get (I); For (Int J = 0; j <numnodes; j ++) {int numinneighborsj = igraph. outdegree (j); If (numinneighborsj = 0) continue; int [] inneighborsj = igraph. successorarray (j); double Rab = 0; For (int A: inneighborsi) {int2doublearraymap aux = scores. get (a); For (int B: inneighborsj) {Rab + = aux. get (B) ;}} Rab * = dampening/(numinneighborsi * numinneighborsj); rimap. put (J, Rab );}}}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.