SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TKronMomentsFit Class Reference

#include <kronecker.h>

Public Member Functions

 TKronMomentsFit (const PUNGraph &G)
 
TFltQu EstABC (const int &R)
 

Static Public Member Functions

static void Test ()
 

Public Attributes

double Edges
 
double Hairpins
 
double Tripins
 
double Triads
 

Detailed Description

Definition at line 303 of file kronecker.h.

Constructor & Destructor Documentation

TKronMomentsFit::TKronMomentsFit ( const PUNGraph G)
inline

Definition at line 307 of file kronecker.h.

307  {
308  Edges=0; Hairpins=0; Tripins=0; Triads=0;
309  for (TUNGraph::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) {
310  const int d = NI.GetOutDeg();
311  Edges += d;
312  Hairpins += d*(d-1.0);
313  Tripins += d*(d-1.0)*(d-2.0);
314  }
315  Edges /= 2.0;
316  Hairpins /= 2.0;
317  Tripins /= 6.0;
318  int64 ot,ct;
319  Triads = (int) TSnap::GetTriads(G, ot, ct)/3.0;
320  printf("E:%g\tH:%g\tT:%g\tD:%g\n", Edges, Hairpins, Tripins, Triads);
321  }
int64 GetTriads(const PGraph &Graph, int64 &ClosedTriads, int64 &OpenTriads, int SampleNodes=-1)
Computes the number of Closed and Open triads.
Definition: triad.h:211
Node iterator. Only forward iteration (operator++) is supported.
Definition: graph.h:64
double Tripins
Definition: kronecker.h:305
double Hairpins
Definition: kronecker.h:305
long long int64
Definition: bd.h:27
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
Definition: graph.h:211
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
Definition: graph.h:209

Member Function Documentation

TFltQu TKronMomentsFit::EstABC ( const int &  R)
inline

Definition at line 323 of file kronecker.h.

323  {
324  const double Step = 0.01;
325  double MinScore=TFlt::Mx;
326  double A=0, B=0, C=0;
327  //Edges=log(Edges); Hairpins=log(Hairpins); Tripins=log(Tripins); Triads=log(Triads);
328  for (double a = 1.0; a > Step; a-=Step) {
329  for (double b = Step; b <= 1.0; b+=Step) {
330  for (double c = Step; c <= a; c+=Step) {
331  double EE = ( pow(a+2*b+c, R) - pow(a+c, R) ) / 2.0;
332  double EH = ( pow(pow(a+b,2) + pow(b+c,2), R)
333  -2*pow(a*(a+b)+c*(c+b), R)
334  -pow(a*a + 2*b*b + c*c, R)
335  +2*pow(a*a + c*c, R) ) / 2.0;
336  double ET = ( pow(pow(a+b,3)+pow(b+c,3), R)
337  -3*pow(a*pow(a+b,2)+c*pow(b+c,2), R)
338  -3*pow(a*a*a + c*c*c + b*(a*a+c*c) + b*b*(a+c) + 2*b*b*b ,R)
339  +2*pow(a*a*a + 2*b*b*b + c*c*c, R)
340  +5*pow(a*a*a + c*c*c + b*b*(a+c), R)
341  +4*pow(a*a*a + c*c*c + b*(a*a+c*c), R)
342  -6*pow(a*a*a + c*c*c, R) ) / 6.0;
343  double ED = ( pow(a*a*a + 3*b*b*(a+c) + c*c*c, R)
344  -3*pow(a*(a*a+b*b) + c*(b*b+c*c), R)
345  +2*pow(a*a*a+c*c*c, R) ) / 6.0;
346  if (EE < 0) { EE = 1; }
347  if (EH < 0) { EH = 1; }
348  if (ET < 0) { ET = 1; }
349  if (ED < 0) { ED = 1; }
350  //EE=log(EE); EH=log(EH); ET=log(ET); ED=log(ED);
351  double Score = pow(Edges-EE,2)/EE + pow(Hairpins-EH ,2)/EH + pow(Tripins-ET, 2)/ET + pow(Triads-ED, 2)/ED;
352  //double Score = fabs(Edges-EE)/EE + fabs(Hairpins-EH)/EH + fabs(Tripins-ET)/ET + fabs(Triads-ED)/ED;
353  //double Score = log(pow(Edges-EE,2)/EE) + log(pow(Hairpins-EH,2)/EH) + log(pow(Tripins-ET, 2)/ET) + log(pow(Triads-ED, 2)/ED);
354  if (MinScore > Score || (a==0.9 && b==0.6 && c==0.2) || (TMath::IsInEps(a-0.99,1e-6) && TMath::IsInEps(b-0.57,1e-6) && TMath::IsInEps(c-0.05,1e-6)))
355  {
356  printf("%.03f %.03f %0.03f %10.4f %10.10g\t%10.10g\t%10.10g\t%10.10g\n", a,b,c, log10(Score), EE, EH, ET, ED);
357  //printf("%.03f %.03f %0.03f %g\n", a,b,c, log(Score));
358  A=a; B=b; C=c; MinScore=Score;
359  }
360  }
361  }
362  }
363  printf("\t\t\t %10.10g\t%10.10g\t%10.10g\t%10.10g\n", Edges, Hairpins, Tripins, Triads);
364  return TFltQu(A,B,C,MinScore);
365  }
double Tripins
Definition: kronecker.h:305
static const double Mx
Definition: dt.h:1298
TQuad< TFlt, TFlt, TFlt, TFlt > TFltQu
Definition: ds.h:263
static bool IsInEps(const T &Val, const T &Eps)
Definition: xmath.h:83
double Hairpins
Definition: kronecker.h:305
static void TKronMomentsFit::Test ( )
inlinestatic

Definition at line 367 of file kronecker.h.

367  {
368  TFIn FIn("as20.ngraph");
369  PUNGraph G = TSnap::ConvertGraph<PUNGraph>(TNGraph::Load(FIn));
370  //PUNGraph G = TKronMtx::GenFastKronecker(TKronMtx::GetMtx("0.9, 0.6; 0.6, 0.2"), 14, false, 0)->GetUNGraph();
371  //PUNGraph G = TUNGraph::GetSmallGraph();
372  TSnap::PrintInfo(G);
374  TSnap::PrintInfo(G);
375  TKronMomentsFit Fit(G);
376  printf("iter %d\n", TKronMtx::GetKronIter(G->GetNodes(), 2));
377  Fit.EstABC(TKronMtx::GetKronIter(G->GetNodes(), 2)); //*/
378  }
int GetKronIter(const int &Nodes) const
Definition: kronecker.cpp:127
Definition: fl.h:275
int GetNodes() const
Returns the number of nodes in the graph.
Definition: graph.h:168
static PNGraph Load(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
Definition: graph.h:431
void DelSelfEdges(const PGraph &Graph)
Removes all the self-edges from the graph.
Definition: alg.h:419
void PrintInfo(const PGraph &Graph, const TStr &Desc="", const TStr &OutFNm="", const bool &Fast=true)
Prints basic graph statistics.
Definition: gbase.h:87

Member Data Documentation

double TKronMomentsFit::Edges

Definition at line 305 of file kronecker.h.

double TKronMomentsFit::Hairpins

Definition at line 305 of file kronecker.h.

double TKronMomentsFit::Triads

Definition at line 305 of file kronecker.h.

double TKronMomentsFit::Tripins

Definition at line 305 of file kronecker.h.


The documentation for this class was generated from the following file: