17 template <
class PGraph>
int GetNodeEcc(
const PGraph& Graph,
const int& NId,
const bool& IsDir=
false);
45 template<
class PGraph>
void GetPageRank(
const PGraph& Graph,
TIntFltH& PRankH,
const double& C=0.85,
const double& Eps=1e-4,
const int& MaxIter=100);
48 template<
class PGraph>
void GetHits(
const PGraph& Graph,
TIntFltH& NIdHubH,
TIntFltH& NIdAuthH,
const int& MaxIter=20);
52 template <
class PGraph>
53 int GetNodeEcc(
const PGraph& Graph,
const int& NId,
const bool& IsDir) {
74 template<
class PGraph>
75 void GetPageRank(
const PGraph& Graph,
TIntFltH& PRankH,
const double& C,
const double& Eps,
const int& MaxIter) {
76 const int NNodes = Graph->GetNodes();
79 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
80 PRankH.
AddDat(NI.GetId(), 1.0/NNodes);
84 for (
int iter = 0; iter < MaxIter; iter++) {
86 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++, j++) {
88 for (
int e = 0; e < NI.GetInDeg(); e++) {
89 const int InNId = NI.GetInNId(e);
90 const int OutDeg = Graph->GetNI(InNId).GetOutDeg();
92 TmpV[j] += PRankH.
GetDat(InNId) / OutDeg; }
97 double diff=0, sum=0, NewVal;
98 for (
int i = 0; i < TmpV.
Len(); i++) { sum += TmpV[i]; }
99 const double Leaked = (1.0-sum) /
double(NNodes);
100 for (
int i = 0; i < PRankH.
Len(); i++) {
101 NewVal = TmpV[i] + Leaked;
103 diff += fabs(NewVal-PRankH[i]);
106 if (diff < Eps) {
break; }
110 template<
class PGraph>
112 const int NNodes = Graph->GetNodes();
114 NIdAuthH.
Gen(NNodes);
115 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
116 NIdHubH.
AddDat(NI.GetId(), 1.0);
117 NIdAuthH.
AddDat(NI.GetId(), 1.0);
120 for (
int iter = 0; iter < MaxIter; iter++) {
123 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
124 double& Auth = NIdAuthH.
GetDat(NI.GetId()).Val;
126 for (
int e = 0; e < NI.GetInDeg(); e++) {
127 Auth += NIdHubH.
GetDat(NI.GetInNId(e)); }
131 for (
int i = 0; i < NIdAuthH.
Len(); i++) { NIdAuthH[i] /= Norm; }
133 for (
typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
134 double& Hub = NIdHubH.
GetDat(NI.GetId()).Val;
136 for (
int e = 0; e < NI.GetOutDeg(); e++) {
137 Hub += NIdAuthH.
GetDat(NI.GetOutNId(e)); }
141 for (
int i = 0; i < NIdHubH.
Len(); i++) { NIdHubH[i] /= Norm; }
145 for (
int i = 0; i < NIdHubH.
Len(); i++) { Norm +=
TMath::Sqr(NIdHubH[i]); }
147 for (
int i = 0; i < NIdHubH.
Len(); i++) { NIdHubH[i] /= Norm; }
149 for (
int i = 0; i < NIdAuthH.
Len(); i++) { Norm +=
TMath::Sqr(NIdAuthH[i]); }
151 for (
int i = 0; i < NIdAuthH.
Len(); i++) { NIdAuthH[i] /= Norm; }
double GetDegreeCentr(const PUNGraph &Graph, const int &NId)
void GetPageRank(const PGraph &Graph, TIntFltH &PRankH, const double &C=0.85, const double &Eps=1e-4, const int &MaxIter=100)
int DoBfs(const int &StartNode, const bool &FollowOut, const bool &FollowIn, const int &TargetNId=-1, const int &MxDist=TInt::Mx)
Performs BFS from node id StartNode for at maps MxDist steps by only following in-links (parameter Fo...
TSizeTy Len() const
Returns the number of elements in the vector.
void GetBetweennessCentr(const PUNGraph &Graph, const TIntV &BtwNIdV, TIntFltH &NodeBtwH, const bool &DoNodeCent, TIntPrFltH &EdgeBtwH, const bool &DoEdgeCent)
const TDat & GetDat(const TKey &Key) const
static double Sqr(const double &x)
void Gen(const int &ExpectVals)
double GetClosenessCentr(const PUNGraph &Graph, const int &NId)
int GetNodeEcc(const PGraph &Graph, const int &NId, const bool &IsDir=false)
void GetHits(const PGraph &Graph, TIntFltH &NIdHubH, TIntFltH &NIdAuthH, const int &MaxIter=20)
double GetFarnessCentr(const PUNGraph &Graph, const int &NId)
void GetEigenVectorCentr(const PUNGraph &Graph, TIntFltH &NIdEigenH, const double &Eps, const int &MaxIter)
TDat & AddDat(const TKey &Key)