Trustrank is a biased PageRank method, which starts from some good seeds to propagate trust. It is very easy to implement based on PageRank.
I implement it in Java using the webgraph and Law jar package, following is the code:
/*
* Trustrank implement
*/
PackageCn.edu. dlut. wisdom;
ImportIt. unimi. DSI. law. Rank. PageRank;
ImportIt. unimi. DSI. law. Rank. pagerankpowermethod;
ImportIt. unimi. DSI. law. Rank. PageRank. iterationnumberstoppingcriterion;
ImportIt. unimi. DSI. law. Rank. PageRank. normdeltastoppingcriterion;
ImportIt. unimi. DSI. webgraph .*;
ImportIt. unimi. DSI. fastutil. Doubles .*;
ImportIt. unimi. DSI. fastutil. ints. intset;
/**
*
* @ Author you Wang
*/
Public ClassTrustrank {
/**
* Graph on which tr will run
*/
PrivateImmutablegraph g;
/**
* PageRank implementation
*/
PrivatePagerankpowermethod PR;
/**
* To be used as stopping Criterion
*/
Private DoubleThreshold = PageRank. default_threshold;
/**
* Number of iteration
*/
Private IntNumberofiteration = PageRank. default_max_iter;
Private DoubleAlpha = PageRank. default_alpha;
/**
*
* @ Param g graph on which tr will run
*/
PublicTrustrank (immutablegraph g ){
This. G = g;
PR =NewPagerankpowermethod (g );
}
Public VoidSetthreshold (DoubleT ){
Threshold = T;
}
Public VoidSetalpha (DoubleAlpha ){
This. Alpha = Alpha;
}
Public VoidSetiteration (IntN ){
Numberofiteration = N;
}
Public Double[] Getrank (){
ReturnPr. rank;
}
/**
* Set the biased good seeds
* @ Param Seeds
*/
Public VoidSetgoodseeds (intset seeds ){
IntNumnodes = G. numnodes ();
Double[] Arr =New Double[Numnodes];
IntSeedsize = seeds. Size ();
For(IntI = 0; I <numnodes; I ++)
If(Seeds. Contains (I ))
Arr [I] = 1/seedsize;
Pr. Start = doublearraylist. Wrap (ARR );
}
/**
* Compute the tr scores
* @ Throws exception
*/
Public VoidCompute ()ThrowsException {
Pr. Alpha = Alpha;
Pr. stepuntil (PageRank. Or (NewNormdeltastoppingcriterion (threshold ),
NewIterationnumberstoppingcriterion (numberofiteration )));
}
}
If you hava any question, please just put a review, or contact me by e-mail.