SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
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
TKronMtx Class Reference

#include <kronecker.h>

Collaboration diagram for TKronMtx:

Public Member Functions

 TKronMtx ()
 
 TKronMtx (const int &Dim)
 
 TKronMtx (const TFltV &SeedMatrix)
 
 TKronMtx (const TKronMtx &Kronecker)
 
void SaveTxt (const TStr &OutFNm) const
 
TKronMtxoperator= (const TKronMtx &Kronecker)
 
bool operator== (const TKronMtx &Kronecker) const
 
int GetPrimHashCd () const
 
int GetSecHashCd () const
 
int GetDim () const
 
int Len () const
 
bool Empty () const
 
bool IsProbMtx () const
 
TFltVGetMtx ()
 
const TFltVGetMtx () const
 
void SetMtx (const TFltV &ParamV)
 
void SetRndMtx (const int &MtxDim, const double &MinProb=0.0)
 
void PutAllMtx (const double &Val)
 
void GenMtx (const int &Dim)
 
void SetEpsMtx (const double &Eps1, const double &Eps0, const int &Eps1Val=1, const int &Eps0Val=0)
 
void SetForEdges (const int &Nodes, const int &Edges)
 
void AddRndNoise (const double &SDev)
 
TStr GetMtxStr () const
 
const double & At (const int &Row, const int &Col) const
 
double & At (const int &Row, const int &Col)
 
const double & At (const int &ValN) const
 
double & At (const int &ValN)
 
int GetNodes (const int &NIter) const
 
int GetEdges (const int &NIter) const
 
int GetKronIter (const int &Nodes) const
 
int GetNZeroK (const PNGraph &Graph) const
 
double GetEZero (const int &Edges, const int &KronIter) const
 
double GetMtxSum () const
 
double GetRowSum (const int &RowId) const
 
double GetColSum (const int &ColId) const
 
void ToOneMinusMtx ()
 
void GetLLMtx (TKronMtx &LLMtx)
 
void GetProbMtx (TKronMtx &ProbMtx)
 
void Swap (TKronMtx &KronMtx)
 
double GetEdgeProb (int NId1, int NId2, const int &NKronIters) const
 
double GetNoEdgeProb (int NId1, int NId2, const int &NKronIters) const
 
double GetEdgeLL (int NId1, int NId2, const int &NKronIters) const
 
double GetNoEdgeLL (int NId1, int NId2, const int &NKronIters) const
 
double GetApxNoEdgeLL (int NId1, int NId2, const int &NKronIters) const
 
bool IsEdgePlace (int NId1, int NId2, const int &NKronIters, const double &ProbTresh) const
 
double GetEdgeDLL (const int &ParamId, int NId1, int NId2, const int &NKronIters) const
 
double GetNoEdgeDLL (const int &ParamId, int NId1, int NId2, const int &NKronIters) const
 
double GetApxNoEdgeDLL (const int &ParamId, int NId1, int NId2, const int &NKronIters) const
 
double GetEdgeProb (const uint &NId1Sig, const uint &NId2Sig, const int &NIter) const
 
PNGraph GenThreshGraph (const double &Thresh) const
 
PNGraph GenRndGraph (const double &RndFact=1.0) const
 
void Dump (const TStr &MtxNm=TStr(), const bool &Sort=false) const
 

Static Public Member Functions

static uint GetNodeSig (const double &OneProb=0.5)
 
static int GetKronIter (const int &GNodes, const int &SeedMtxSz)
 
static PNGraph GenKronecker (const TKronMtx &SeedMtx, const int &NIter, const bool &IsDir, const int &Seed=0)
 
static PNGraph GenFastKronecker (const TKronMtx &SeedMtx, const int &NIter, const bool &IsDir, const int &Seed=0)
 
static PNGraph GenFastKronecker (const TKronMtx &SeedMtx, const int &NIter, const int &Edges, const bool &IsDir, const int &Seed=0)
 
static PNGraph GenDetKronecker (const TKronMtx &SeedMtx, const int &NIter, const bool &IsDir)
 
static void PlotCmpGraphs (const TKronMtx &SeedMtx, const PNGraph &Graph, const TStr &OutFNm, const TStr &Desc)
 
static void PlotCmpGraphs (const TKronMtx &SeedMtx1, const TKronMtx &SeedMtx2, const PNGraph &Graph, const TStr &OutFNm, const TStr &Desc)
 
static void PlotCmpGraphs (const TVec< TKronMtx > &SeedMtxV, const PNGraph &Graph, const TStr &FNmPref, const TStr &Desc)
 
static void KronMul (const TKronMtx &LeftPt, const TKronMtx &RightPt, TKronMtx &OutMtx)
 
static void KronSum (const TKronMtx &LeftPt, const TKronMtx &RightPt, TKronMtx &OutMtx)
 
static void KronPwr (const TKronMtx &KronPt, const int &NIter, TKronMtx &OutMtx)
 
static double GetAvgAbsErr (const TKronMtx &Kron1, const TKronMtx &Kron2)
 
static double GetAvgFroErr (const TKronMtx &Kron1, const TKronMtx &Kron2)
 
static TKronMtx GetMtx (TStr MatlabMtxStr)
 
static TKronMtx GetRndMtx (const int &Dim, const double &MinProb)
 
static TKronMtx GetInitMtx (const int &Dim, const int &Nodes, const int &Edges)
 
static TKronMtx GetInitMtx (const TStr &MtxStr, const int &Dim, const int &Nodes, const int &Edges)
 
static TKronMtx GetMtxFromNm (const TStr &MtxNm)
 
static TKronMtx LoadTxt (const TStr &MtxFNm)
 
static void PutRndSeed (const int &Seed)
 

Static Public Attributes

static const double NInf = -DBL_MAX
 
static TRnd Rnd = TRnd(0)
 

Private Attributes

TInt MtxDim
 
TFltV SeedMtx
 

Detailed Description

Definition at line 11 of file kronecker.h.

Constructor & Destructor Documentation

TKronMtx::TKronMtx ( )
inline

Definition at line 19 of file kronecker.h.

Referenced by GetMtxFromNm().

19 : MtxDim(-1), SeedMtx() { }
TInt MtxDim
Definition: kronecker.h:16
TFltV SeedMtx
Definition: kronecker.h:17

Here is the caller graph for this function:

TKronMtx::TKronMtx ( const int &  Dim)
inline

Definition at line 20 of file kronecker.h.

20 : MtxDim(Dim), SeedMtx(Dim*Dim) { }
TInt MtxDim
Definition: kronecker.h:16
TFltV SeedMtx
Definition: kronecker.h:17
TKronMtx::TKronMtx ( const TFltV SeedMatrix)

Definition at line 9 of file kronecker.cpp.

References IAssert, TVec< TVal, TSizeTy >::Len(), MtxDim, and SeedMtx.

9  : SeedMtx(SeedMatrix) {
10  MtxDim = (int) sqrt((double)SeedMatrix.Len());
12 }
#define IAssert(Cond)
Definition: bd.h:262
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TInt MtxDim
Definition: kronecker.h:16
TFltV SeedMtx
Definition: kronecker.h:17

Here is the call graph for this function:

TKronMtx::TKronMtx ( const TKronMtx Kronecker)
inline

Definition at line 22 of file kronecker.h.

22 : MtxDim(Kronecker.MtxDim), SeedMtx(Kronecker.SeedMtx) { }
TInt MtxDim
Definition: kronecker.h:16
TFltV SeedMtx
Definition: kronecker.h:17

Member Function Documentation

void TKronMtx::AddRndNoise ( const double &  SDev)

Definition at line 69 of file kronecker.cpp.

References At(), Dump(), TRnd::GetNrmDev(), Len(), and Rnd.

Referenced by GetInitMtx().

69  {
70  Dump("before");
71  double NewVal;
72  int c =0;
73  for (int i = 0; i < Len(); i++) {
74  for(c = 0; ((NewVal = At(i)*Rnd.GetNrmDev(1, SDev, 0.8, 1.2)) < 0.01 || NewVal>0.99) && c <1000; c++) { }
75  if (c < 999) { At(i) = NewVal; } else { printf("XXXXX\n"); }
76  }
77  Dump("after");
78 }
static TRnd Rnd
Definition: kronecker.h:14
int Len() const
Definition: kronecker.h:31
void Dump(const TStr &MtxNm=TStr(), const bool &Sort=false) const
Definition: kronecker.cpp:636
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
double GetNrmDev()
Definition: dt.cpp:63

Here is the call graph for this function:

Here is the caller graph for this function:

double& TKronMtx::At ( const int &  Row,
const int &  Col 
)
inline

Definition at line 47 of file kronecker.h.

References MtxDim, and SeedMtx.

47 { return SeedMtx[MtxDim*Row+Col].Val; }
TInt MtxDim
Definition: kronecker.h:16
TFltV SeedMtx
Definition: kronecker.h:17
const double& TKronMtx::At ( const int &  ValN) const
inline

Definition at line 48 of file kronecker.h.

References SeedMtx.

48 { return SeedMtx[ValN].Val; }
TFltV SeedMtx
Definition: kronecker.h:17
double& TKronMtx::At ( const int &  ValN)
inline

Definition at line 49 of file kronecker.h.

References SeedMtx.

49 { return SeedMtx[ValN].Val; }
TFltV SeedMtx
Definition: kronecker.h:17
void TKronMtx::Dump ( const TStr MtxNm = TStr(),
const bool &  Sort = false 
) const

Definition at line 636 of file kronecker.cpp.

References TStr::CStr(), TStr::Empty(), GetDim(), TVec< TVal, TSizeTy >::Len(), SeedMtx, and TVec< TVal, TSizeTy >::Sort().

Referenced by AddRndNoise(), TKroneckerLL::GradDescent(), TKroneckerLL::GradDescent2(), TKroneckerLL::GradDescentConvergence(), TKroneckerLL::RunMStep(), TKroneckerLL::TestBicCriterion(), TKroneckerLL::TestKronDescent(), and TKroneckerLL::TestSamplePerm().

636  {
637  /*printf("%s: %d x %d\n", MtxNm.Empty()?"Mtx":MtxNm.CStr(), GetDim(), GetDim());
638  for (int r = 0; r < GetDim(); r++) {
639  for (int c = 0; c < GetDim(); c++) { printf(" %8.2g", At(r, c)); }
640  printf("\n");
641  }*/
642  if (! MtxNm.Empty()) printf("%s\n", MtxNm.CStr());
643  double Sum=0.0;
644  TFltV ValV = SeedMtx;
645  if (Sort) { ValV.Sort(false); }
646  for (int i = 0; i < ValV.Len(); i++) {
647  printf(" %10.4g", ValV[i]());
648  Sum += ValV[i];
649  if ((i+1) % GetDim() == 0) { printf("\n"); }
650  }
651  printf(" (sum:%.4f)\n", Sum);
652 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1318
int GetDim() const
Definition: kronecker.h:30
bool Empty() const
Definition: dt.h:488
TFltV SeedMtx
Definition: kronecker.h:17
char * CStr()
Definition: dt.h:476

Here is the call graph for this function:

Here is the caller graph for this function:

bool TKronMtx::Empty ( ) const
inline

Definition at line 32 of file kronecker.h.

References TVec< TVal, TSizeTy >::Empty(), and SeedMtx.

Referenced by TKroneckerLL::GradDescentConvergence(), and TKroneckerLL::TestSamplePerm().

32 { return SeedMtx.Empty(); }
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:570
TFltV SeedMtx
Definition: kronecker.h:17

Here is the call graph for this function:

Here is the caller graph for this function:

PNGraph TKronMtx::GenDetKronecker ( const TKronMtx SeedMtx,
const int &  NIter,
const bool &  IsDir 
)
static

Definition at line 458 of file kronecker.cpp.

References TNGraph::AddEdge(), TNGraph::AddNode(), GetNodes(), TRnd::GetUniDev(), IsEdgePlace(), TNGraph::New(), Rnd, and SeedMtx.

458  {
459  const TKronMtx& SeedGraph = SeedMtx;
460  const int NNodes = SeedGraph.GetNodes(NIter);
461  printf(" Deterministic Kronecker: %d nodes, %s...\n", NNodes, IsDir ? "Directed":"UnDirected");
462  PNGraph Graph = TNGraph::New(NNodes, -1);
463  TExeTm ExeTm;
464  int edges = 0;
465  for (int node1 = 0; node1 < NNodes; node1++) { Graph->AddNode(node1); }
466 
467  for (int node1 = 0; node1 < NNodes; node1++) {
468  for (int node2 = 0; node2 < NNodes; node2++) {
469  if (SeedGraph.IsEdgePlace(node1, node2, NIter, Rnd.GetUniDev())) {
470  Graph->AddEdge(node1, node2);
471  edges++;
472  }
473  }
474  if (node1 % 1000 == 0) printf("\r...%dk, %dk", node1/1000, edges/1000);
475  }
476  return Graph;
477 }
static TRnd Rnd
Definition: kronecker.h:14
Definition: tm.h:355
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
Definition: graph.h:477
bool IsEdgePlace(int NId1, int NId2, const int &NKronIters, const double &ProbTresh) const
Definition: kronecker.cpp:196
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
Definition: graph.cpp:236
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the graph.
Definition: graph.cpp:321
double GetUniDev()
Definition: dt.h:30
int GetNodes(const int &NIter) const
Definition: kronecker.cpp:119
TFltV SeedMtx
Definition: kronecker.h:17

Here is the call graph for this function:

PNGraph TKronMtx::GenFastKronecker ( const TKronMtx SeedMtx,
const int &  NIter,
const bool &  IsDir,
const int &  Seed = 0 
)
static

Definition at line 349 of file kronecker.cpp.

References TVec< TVal, TSizeTy >::Add(), TNGraph::AddEdge(), TNGraph::AddNode(), At(), GetDim(), GetEdges(), TNGraph::GetEdges(), GetMtxSum(), GetNodes(), TRnd::GetUniDev(), TNGraph::IsEdge(), MtxDim, TNGraph::New(), Rnd, and SeedMtx.

Referenced by TKroneckerLL::GradDescentConvergence(), PlotCmpGraphs(), TKronMaxLL::Test(), and TKroneckerLL::TestGradDescent().

349  {
350  const TKronMtx& SeedGraph = SeedMtx;
351  const int MtxDim = SeedGraph.GetDim();
352  const double MtxSum = SeedGraph.GetMtxSum();
353  const int NNodes = SeedGraph.GetNodes(NIter);
354  const int NEdges = SeedGraph.GetEdges(NIter);
355  //const double DiagEdges = NNodes * pow(SeedGraph.At(0,0), double(NIter));
356  //const int NEdges = (int) TMath::Round(((pow(double(SeedGraph.GetMtxSum()), double(NIter)) - DiagEdges) /2.0));
357  printf(" FastKronecker: %d nodes, %d edges, %s...\n", NNodes, NEdges, IsDir ? "Directed":"UnDirected");
358  PNGraph Graph = TNGraph::New(NNodes, -1);
359  TRnd Rnd(Seed);
360  TExeTm ExeTm;
361  // prepare cell probability vector
362  TVec<TFltIntIntTr> ProbToRCPosV; // row, col position
363  double CumProb = 0.0;
364  for (int r = 0; r < MtxDim; r++) {
365  for (int c = 0; c < MtxDim; c++) {
366  const double Prob = SeedGraph.At(r, c);
367  if (Prob > 0.0) {
368  CumProb += Prob;
369  ProbToRCPosV.Add(TFltIntIntTr(CumProb/MtxSum, r, c));
370  }
371  }
372  }
373  // add nodes
374  for (int i = 0; i < NNodes; i++) {
375  Graph->AddNode(i); }
376  // add edges
377  int Rng, Row, Col, Collision=0, n = 0;
378  for (int edges = 0; edges < NEdges; ) {
379  Rng=NNodes; Row=0; Col=0;
380  for (int iter = 0; iter < NIter; iter++) {
381  const double& Prob = Rnd.GetUniDev();
382  n = 0; while(Prob > ProbToRCPosV[n].Val1) { n++; }
383  const int MtxRow = ProbToRCPosV[n].Val2;
384  const int MtxCol = ProbToRCPosV[n].Val3;
385  Rng /= MtxDim;
386  Row += MtxRow * Rng;
387  Col += MtxCol * Rng;
388  }
389  if (! Graph->IsEdge(Row, Col)) { // allow self-loops
390  Graph->AddEdge(Row, Col); edges++;
391  if (! IsDir) {
392  if (Row != Col) Graph->AddEdge(Col, Row);
393  edges++;
394  }
395  } else { Collision++; }
396  //if (edges % 1000 == 0) printf("\r...%dk", edges/1000);
397  }
398  //printf(" %d edges [%s]\n", Graph->GetEdges(), ExeTm.GetTmStr());
399  printf(" collisions: %d (%.4f)\n", Collision, Collision/(double)Graph->GetEdges());
400  return Graph;
401 }
static TRnd Rnd
Definition: kronecker.h:14
int GetEdges(const int &NIter) const
Definition: kronecker.cpp:123
Definition: tm.h:355
double GetMtxSum() const
Definition: kronecker.cpp:140
Definition: dt.h:11
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
Definition: graph.h:477
int GetEdges() const
Returns the number of edges in the graph.
Definition: graph.cpp:313
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
Definition: graph.cpp:236
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
TInt MtxDim
Definition: kronecker.h:16
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the graph.
Definition: graph.cpp:321
bool IsEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true) const
Tests whether an edge from node IDs SrcNId to DstNId exists in the graph.
Definition: graph.cpp:363
int GetDim() const
Definition: kronecker.h:30
double GetUniDev()
Definition: dt.h:30
int GetNodes(const int &NIter) const
Definition: kronecker.cpp:119
TFltV SeedMtx
Definition: kronecker.h:17
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
TTriple< TFlt, TInt, TInt > TFltIntIntTr
Definition: ds.h:182
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:430

Here is the call graph for this function:

Here is the caller graph for this function:

PNGraph TKronMtx::GenFastKronecker ( const TKronMtx SeedMtx,
const int &  NIter,
const int &  Edges,
const bool &  IsDir,
const int &  Seed = 0 
)
static

Definition at line 404 of file kronecker.cpp.

References TVec< TVal, TSizeTy >::Add(), TNGraph::AddEdge(), TNGraph::AddNode(), At(), GetDim(), TNGraph::GetEdges(), GetMtxSum(), GetNodes(), TRnd::GetUniDev(), TNGraph::IsEdge(), MtxDim, TNGraph::New(), Rnd, and SeedMtx.

404  {
405  const TKronMtx& SeedGraph = SeedMtx;
406  const int MtxDim = SeedGraph.GetDim();
407  const double MtxSum = SeedGraph.GetMtxSum();
408  const int NNodes = SeedGraph.GetNodes(NIter);
409  const int NEdges = Edges;
410  //const double DiagEdges = NNodes * pow(SeedGraph.At(0,0), double(NIter));
411  //const int NEdges = (int) TMath::Round(((pow(double(SeedGraph.GetMtxSum()), double(NIter)) - DiagEdges) /2.0));
412  printf(" RMat Kronecker: %d nodes, %d edges, %s...\n", NNodes, NEdges, IsDir ? "Directed":"UnDirected");
413  PNGraph Graph = TNGraph::New(NNodes, -1);
414  TRnd Rnd(Seed);
415  TExeTm ExeTm;
416  // prepare cell probability vector
417  TVec<TFltIntIntTr> ProbToRCPosV; // row, col position
418  double CumProb = 0.0;
419  for (int r = 0; r < MtxDim; r++) {
420  for (int c = 0; c < MtxDim; c++) {
421  const double Prob = SeedGraph.At(r, c);
422  if (Prob > 0.0) {
423  CumProb += Prob;
424  ProbToRCPosV.Add(TFltIntIntTr(CumProb/MtxSum, r, c));
425  }
426  }
427  }
428  // add nodes
429  for (int i = 0; i < NNodes; i++) {
430  Graph->AddNode(i); }
431  // add edges
432  int Rng, Row, Col, Collision=0, n = 0;
433  for (int edges = 0; edges < NEdges; ) {
434  Rng=NNodes; Row=0; Col=0;
435  for (int iter = 0; iter < NIter; iter++) {
436  const double& Prob = Rnd.GetUniDev();
437  n = 0; while(Prob > ProbToRCPosV[n].Val1) { n++; }
438  const int MtxRow = ProbToRCPosV[n].Val2;
439  const int MtxCol = ProbToRCPosV[n].Val3;
440  Rng /= MtxDim;
441  Row += MtxRow * Rng;
442  Col += MtxCol * Rng;
443  }
444  if (! Graph->IsEdge(Row, Col)) { // allow self-loops
445  Graph->AddEdge(Row, Col); edges++;
446  if (! IsDir) {
447  if (Row != Col) Graph->AddEdge(Col, Row);
448  edges++;
449  }
450  } else { Collision++; }
451  //if (edges % 1000 == 0) printf("\r...%dk", edges/1000);
452  }
453  //printf(" %d edges [%s]\n", Graph->GetEdges(), ExeTm.GetTmStr());
454  printf(" collisions: %d (%.4f)\n", Collision, Collision/(double)Graph->GetEdges());
455  return Graph;
456 }
static TRnd Rnd
Definition: kronecker.h:14
Definition: tm.h:355
double GetMtxSum() const
Definition: kronecker.cpp:140
Definition: dt.h:11
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
Definition: graph.h:477
int GetEdges() const
Returns the number of edges in the graph.
Definition: graph.cpp:313
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
Definition: graph.cpp:236
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
TInt MtxDim
Definition: kronecker.h:16
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the graph.
Definition: graph.cpp:321
bool IsEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true) const
Tests whether an edge from node IDs SrcNId to DstNId exists in the graph.
Definition: graph.cpp:363
int GetDim() const
Definition: kronecker.h:30
double GetUniDev()
Definition: dt.h:30
int GetNodes(const int &NIter) const
Definition: kronecker.cpp:119
TFltV SeedMtx
Definition: kronecker.h:17
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
TTriple< TFlt, TInt, TInt > TFltIntIntTr
Definition: ds.h:182
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:430

Here is the call graph for this function:

PNGraph TKronMtx::GenKronecker ( const TKronMtx SeedMtx,
const int &  NIter,
const bool &  IsDir,
const int &  Seed = 0 
)
static

Definition at line 312 of file kronecker.cpp.

References TNGraph::AddEdge(), TNGraph::AddNode(), TNGraph::GetEdges(), GetNodes(), TExeTm::GetTmStr(), TRnd::GetUniDev(), IsEdgePlace(), TNGraph::New(), Rnd, and SeedMtx.

Referenced by PlotCmpGraphs().

312  {
313  const TKronMtx& SeedGraph = SeedMtx;
314  const int NNodes = SeedGraph.GetNodes(NIter);
315  printf(" Kronecker: %d nodes, %s...\n", NNodes, IsDir ? "Directed":"UnDirected");
316  PNGraph Graph = TNGraph::New(NNodes, -1);
317  TExeTm ExeTm;
318  TRnd Rnd(Seed);
319  int edges = 0;
320  for (int node1 = 0; node1 < NNodes; node1++) {
321  Graph->AddNode(node1); }
322  if (IsDir) {
323  for (int node1 = 0; node1 < NNodes; node1++) {
324  for (int node2 = 0; node2 < NNodes; node2++) {
325  if (SeedGraph.IsEdgePlace(node1, node2, NIter, Rnd.GetUniDev())) {
326  Graph->AddEdge(node1, node2);
327  edges++;
328  }
329  }
330  if (node1 % 1000 == 0) printf("\r...%dk, %dk", node1/1000, edges/1000);
331  }
332  } else {
333  for (int node1 = 0; node1 < NNodes; node1++) {
334  for (int node2 = node1; node2 < NNodes; node2++) {
335  if (SeedGraph.IsEdgePlace(node1, node2, NIter, Rnd.GetUniDev())) {
336  Graph->AddEdge(node1, node2);
337  Graph->AddEdge(node2, node1);
338  edges++;
339  }
340  }
341  if (node1 % 1000 == 0) printf("\r...%dk, %dk", node1/1000, edges/1000);
342  }
343  }
344  printf("\r %d edges [%s]\n", Graph->GetEdges(), ExeTm.GetTmStr());
345  return Graph;
346 }
static TRnd Rnd
Definition: kronecker.h:14
Definition: tm.h:355
Definition: dt.h:11
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
Definition: graph.h:477
int GetEdges() const
Returns the number of edges in the graph.
Definition: graph.cpp:313
bool IsEdgePlace(int NId1, int NId2, const int &NKronIters, const double &ProbTresh) const
Definition: kronecker.cpp:196
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
Definition: graph.cpp:236
const char * GetTmStr() const
Definition: tm.h:370
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the graph.
Definition: graph.cpp:321
double GetUniDev()
Definition: dt.h:30
int GetNodes(const int &NIter) const
Definition: kronecker.cpp:119
TFltV SeedMtx
Definition: kronecker.h:17

Here is the call graph for this function:

Here is the caller graph for this function:

void TKronMtx::GenMtx ( const int &  Dim)
inline

Definition at line 40 of file kronecker.h.

References TVec< TVal, TSizeTy >::Gen(), MtxDim, and SeedMtx.

Referenced by GetLLMtx(), GetProbMtx(), KronMul(), KronSum(), and TKronMaxLL::RoundTheta().

40 { MtxDim=Dim; SeedMtx.Gen(Dim*Dim); }
TInt MtxDim
Definition: kronecker.h:16
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
TFltV SeedMtx
Definition: kronecker.h:17

Here is the call graph for this function:

Here is the caller graph for this function:

PNGraph TKronMtx::GenRndGraph ( const double &  RndFact = 1.0) const

Definition at line 295 of file kronecker.cpp.

References TNGraph::AddEdge(), TNGraph::AddNode(), At(), GetDim(), TRnd::GetUniDev(), and TNGraph::New().

295  {
296  PNGraph Graph = TNGraph::New();
297  for (int i = 0; i < GetDim(); i++) {
298  Graph->AddNode(i); }
299  for (int r = 0; r < GetDim(); r++) {
300  for (int c = 0; c < GetDim(); c++) {
301  if (RndFact * At(r, c) >= TKronMtx::Rnd.GetUniDev()) { Graph->AddEdge(r, c); }
302  }
303  }
304  return Graph;
305 }
static TRnd Rnd
Definition: kronecker.h:14
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
Definition: graph.h:477
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
Definition: graph.cpp:236
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the graph.
Definition: graph.cpp:321
int GetDim() const
Definition: kronecker.h:30
double GetUniDev()
Definition: dt.h:30

Here is the call graph for this function:

PNGraph TKronMtx::GenThreshGraph ( const double &  Thresh) const

Definition at line 283 of file kronecker.cpp.

References TNGraph::AddEdge(), TNGraph::AddNode(), At(), GetDim(), and TNGraph::New().

283  {
284  PNGraph Graph = TNGraph::New();
285  for (int i = 0; i < GetDim(); i++) {
286  Graph->AddNode(i); }
287  for (int r = 0; r < GetDim(); r++) {
288  for (int c = 0; c < GetDim(); c++) {
289  if (At(r, c) >= Thresh) { Graph->AddEdge(r, c); }
290  }
291  }
292  return Graph;
293 }
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
Definition: graph.h:477
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
Definition: graph.cpp:236
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the graph.
Definition: graph.cpp:321
int GetDim() const
Definition: kronecker.h:30

Here is the call graph for this function:

double TKronMtx::GetApxNoEdgeDLL ( const int &  ParamId,
int  NId1,
int  NId2,
const int &  NKronIters 
) const

Definition at line 240 of file kronecker.cpp.

References At(), GetDim(), IAssert, MtxDim, and NInf.

Referenced by TKroneckerLL::CalcApxGraphDLL(), TKroneckerLL::CalcFullApxGraphDLL(), TKroneckerLL::MetroGibbsSampleNext(), TKroneckerLL::NodeDLLDelta(), and TKroneckerLL::UpdateGraphDLL().

240  {
241  const int& ThetaX = ParamId % GetDim();
242  const int& ThetaY = ParamId / GetDim();
243  int ThetaCnt = 0;
244  double DLL = 0;//, LL = 0;
245  for (int level = 0; level < NKronIters; level++) {
246  const int X = NId1 % MtxDim;
247  const int Y = NId2 % MtxDim;
248  const double LVal = At(X, Y); IAssert(LVal > NInf);
249  if (X == ThetaX && Y == ThetaY) {
250  if (ThetaCnt != 0) { DLL += LVal; }
251  ThetaCnt++;
252  } else { DLL += LVal; }
253  //LL += LVal;
254  NId1 /= MtxDim; NId2 /= MtxDim;
255  }
256  //return -ThetaCnt*exp(DLL)*(1.0 + exp(LL)); // -x'/(1+x) WRONG!
257  // deriv = -(ax^(a-1)*y^b..) - a*x^(2a-1)*y^2b..
258  // = - (ax^(a-1)*y^b..) - a*x*(x^(a-1)*y^b..)^2
259  return -ThetaCnt*exp(DLL) - ThetaCnt*exp(At(ThetaX, ThetaY)+2*DLL);
260 }
#define IAssert(Cond)
Definition: bd.h:262
static const double NInf
Definition: kronecker.h:13
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
TInt MtxDim
Definition: kronecker.h:16
int GetDim() const
Definition: kronecker.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

double TKronMtx::GetApxNoEdgeLL ( int  NId1,
int  NId2,
const int &  NKronIters 
) const

Definition at line 191 of file kronecker.cpp.

References GetEdgeLL().

Referenced by TKroneckerLL::CalcApxGraphLL(), TKroneckerLL::MetroGibbsSampleNext(), TKroneckerLL::NodeLLDelta(), and TKroneckerLL::SwapNodesLL().

191  {
192  const double EdgeLL = GetEdgeLL(NId1, NId2, NKronIters);
193  return -exp(EdgeLL) - 0.5*exp(2*EdgeLL);
194 }
double GetEdgeLL(int NId1, int NId2, const int &NKronIters) const
Definition: kronecker.cpp:175

Here is the call graph for this function:

Here is the caller graph for this function:

double TKronMtx::GetAvgAbsErr ( const TKronMtx Kron1,
const TKronMtx Kron2 
)
static

Definition at line 655 of file kronecker.cpp.

References GetMtx(), IAssert, TVec< TVal, TSizeTy >::Len(), and TVec< TVal, TSizeTy >::Sort().

Referenced by TKroneckerLL::GradDescentConvergence(), and TKroneckerLL::TestKronDescent().

655  {
656  TFltV P1 = Kron1.GetMtx();
657  TFltV P2 = Kron2.GetMtx();
658  IAssert(P1.Len() == P2.Len());
659  P1.Sort(); P2.Sort();
660  double delta = 0.0;
661  for (int i = 0; i < P1.Len(); i++) {
662  delta += fabs(P1[i] - P2[i]);
663  }
664  return delta/P1.Len();
665 }
#define IAssert(Cond)
Definition: bd.h:262
TFltV & GetMtx()
Definition: kronecker.h:35
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1318

Here is the call graph for this function:

Here is the caller graph for this function:

double TKronMtx::GetAvgFroErr ( const TKronMtx Kron1,
const TKronMtx Kron2 
)
static

Definition at line 668 of file kronecker.cpp.

References GetMtx(), IAssert, TVec< TVal, TSizeTy >::Len(), and TVec< TVal, TSizeTy >::Sort().

668  {
669  TFltV P1 = Kron1.GetMtx();
670  TFltV P2 = Kron2.GetMtx();
671  IAssert(P1.Len() == P2.Len());
672  P1.Sort(); P2.Sort();
673  double delta = 0.0;
674  for (int i = 0; i < P1.Len(); i++) {
675  delta += pow(P1[i] - P2[i], 2);
676  }
677  return sqrt(delta/P1.Len());
678 }
#define IAssert(Cond)
Definition: bd.h:262
TFltV & GetMtx()
Definition: kronecker.h:35
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1318

Here is the call graph for this function:

double TKronMtx::GetColSum ( const int &  ColId) const

Definition at line 154 of file kronecker.cpp.

References At(), and GetDim().

Referenced by TKroneckerLL::GetFullColLL().

154  {
155  double Sum = 0;
156  for (int r = 0; r < GetDim(); r++) {
157  Sum += At(r, ColId); }
158  return Sum;
159 }
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
int GetDim() const
Definition: kronecker.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

double TKronMtx::GetEdgeDLL ( const int &  ParamId,
int  NId1,
int  NId2,
const int &  NKronIters 
) const

Definition at line 207 of file kronecker.cpp.

References At(), GetDim(), and MtxDim.

Referenced by TKroneckerLL::CalcApxGraphDLL(), TKroneckerLL::CalcFullApxGraphDLL(), TKroneckerLL::CalcGraphDLL(), TKroneckerLL::MetroGibbsSampleNext(), TKroneckerLL::NodeDLLDelta(), and TKroneckerLL::UpdateGraphDLL().

207  {
208  const int ThetaX = ParamId % GetDim();
209  const int ThetaY = ParamId / GetDim();
210  int ThetaCnt = 0;
211  for (int level = 0; level < NKronIters; level++) {
212  if ((NId1 % MtxDim) == ThetaX && (NId2 % MtxDim) == ThetaY) {
213  ThetaCnt++; }
214  NId1 /= MtxDim; NId2 /= MtxDim;
215  }
216  return double(ThetaCnt) / exp(At(ParamId));
217 }
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
TInt MtxDim
Definition: kronecker.h:16
int GetDim() const
Definition: kronecker.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

double TKronMtx::GetEdgeLL ( int  NId1,
int  NId2,
const int &  NKronIters 
) const

Definition at line 175 of file kronecker.cpp.

References At(), MtxDim, and NInf.

Referenced by TKroneckerLL::CalcApxGraphLL(), TKroneckerLL::CalcGraphLL(), GetApxNoEdgeLL(), GetNoEdgeLL(), TKroneckerLL::MetroGibbsSampleNext(), TKroneckerLL::NodeLLDelta(), and TKroneckerLL::SwapNodesLL().

175  {
176  double LL = 0.0;
177  for (int level = 0; level < NKronIters; level++) {
178  const double& LLVal = At(NId1 % MtxDim, NId2 % MtxDim);
179  if (LLVal == NInf) return NInf;
180  LL += LLVal;
181  NId1 /= MtxDim; NId2 /= MtxDim;
182  }
183  return LL;
184 }
static const double NInf
Definition: kronecker.h:13
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
TInt MtxDim
Definition: kronecker.h:16

Here is the call graph for this function:

Here is the caller graph for this function:

double TKronMtx::GetEdgeProb ( int  NId1,
int  NId2,
const int &  NKronIters 
) const

Definition at line 161 of file kronecker.cpp.

References At(), and MtxDim.

Referenced by GetNoEdgeProb().

161  {
162  double Prob = 1.0;
163  for (int level = 0; level < NKronIters; level++) {
164  Prob *= At(NId1 % MtxDim, NId2 % MtxDim);
165  if (Prob == 0.0) { return 0.0; }
166  NId1 /= MtxDim; NId2 /= MtxDim;
167  }
168  return Prob;
169 }
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
TInt MtxDim
Definition: kronecker.h:16

Here is the call graph for this function:

Here is the caller graph for this function:

double TKronMtx::GetEdgeProb ( const uint NId1Sig,
const uint NId2Sig,
const int &  NIter 
) const

Definition at line 271 of file kronecker.cpp.

References Assert, At(), and GetDim().

271  {
272  Assert(GetDim() == 2);
273  double Prob = 1.0;
274  for (int i = 0; i < NIter; i++) {
275  const uint Mask = (1u<<i);
276  const uint Bit1 = NId1Sig & Mask;
277  const uint Bit2 = NId2Sig & Mask;
278  Prob *= At(int(Bit1!=0), int(Bit2!=0));
279  }
280  return Prob;
281 }
unsigned int uint
Definition: bd.h:11
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
#define Assert(Cond)
Definition: bd.h:251
int GetDim() const
Definition: kronecker.h:30

Here is the call graph for this function:

int TKronMtx::GetEdges ( const int &  NIter) const

Definition at line 123 of file kronecker.cpp.

References GetMtxSum().

Referenced by GenFastKronecker(), TKroneckerLL::GradDescent(), TKroneckerLL::GradDescent2(), and TKroneckerLL::GradDescentConvergence().

123  {
124  return (int) pow(double(GetMtxSum()), double(NIter));
125 }
double GetMtxSum() const
Definition: kronecker.cpp:140

Here is the call graph for this function:

Here is the caller graph for this function:

double TKronMtx::GetEZero ( const int &  Edges,
const int &  KronIter 
) const

Definition at line 136 of file kronecker.cpp.

136  {
137  return pow((double) Edges, 1.0/double(KronIters));
138 }
TKronMtx TKronMtx::GetInitMtx ( const int &  Dim,
const int &  Nodes,
const int &  Edges 
)
static

Definition at line 705 of file kronecker.cpp.

References TRnd::GetUniDev(), TVec< TVal, TSizeTy >::Len(), TVec< TVal, TSizeTy >::PutAll(), and SetForEdges().

Referenced by GetInitMtx(), and TKroneckerLL::TestBicCriterion().

705  {
706  const double MxParam = 0.8+TKronMtx::Rnd.GetUniDev()/5.0;
707  const double MnParam = 0.2-TKronMtx::Rnd.GetUniDev()/5.0;
708  const double Step = (MxParam-MnParam) / (Dim*Dim-1);
709  TFltV ParamV(Dim*Dim);
710  if (Dim == 1) { ParamV.PutAll(0.5); } // random graph
711  else {
712  for (int p = 0; p < ParamV.Len(); p++) {
713  ParamV[p] = MxParam - p*Step; }
714  }
715  //IAssert(ParamV[0]==MxParam && ParamV.Last()==MnParam);
716  TKronMtx Mtx(ParamV);
717  Mtx.SetForEdges(Nodes, Edges);
718  return Mtx;
719 }
static TRnd Rnd
Definition: kronecker.h:14
double GetUniDev()
Definition: dt.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

TKronMtx TKronMtx::GetInitMtx ( const TStr MtxStr,
const int &  Dim,
const int &  Nodes,
const int &  Edges 
)
static

Definition at line 721 of file kronecker.cpp.

References AddRndNoise(), At(), FailR, GetInitMtx(), GetMtx(), GetRndMtx(), TRnd::GetUniDev(), TCh::IsNum(), and SetForEdges().

721  {
722  TKronMtx Mtx(Dim);
723  if (TCh::IsNum(MtxStr[0])) { Mtx = TKronMtx::GetMtx(MtxStr); }
724  else if (MtxStr[0] == 'r') { Mtx = TKronMtx::GetRndMtx(Dim, 0.1); }
725  else if (MtxStr[0] == 'a') {
726  const double Prob = TKronMtx::Rnd.GetUniDev();
727  if (Prob < 0.4) {
728  Mtx = TKronMtx::GetInitMtx(Dim, Nodes, Edges); }
729  else { // interpolate so that there are in the corners 0.9, 0.5, 0.1, 0.5
730  const double Max = 0.9+TKronMtx::Rnd.GetUniDev()/10.0;
731  const double Min = 0.1-TKronMtx::Rnd.GetUniDev()/10.0;
732  const double Med = (Max-Min)/2.0;
733  Mtx.At(0,0) = Max; Mtx.At(0,Dim-1) = Med;
734  Mtx.At(Dim-1, 0) = Med; Mtx.At(Dim-1, Dim-1) = Min;
735  for (int i = 1; i < Dim-1; i++) {
736  Mtx.At(i,i) = Max - double(i)*(Max-Min)/double(Dim-1);
737  Mtx.At(i, 0) = Mtx.At(0, i) = Max - double(i)*(Max-Med)/double(Dim-1);
738  Mtx.At(i, Dim-1) = Mtx.At(Dim-1, i) = Med - double(i)*(Med-Min)/double(Dim-1);
739  }
740  for (int i = 1; i < Dim-1; i++) {
741  for (int j = 1; j < Dim-1; j++) {
742  if (i >= j) { continue; }
743  Mtx.At(i,j) = Mtx.At(j,i) = Mtx.At(i,i) - (j-i)*(Mtx.At(i,i)-Mtx.At(i,Dim-1))/(Dim-i-1);
744  }
745  }
746  Mtx.AddRndNoise(0.1);
747  }
748  } else { FailR("Wrong mtx: matlab str, or random (r), or all (a)"); }
749  Mtx.SetForEdges(Nodes, Edges);
750  return Mtx;
751 }
static TRnd Rnd
Definition: kronecker.h:14
TFltV & GetMtx()
Definition: kronecker.h:35
static bool IsNum(const char &Ch)
Definition: dt.h:1064
static TKronMtx GetInitMtx(const int &Dim, const int &Nodes, const int &Edges)
Definition: kronecker.cpp:705
#define FailR(Reason)
Definition: bd.h:240
static TKronMtx GetRndMtx(const int &Dim, const double &MinProb)
Definition: kronecker.cpp:699
double GetUniDev()
Definition: dt.h:30

Here is the call graph for this function:

int TKronMtx::GetKronIter ( const int &  Nodes) const

Definition at line 127 of file kronecker.cpp.

References GetDim().

Referenced by GetNZeroK(), PlotCmpGraphs(), SetForEdges(), and TKronMomentsFit::Test().

127  {
128  return (int) ceil(log(double(Nodes)) / log(double(GetDim()))); // upper bound
129  //return (int) TMath::Round(log(double(Nodes)) / log(double(GetDim()))); // round to nearest power
130 }
int GetDim() const
Definition: kronecker.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

int TKronMtx::GetKronIter ( const int &  GNodes,
const int &  SeedMtxSz 
)
static

Definition at line 307 of file kronecker.cpp.

307  {
308  return (int) ceil(log(double(GNodes)) / log(double(SeedMtxSz)));
309 }
void TKronMtx::GetLLMtx ( TKronMtx LLMtx)

Definition at line 98 of file kronecker.cpp.

References At(), GenMtx(), Len(), MtxDim, and NInf.

Referenced by TKroneckerLL::GradDescent(), TKroneckerLL::GradDescent2(), TKroneckerLL::GradDescentConvergence(), TKroneckerLL::InitLL(), TKroneckerLL::RunMStep(), and TKroneckerLL::TestKronDescent().

98  {
99  LLMtx.GenMtx(MtxDim);
100  for (int i = 0; i < Len(); i++) {
101  if (At(i) != 0.0) { LLMtx.At(i) = log(At(i)); }
102  else { LLMtx.At(i) = NInf; }
103  }
104 }
int Len() const
Definition: kronecker.h:31
static const double NInf
Definition: kronecker.h:13
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
TInt MtxDim
Definition: kronecker.h:16
void GenMtx(const int &Dim)
Definition: kronecker.h:40

Here is the call graph for this function:

Here is the caller graph for this function:

TFltV& TKronMtx::GetMtx ( )
inline

Definition at line 35 of file kronecker.h.

References SeedMtx.

Referenced by GetAvgAbsErr(), GetAvgFroErr(), GetInitMtx(), GetMtxFromNm(), TKronMaxLL::Test(), and TKroneckerLL::TestGradDescent().

35 { return SeedMtx; }
TFltV SeedMtx
Definition: kronecker.h:17

Here is the caller graph for this function:

const TFltV& TKronMtx::GetMtx ( ) const
inline

Definition at line 36 of file kronecker.h.

References SeedMtx.

36 { return SeedMtx; }
TFltV SeedMtx
Definition: kronecker.h:17
TKronMtx TKronMtx::GetMtx ( TStr  MatlabMtxStr)
static

Definition at line 681 of file kronecker.cpp.

References At(), TStr::ChangeChAll(), TVec< TVal, TSizeTy >::Empty(), IAssert, TVec< TVal, TSizeTy >::Len(), and TStr::SplitOnAllCh().

681  {
682  TStrV RowStrV, ColStrV;
683  MatlabMtxStr.ChangeChAll(',', ' ');
684  MatlabMtxStr.SplitOnAllCh(';', RowStrV); IAssert(! RowStrV.Empty());
685  RowStrV[0].SplitOnWs(ColStrV); IAssert(! ColStrV.Empty());
686  const int Rows = RowStrV.Len();
687  const int Cols = ColStrV.Len();
688  IAssert(Rows == Cols);
689  TKronMtx Mtx(Rows);
690  for (int r = 0; r < Rows; r++) {
691  RowStrV[r].SplitOnWs(ColStrV);
692  IAssert(ColStrV.Len() == Cols);
693  for (int c = 0; c < Cols; c++) {
694  Mtx.At(r, c) = (double) ColStrV[c].GetFlt(); }
695  }
696  return Mtx;
697 }
#define IAssert(Cond)
Definition: bd.h:262
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
int ChangeChAll(const char &SrcCh, const char &DstCh)
Definition: dt.cpp:1113
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:570
void SplitOnAllCh(const char &SplitCh, TStrV &StrV, const bool &SkipEmpty=true) const
Definition: dt.cpp:926

Here is the call graph for this function:

TKronMtx TKronMtx::GetMtxFromNm ( const TStr MtxNm)
static

Definition at line 753 of file kronecker.cpp.

References TStr::CStr(), FailR, TStr::Fmt(), GetMtx(), and TKronMtx().

753  {
754  if (MtxNm == "3chain") return TKronMtx::GetMtx("1 1 0; 1 1 1; 0 1 1");
755  else if (MtxNm == "4star") return TKronMtx::GetMtx("1 1 1 1; 1 1 0 0 ; 1 0 1 0; 1 0 0 1");
756  else if (MtxNm == "4chain") return TKronMtx::GetMtx("1 1 0 0; 1 1 1 0 ; 0 1 1 1; 0 0 1 1");
757  else if (MtxNm == "4square") return TKronMtx::GetMtx("1 1 0 1; 1 1 1 0 ; 0 1 1 1; 1 0 1 1");
758  else if (MtxNm == "5star") return TKronMtx::GetMtx("1 1 1 1 1; 1 1 0 0 0; 1 0 1 0 0; 1 0 0 1 0; 1 0 0 0 1");
759  else if (MtxNm == "6star") return TKronMtx::GetMtx("1 1 1 1 1 1; 1 1 0 0 0 0; 1 0 1 0 0 0; 1 0 0 1 0 0; 1 0 0 0 1 0; 1 0 0 0 0 1");
760  else if (MtxNm == "7star") return TKronMtx::GetMtx("1 1 1 1 1 1 1; 1 1 0 0 0 0 0; 1 0 1 0 0 0 0; 1 0 0 1 0 0 0; 1 0 0 0 1 0 0; 1 0 0 0 0 1 0; 1 0 0 0 0 0 1");
761  else if (MtxNm == "5burst") return TKronMtx::GetMtx("1 1 1 1 0; 1 1 0 0 0; 1 0 1 0 0; 1 0 0 1 1; 0 0 0 1 1");
762  else if (MtxNm == "7burst") return TKronMtx::GetMtx("1 0 0 1 0 0 0; 0 1 0 1 0 0 0; 0 0 1 1 0 0 0; 1 1 1 1 1 0 0; 0 0 0 1 1 1 1; 0 0 0 0 1 1 0; 0 0 0 0 1 0 1");
763  else if (MtxNm == "7cross") return TKronMtx::GetMtx("1 0 0 1 0 0 0; 0 1 0 1 0 0 0; 0 0 1 1 0 0 0; 1 1 1 1 1 0 0; 0 0 0 1 1 1 0; 0 0 0 0 1 1 1; 0 0 0 0 0 1 1");
764  FailR(TStr::Fmt("Unknow matrix: '%s'", MtxNm.CStr()).CStr());
765  return TKronMtx();
766 }
TFltV & GetMtx()
Definition: kronecker.h:35
#define FailR(Reason)
Definition: bd.h:240
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
TKronMtx()
Definition: kronecker.h:19

Here is the call graph for this function:

TStr TKronMtx::GetMtxStr ( ) const

Definition at line 80 of file kronecker.cpp.

References At(), TStr::Fmt(), GetDim(), and Len().

Referenced by PlotCmpGraphs().

80  {
81  TChA ChA("[");
82  for (int i = 0; i < Len(); i++) {
83  ChA += TStr::Fmt("%g", At(i));
84  if ((i+1)%GetDim()==0 && (i+1<Len())) { ChA += "; "; }
85  else if (i+1<Len()) { ChA += ", "; }
86  }
87  ChA += "]";
88  return TStr(ChA);
89 }
int Len() const
Definition: kronecker.h:31
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
Definition: dt.h:201
int GetDim() const
Definition: kronecker.h:30
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599

Here is the call graph for this function:

Here is the caller graph for this function:

double TKronMtx::GetMtxSum ( ) const

Definition at line 140 of file kronecker.cpp.

References At(), and Len().

Referenced by GenFastKronecker(), TKroneckerLL::GetAbsErr(), GetEdges(), TKroneckerLL::GetFullGraphLL(), TKroneckerLL::GradDescent(), TKroneckerLL::GradDescent2(), TKroneckerLL::GradDescentConvergence(), TKroneckerLL::MetroGibbsSampleSetup(), TKroneckerLL::RunMStep(), SetForEdges(), TKroneckerLL::SetRandomEdges(), and TKroneckerLL::TestKronDescent().

140  {
141  double Sum = 0;
142  for (int i = 0; i < Len(); i++) {
143  Sum += At(i); }
144  return Sum;
145 }
int Len() const
Definition: kronecker.h:31
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46

Here is the call graph for this function:

Here is the caller graph for this function:

int TKronMtx::GetNodes ( const int &  NIter) const

Definition at line 119 of file kronecker.cpp.

References GetDim().

Referenced by GenDetKronecker(), GenFastKronecker(), GenKronecker(), TKroneckerLL::GetEmptyGraphLL(), GetNZeroK(), TKroneckerLL::GradDescent(), TKroneckerLL::GradDescent2(), TKroneckerLL::GradDescentConvergence(), and TKroneckerLL::RunKronEM().

119  {
120  return (int) pow(double(GetDim()), double(NIter));
121 }
int GetDim() const
Definition: kronecker.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

uint TKronMtx::GetNodeSig ( const double &  OneProb = 0.5)
static

Definition at line 262 of file kronecker.cpp.

262  {
263  uint Sig = 0;
264  for (int i = 0; i < (int)(8*sizeof(uint)); i++) {
265  if (TKronMtx::Rnd.GetUniDev() < OneProb) {
266  Sig |= (1u<<i); }
267  }
268  return Sig;
269 }
static TRnd Rnd
Definition: kronecker.h:14
unsigned int uint
Definition: bd.h:11
double TKronMtx::GetNoEdgeDLL ( const int &  ParamId,
int  NId1,
int  NId2,
const int &  NKronIters 
) const

Definition at line 220 of file kronecker.cpp.

References At(), GetDim(), and MtxDim.

Referenced by TKroneckerLL::CalcGraphDLL(), and TKroneckerLL::GetEmptyGraphDLL().

220  {
221  const int& ThetaX = ParamId % GetDim();
222  const int& ThetaY = ParamId / GetDim();
223  int ThetaCnt = 0;
224  double DLL = 0, LL = 0;
225  for (int level = 0; level < NKronIters; level++) {
226  const int X = NId1 % MtxDim;
227  const int Y = NId2 % MtxDim;
228  const double LVal = At(X, Y);
229  if (X == ThetaX && Y == ThetaY) {
230  if (ThetaCnt != 0) { DLL += LVal; }
231  ThetaCnt++;
232  } else { DLL += LVal; }
233  LL += LVal;
234  NId1 /= MtxDim; NId2 /= MtxDim;
235  }
236  return -ThetaCnt*exp(DLL) / (1.0 - exp(LL));
237 }
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
TInt MtxDim
Definition: kronecker.h:16
int GetDim() const
Definition: kronecker.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

double TKronMtx::GetNoEdgeLL ( int  NId1,
int  NId2,
const int &  NKronIters 
) const

Definition at line 186 of file kronecker.cpp.

References GetEdgeLL().

Referenced by TKroneckerLL::CalcGraphLL(), and TKroneckerLL::GetEmptyGraphLL().

186  {
187  return log(1.0 - exp(GetEdgeLL(NId1, NId2, NKronIters)));
188 }
double GetEdgeLL(int NId1, int NId2, const int &NKronIters) const
Definition: kronecker.cpp:175

Here is the call graph for this function:

Here is the caller graph for this function:

double TKronMtx::GetNoEdgeProb ( int  NId1,
int  NId2,
const int &  NKronIters 
) const

Definition at line 171 of file kronecker.cpp.

References GetEdgeProb().

171  {
172  return 1.0 - GetEdgeProb(NId1, NId2, NKronIters);
173 }
double GetEdgeProb(int NId1, int NId2, const int &NKronIters) const
Definition: kronecker.cpp:161

Here is the call graph for this function:

int TKronMtx::GetNZeroK ( const PNGraph Graph) const

Definition at line 132 of file kronecker.cpp.

References GetKronIter(), GetNodes(), and TNGraph::GetNodes().

132  {
133  return GetNodes(GetKronIter(Graph->GetNodes()));
134 }
int GetKronIter(const int &Nodes) const
Definition: kronecker.cpp:127
int GetNodes() const
Returns the number of nodes in the graph.
Definition: graph.h:499
int GetNodes(const int &NIter) const
Definition: kronecker.cpp:119

Here is the call graph for this function:

int TKronMtx::GetPrimHashCd ( ) const
inline

Definition at line 26 of file kronecker.h.

References TVec< TVal, TSizeTy >::GetPrimHashCd(), and SeedMtx.

26 { return SeedMtx.GetPrimHashCd(); }
int GetPrimHashCd() const
Returns primary hash code of the vector. Used by THash.
Definition: ds.h:999
TFltV SeedMtx
Definition: kronecker.h:17

Here is the call graph for this function:

void TKronMtx::GetProbMtx ( TKronMtx ProbMtx)

Definition at line 106 of file kronecker.cpp.

References At(), GenMtx(), Len(), MtxDim, and NInf.

106  {
107  ProbMtx.GenMtx(MtxDim);
108  for (int i = 0; i < Len(); i++) {
109  if (At(i) != NInf) { ProbMtx.At(i) = exp(At(i)); }
110  else { ProbMtx.At(i) = 0.0; }
111  }
112 }
int Len() const
Definition: kronecker.h:31
static const double NInf
Definition: kronecker.h:13
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
TInt MtxDim
Definition: kronecker.h:16
void GenMtx(const int &Dim)
Definition: kronecker.h:40

Here is the call graph for this function:

TKronMtx TKronMtx::GetRndMtx ( const int &  Dim,
const double &  MinProb 
)
static

Definition at line 699 of file kronecker.cpp.

References SetRndMtx().

Referenced by GetInitMtx().

699  {
700  TKronMtx Mtx;
701  Mtx.SetRndMtx(Dim, MinProb);
702  return Mtx;
703 }
void SetRndMtx(const int &MtxDim, const double &MinProb=0.0)
Definition: kronecker.cpp:40

Here is the call graph for this function:

Here is the caller graph for this function:

double TKronMtx::GetRowSum ( const int &  RowId) const

Definition at line 147 of file kronecker.cpp.

References At(), and GetDim().

Referenced by TKroneckerLL::GetFullRowLL().

147  {
148  double Sum = 0;
149  for (int c = 0; c < GetDim(); c++) {
150  Sum += At(RowId, c); }
151  return Sum;
152 }
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
int GetDim() const
Definition: kronecker.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

int TKronMtx::GetSecHashCd ( ) const
inline

Definition at line 27 of file kronecker.h.

References TVec< TVal, TSizeTy >::GetSecHashCd(), and SeedMtx.

27 { return SeedMtx.GetSecHashCd(); }
int GetSecHashCd() const
Returns secondary hash code of the vector. Used by THash.
Definition: ds.h:1011
TFltV SeedMtx
Definition: kronecker.h:17

Here is the call graph for this function:

bool TKronMtx::IsEdgePlace ( int  NId1,
int  NId2,
const int &  NKronIters,
const double &  ProbTresh 
) const

Definition at line 196 of file kronecker.cpp.

References At(), and MtxDim.

Referenced by GenDetKronecker(), and GenKronecker().

196  {
197  double Prob = 1.0;
198  for (int level = 0; level < NKronIters; level++) {
199  Prob *= At(NId1 % MtxDim, NId2 % MtxDim);
200  if (ProbTresh > Prob) { return false; }
201  NId1 /= MtxDim; NId2 /= MtxDim;
202  }
203  return true;
204 }
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
TInt MtxDim
Definition: kronecker.h:16

Here is the call graph for this function:

Here is the caller graph for this function:

bool TKronMtx::IsProbMtx ( ) const

Definition at line 33 of file kronecker.cpp.

References At(), and Len().

Referenced by TKroneckerLL::InitLL().

33  {
34  for (int i = 0; i < Len(); i++) {
35  if (At(i) < 0.0 || At(i) > 1.0) return false;
36  }
37  return true;
38 }
int Len() const
Definition: kronecker.h:31
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46

Here is the call graph for this function:

Here is the caller graph for this function:

void TKronMtx::KronMul ( const TKronMtx LeftPt,
const TKronMtx RightPt,
TKronMtx OutMtx 
)
static

Definition at line 591 of file kronecker.cpp.

References At(), GenMtx(), and GetDim().

Referenced by KronPwr().

591  {
592  const int LDim = Left.GetDim();
593  const int RDim = Right.GetDim();
594  Result.GenMtx(LDim * RDim);
595  for (int r1 = 0; r1 < LDim; r1++) {
596  for (int c1 = 0; c1 < LDim; c1++) {
597  const double& Val = Left.At(r1, c1);
598  for (int r2 = 0; r2 < RDim; r2++) {
599  for (int c2 = 0; c2 < RDim; c2++) {
600  Result.At(r1*RDim+r2, c1*RDim+c2) = Val * Right.At(r2, c2);
601  }
602  }
603  }
604  }
605 }

Here is the call graph for this function:

Here is the caller graph for this function:

void TKronMtx::KronPwr ( const TKronMtx KronPt,
const int &  NIter,
TKronMtx OutMtx 
)
static

Definition at line 626 of file kronecker.cpp.

References KronMul(), and Swap().

626  {
627  OutMtx = KronMtx;
628  TKronMtx NewOutMtx;
629  for (int iter = 0; iter < NIter; iter++) {
630  KronMul(OutMtx, KronMtx, NewOutMtx);
631  NewOutMtx.Swap(OutMtx);
632  }
633 
634 }
static void KronMul(const TKronMtx &LeftPt, const TKronMtx &RightPt, TKronMtx &OutMtx)
Definition: kronecker.cpp:591
void Swap(TKronMtx &KronMtx)
Definition: kronecker.cpp:114

Here is the call graph for this function:

void TKronMtx::KronSum ( const TKronMtx LeftPt,
const TKronMtx RightPt,
TKronMtx OutMtx 
)
static

Definition at line 607 of file kronecker.cpp.

References At(), GenMtx(), GetDim(), and NInf.

607  {
608  const int LDim = Left.GetDim();
609  const int RDim = Right.GetDim();
610  Result.GenMtx(LDim * RDim);
611  for (int r1 = 0; r1 < LDim; r1++) {
612  for (int c1 = 0; c1 < LDim; c1++) {
613  const double& Val = Left.At(r1, c1);
614  for (int r2 = 0; r2 < RDim; r2++) {
615  for (int c2 = 0; c2 < RDim; c2++) {
616  if (Val == NInf || Right.At(r2, c2) == NInf) {
617  Result.At(r1*RDim+r2, c1*RDim+c2) = NInf; }
618  else {
619  Result.At(r1*RDim+r2, c1*RDim+c2) = Val + Right.At(r2, c2); }
620  }
621  }
622  }
623  }
624 }
static const double NInf
Definition: kronecker.h:13

Here is the call graph for this function:

int TKronMtx::Len ( ) const
inline
TKronMtx TKronMtx::LoadTxt ( const TStr MtxFNm)
static

Definition at line 768 of file kronecker.cpp.

References At(), IAssert, IAssertR, TSs::LoadTxt(), and ssfTabSep.

768  {
769  PSs Ss = TSs::LoadTxt(ssfTabSep, MtxFNm);
770  IAssertR(Ss->GetXLen() == Ss->GetYLen(), "Not a square matrix");
771  IAssert(Ss->GetYLen() == Ss->GetXLen());
772  TKronMtx Mtx(Ss->GetYLen());
773  for (int r = 0; r < Ss->GetYLen(); r++) {
774  for (int c = 0; c < Ss->GetXLen(); c++) {
775  Mtx.At(r, c) = (double) Ss->At(c, r).GetFlt(); }
776  }
777  return Mtx;
778 }
#define IAssert(Cond)
Definition: bd.h:262
#define IAssertR(Cond, Reason)
Definition: bd.h:265
static PSs LoadTxt(const TSsFmt &SsFmt, const TStr &FNm, const PNotify &Notify=NULL, const bool &IsExcelEoln=true, const int &MxY=-1, const TIntV &AllowedColNV=TIntV(), const bool &IsQStr=true)
Definition: ss.cpp:100
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
Tab separated.
Definition: ss.h:6
Definition: bd.h:196

Here is the call graph for this function:

TKronMtx & TKronMtx::operator= ( const TKronMtx Kronecker)

Definition at line 25 of file kronecker.cpp.

References MtxDim, and SeedMtx.

25  {
26  if (this != &Kronecker){
27  MtxDim=Kronecker.MtxDim;
28  SeedMtx=Kronecker.SeedMtx;
29  }
30  return *this;
31 }
TInt MtxDim
Definition: kronecker.h:16
TFltV SeedMtx
Definition: kronecker.h:17
bool TKronMtx::operator== ( const TKronMtx Kronecker) const
inline

Definition at line 25 of file kronecker.h.

References SeedMtx.

25 { return SeedMtx==Kronecker.SeedMtx; }
TFltV SeedMtx
Definition: kronecker.h:17
void TKronMtx::PlotCmpGraphs ( const TKronMtx SeedMtx,
const PNGraph Graph,
const TStr OutFNm,
const TStr Desc 
)
static

Definition at line 479 of file kronecker.cpp.

References TStr::CStr(), TSnap::DelZeroDegNodes(), TStr::Fmt(), GenFastKronecker(), GenKronecker(), TNGraph::GetEdges(), GetKronIter(), TSnap::GetMxWcc(), TNGraph::GetNodes(), gpwLinesPoints, gsdClustCf, gsdHops, gsdInDeg, gsdOutDeg, gsdScc, gsdSngVal, gsdSngVec, gsdWcc, and tmuNodes.

479  {
480  const int KronIters = SeedMtx.GetKronIter(Graph->GetNodes());
481  PNGraph KronG, WccG;
482  const bool FastGen = true;
483  if (FastGen) { KronG = TKronMtx::GenFastKronecker(SeedMtx, KronIters, true, 0); }
484  else { KronG = TKronMtx::GenKronecker(SeedMtx, KronIters, true, 0); }
485  TSnap::DelZeroDegNodes(KronG);
486  WccG = TSnap::GetMxWcc(KronG);
487  const TStr Desc1 = TStr::Fmt("%s", Desc.CStr());
489  //gsdHops
490  //gsWccHops, gsdSngVal, gsdSngVec, gsdClustCf
491  GS.Add(Graph, TSecTm(1), TStr::Fmt("GRAPH G(%d, %d)", Graph->GetNodes(), Graph->GetEdges()));
492  GS.Add(KronG, TSecTm(2), TStr::Fmt("KRONECKER K(%d, %d)", KronG->GetNodes(), KronG->GetEdges()));
493  GS.Add(WccG, TSecTm(3), TStr::Fmt("KRONECKER wccK(%d, %d)", WccG->GetNodes(), WccG->GetEdges()));
494  const TStr Style = "linewidth 1 pointtype 6 pointsize 1";
495  GS.ImposeDistr(gsdInDeg, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
496  GS.ImposeDistr(gsdInDeg, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
497  GS.ImposeDistr(gsdOutDeg, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
498  GS.ImposeDistr(gsdOutDeg, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
499  GS.ImposeDistr(gsdHops, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
500  GS.ImposeDistr(gsdClustCf, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
501  GS.ImposeDistr(gsdClustCf, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
502  GS.ImposeDistr(gsdSngVal, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
503  GS.ImposeDistr(gsdSngVal, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
504  GS.ImposeDistr(gsdSngVec, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
505  GS.ImposeDistr(gsdSngVec, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
506  GS.ImposeDistr(gsdWcc, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
507  GS.ImposeDistr(gsdWcc, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
508  GS.ImposeDistr(gsdScc, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
509  GS.ImposeDistr(gsdScc, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
510 // typedef enum { distrUndef, distrInDeg, distrOutDeg, distrWcc, distrScc,
511 // distrHops, distrWccHops, distrSngVal, distrSngVec, distrClustCf, distrMx } TGraphDistr;*/
512 }
static PNGraph GenKronecker(const TKronMtx &SeedMtx, const int &NIter, const bool &IsDir, const int &Seed=0)
Definition: kronecker.cpp:312
int GetKronIter(const int &Nodes) const
Definition: kronecker.cpp:127
PGraph GetMxWcc(const PGraph &Graph)
Returns a graph representing the largest weakly connected component on an input Graph.
Definition: cncom.h:452
Definition: gstat.h:28
int GetEdges() const
Returns the number of edges in the graph.
Definition: graph.cpp:313
Definition: bits.h:119
int GetNodes() const
Returns the number of nodes in the graph.
Definition: graph.h:499
Definition: gstat.h:29
Definition: gstat.h:28
Graph Statistics Sequence.
Definition: gstat.h:155
void DelZeroDegNodes(PGraph &Graph)
Removes all the zero-degree nodes, that isolated nodes, from the graph.
Definition: alg.h:432
Definition: tm.h:14
Definition: tm.h:81
Definition: gstat.h:28
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
static PNGraph GenFastKronecker(const TKronMtx &SeedMtx, const int &NIter, const bool &IsDir, const int &Seed=0)
Definition: kronecker.cpp:349

Here is the call graph for this function:

void TKronMtx::PlotCmpGraphs ( const TKronMtx SeedMtx1,
const TKronMtx SeedMtx2,
const PNGraph Graph,
const TStr OutFNm,
const TStr Desc 
)
static

!!

Definition at line 514 of file kronecker.cpp.

References TStr::CStr(), TSnap::DelZeroDegNodes(), TStr::Fmt(), GenFastKronecker(), GenKronecker(), TNGraph::GetEdges(), GetKronIter(), GetMtxStr(), TNGraph::GetNodes(), gpwLinesPoints, gsdClustCf, gsdHops, gsdInDeg, gsdOutDeg, gsdScc, gsdSngVal, gsdSngVec, gsdTriadPart, gsdWcc, and tmuNodes.

514  {
515  const int KronIters1 = SeedMtx1.GetKronIter(Graph->GetNodes());
516  const int KronIters2 = SeedMtx2.GetKronIter(Graph->GetNodes());
517  PNGraph KronG1, KronG2;
518  const bool FastGen = true;
519  if (FastGen) {
520  KronG1 = TKronMtx::GenFastKronecker(SeedMtx1, KronIters1, true, 0);
521  KronG2 = TKronMtx::GenFastKronecker(SeedMtx2, KronIters2, false, 0); }
522  else {
523  KronG1 = TKronMtx::GenKronecker(SeedMtx1, KronIters1, true, 0);
524  KronG2 = TKronMtx::GenKronecker(SeedMtx2, KronIters2, true, 0); }
525  TSnap::DelZeroDegNodes(KronG1);
526  TSnap::DelZeroDegNodes(KronG2);
527  const TStr Desc1 = TStr::Fmt("%s", Desc.CStr());
529  //gsdHops
530  //gsWccHops, gsdSngVal, gsdSngVec, gsdClustCf
531  GS.Add(Graph, TSecTm(1), TStr::Fmt("GRAPH G(%d, %d)", Graph->GetNodes(), Graph->GetEdges()));
532  GS.Add(KronG1, TSecTm(2), TStr::Fmt("KRONECKER1 K(%d, %d) %s", KronG1->GetNodes(), KronG1->GetEdges(), SeedMtx1.GetMtxStr().CStr()));
533  GS.Add(KronG2, TSecTm(3), TStr::Fmt("KRONECKER2 K(%d, %d) %s", KronG2->GetNodes(), KronG2->GetEdges(), SeedMtx2.GetMtxStr().CStr()));
534  const TStr Style = "linewidth 1 pointtype 6 pointsize 1";
535  // raw data
536  GS.ImposeDistr(gsdInDeg, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
537  GS.ImposeDistr(gsdOutDeg, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
538  GS.ImposeDistr(gsdHops, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
539  GS.ImposeDistr(gsdClustCf, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
540  GS.ImposeDistr(gsdSngVal, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
541  GS.ImposeDistr(gsdSngVec, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
542  GS.ImposeDistr(gsdWcc, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
543  GS.ImposeDistr(gsdScc, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
544  GS.ImposeDistr(gsdTriadPart, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
545  // smooth
546  GS.ImposeDistr(gsdInDeg, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
547  GS.ImposeDistr(gsdOutDeg, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
548  GS.ImposeDistr(gsdClustCf, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
549  GS.ImposeDistr(gsdScc, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
550  GS.ImposeDistr(gsdWcc, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
551  GS.ImposeDistr(gsdSngVec, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
552  GS.ImposeDistr(gsdSngVal, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
553  GS.ImposeDistr(gsdTriadPart, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
554 }
static PNGraph GenKronecker(const TKronMtx &SeedMtx, const int &NIter, const bool &IsDir, const int &Seed=0)
Definition: kronecker.cpp:312
int GetKronIter(const int &Nodes) const
Definition: kronecker.cpp:127
Definition: gstat.h:28
int GetEdges() const
Returns the number of edges in the graph.
Definition: graph.cpp:313
Definition: bits.h:119
int GetNodes() const
Returns the number of nodes in the graph.
Definition: graph.h:499
TStr GetMtxStr() const
Definition: kronecker.cpp:80
Definition: gstat.h:29
Definition: gstat.h:28
Graph Statistics Sequence.
Definition: gstat.h:155
void DelZeroDegNodes(PGraph &Graph)
Removes all the zero-degree nodes, that isolated nodes, from the graph.
Definition: alg.h:432
Definition: tm.h:14
Definition: tm.h:81
Definition: gstat.h:28
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
static PNGraph GenFastKronecker(const TKronMtx &SeedMtx, const int &NIter, const bool &IsDir, const int &Seed=0)
Definition: kronecker.cpp:349

Here is the call graph for this function:

void TKronMtx::PlotCmpGraphs ( const TVec< TKronMtx > &  SeedMtxV,
const PNGraph Graph,
const TStr FNmPref,
const TStr Desc 
)
static

Definition at line 556 of file kronecker.cpp.

References TStr::CStr(), TSnap::DelZeroDegNodes(), TStr::Fmt(), GenFastKronecker(), TNGraph::GetEdges(), TNGraph::GetNodes(), gpwLines, gsdClustCf, gsdHops, gsdInDeg, gsdOutDeg, gsdScc, gsdSngVal, gsdSngVec, gsdWcc, TVec< TVal, TSizeTy >::Len(), and tmuNodes.

556  {
557  const TStr Desc1 = TStr::Fmt("%s", Desc.CStr());
559  GS.Add(Graph, TSecTm(1), TStr::Fmt("GRAPH G(%d, %d)", Graph->GetNodes(), Graph->GetEdges()));
560  //gsdHops
561  //gsWccHops, gsdSngVal, gsdSngVec, gsdClustCf
562  for (int m = 0; m < SeedMtxV.Len(); m++) {
563  const int KronIters = SeedMtxV[m].GetKronIter(Graph->GetNodes());
564  PNGraph KronG1 = TKronMtx::GenFastKronecker(SeedMtxV[m], KronIters, true, 0);
565  printf("*** K(%d, %d) n0=%d\n", KronG1->GetNodes(), KronG1->GetEdges(), SeedMtxV[m].GetDim());
566  TSnap::DelZeroDegNodes(KronG1);
567  printf(" del zero deg K(%d, %d) n0=%d\n", KronG1->GetNodes(), KronG1->GetEdges(), m);
568  GS.Add(KronG1, TSecTm(m+2), TStr::Fmt("K(%d, %d) n0^k=%d n0=%d", KronG1->GetNodes(), KronG1->GetEdges(), SeedMtxV[m].GetNZeroK(Graph), SeedMtxV[m].GetDim()));
569  // plot after each Kronecker is done
570  const TStr Style = "linewidth 1 pointtype 6 pointsize 1";
571  GS.ImposeDistr(gsdInDeg, FNmPref, Desc1, false, false, gpwLines, Style);
572  GS.ImposeDistr(gsdInDeg, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
573  GS.ImposeDistr(gsdOutDeg, FNmPref, Desc1, false, false, gpwLines, Style);
574  GS.ImposeDistr(gsdOutDeg, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
575  GS.ImposeDistr(gsdHops, FNmPref, Desc1, false, false, gpwLines, Style);
576  GS.ImposeDistr(gsdClustCf, FNmPref, Desc1, false, false, gpwLines, Style);
577  GS.ImposeDistr(gsdClustCf, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
578  GS.ImposeDistr(gsdSngVal, FNmPref, Desc1, false, false, gpwLines, Style);
579  GS.ImposeDistr(gsdSngVal, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
580  GS.ImposeDistr(gsdSngVec, FNmPref, Desc1, false, false, gpwLines, Style);
581  GS.ImposeDistr(gsdSngVec, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
582  GS.ImposeDistr(gsdWcc, FNmPref, Desc1, false, false, gpwLines, Style);
583  GS.ImposeDistr(gsdWcc, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
584  GS.ImposeDistr(gsdScc, FNmPref, Desc1, false, false, gpwLines, Style);
585  GS.ImposeDistr(gsdScc, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
586  }
587  // typedef enum { distrUndef, distrInDeg, distrOutDeg, distrWcc, distrScc,
588  // distrHops, distrWccHops, distrSngVal, distrSngVec, distrClustCf, distrMx } TGraphDistr;*/
589 }
Definition: gstat.h:28
int GetEdges() const
Returns the number of edges in the graph.
Definition: graph.cpp:313
Definition: bits.h:119
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
int GetNodes() const
Returns the number of nodes in the graph.
Definition: graph.h:499
Definition: gstat.h:29
Definition: gstat.h:28
Graph Statistics Sequence.
Definition: gstat.h:155
void DelZeroDegNodes(PGraph &Graph)
Removes all the zero-degree nodes, that isolated nodes, from the graph.
Definition: alg.h:432
Definition: tm.h:14
Definition: tm.h:81
Definition: gstat.h:28
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
static PNGraph GenFastKronecker(const TKronMtx &SeedMtx, const int &NIter, const bool &IsDir, const int &Seed=0)
Definition: kronecker.cpp:349

Here is the call graph for this function:

void TKronMtx::PutAllMtx ( const double &  Val)
inline

Definition at line 39 of file kronecker.h.

References TVec< TVal, TSizeTy >::PutAll(), and SeedMtx.

39 { SeedMtx.PutAll(Val); }
void PutAll(const TVal &Val)
Sets all elements of the vector to value Val.
Definition: ds.h:1229
TFltV SeedMtx
Definition: kronecker.h:17

Here is the call graph for this function:

static void TKronMtx::PutRndSeed ( const int &  Seed)
inlinestatic

Definition at line 108 of file kronecker.h.

References TRnd::PutSeed(), and Rnd.

Referenced by TKronMaxLL::Test().

108 { TKronMtx::Rnd.PutSeed(Seed); }
static TRnd Rnd
Definition: kronecker.h:14
void PutSeed(const int &_Seed)
Definition: dt.cpp:18

Here is the call graph for this function:

Here is the caller graph for this function:

void TKronMtx::SaveTxt ( const TStr OutFNm) const

Definition at line 14 of file kronecker.cpp.

References At(), TStr::CStr(), and GetDim().

14  {
15  FILE *F = fopen(OutFNm.CStr(), "wt");
16  for (int i = 0; i < GetDim(); i++) {
17  for (int j = 0; j < GetDim(); j++) {
18  if (j > 0) fprintf(F, "\t");
19  fprintf(F, "%f", At(i,j)); }
20  fprintf(F, "\n");
21  }
22  fclose(F);
23 }
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46
int GetDim() const
Definition: kronecker.h:30
char * CStr()
Definition: dt.h:476

Here is the call graph for this function:

void TKronMtx::SetEpsMtx ( const double &  Eps1,
const double &  Eps0,
const int &  Eps1Val = 1,
const int &  Eps0Val = 0 
)

Definition at line 50 of file kronecker.cpp.

References At(), and Len().

50  {
51  for (int i = 0; i < Len(); i++) {
52  double& Val = At(i);
53  if (Val == Eps1Val) Val = double(Eps1);
54  else if (Val == Eps0Val) Val = double(Eps0);
55  }
56 }
int Len() const
Definition: kronecker.h:31
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46

Here is the call graph for this function:

void TKronMtx::SetForEdges ( const int &  Nodes,
const int &  Edges 
)

Definition at line 59 of file kronecker.cpp.

References At(), GetKronIter(), GetMtxSum(), and Len().

Referenced by GetInitMtx().

59  {
60  const int KronIter = GetKronIter(Nodes);
61  const double EZero = pow((double) Edges, 1.0/double(KronIter));
62  const double Factor = EZero / GetMtxSum();
63  for (int i = 0; i < Len(); i++) {
64  At(i) *= Factor;
65  if (At(i) > 1) { At(i) = 1; }
66  }
67 }
double GetMtxSum() const
Definition: kronecker.cpp:140
int GetKronIter(const int &Nodes) const
Definition: kronecker.cpp:127
int Len() const
Definition: kronecker.h:31
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46

Here is the call graph for this function:

Here is the caller graph for this function:

void TKronMtx::SetMtx ( const TFltV ParamV)
inline

Definition at line 37 of file kronecker.h.

References SeedMtx.

37 { SeedMtx = ParamV; }
TFltV SeedMtx
Definition: kronecker.h:17
void TKronMtx::SetRndMtx ( const int &  MtxDim,
const double &  MinProb = 0.0 
)

Definition at line 40 of file kronecker.cpp.

References TVec< TVal, TSizeTy >::Gen(), TRnd::GetUniDev(), TVec< TVal, TSizeTy >::Len(), MtxDim, and SeedMtx.

Referenced by GetRndMtx().

40  {
41  MtxDim = PrmMtxDim;
43  for (int p = 0; p < SeedMtx.Len(); p++) {
44  do {
46  } while (SeedMtx[p] < MinProb);
47  }
48 }
static TRnd Rnd
Definition: kronecker.h:14
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TInt MtxDim
Definition: kronecker.h:16
double GetUniDev()
Definition: dt.h:30
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
TFltV SeedMtx
Definition: kronecker.h:17

Here is the call graph for this function:

Here is the caller graph for this function:

void TKronMtx::Swap ( TKronMtx KronMtx)

Definition at line 114 of file kronecker.cpp.

References MtxDim, SeedMtx, and TVec< TVal, TSizeTy >::Swap().

Referenced by KronPwr().

114  {
115  ::Swap(MtxDim, KronMtx.MtxDim);
116  SeedMtx.Swap(KronMtx.SeedMtx);
117 }
void Swap(TKronMtx &KronMtx)
Definition: kronecker.cpp:114
TInt MtxDim
Definition: kronecker.h:16
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
Definition: ds.h:1101
TFltV SeedMtx
Definition: kronecker.h:17

Here is the call graph for this function:

Here is the caller graph for this function:

void TKronMtx::ToOneMinusMtx ( )

Definition at line 91 of file kronecker.cpp.

References At(), IAssert, and Len().

91  {
92  for (int i = 0; i < Len(); i++) {
93  IAssert(At(i) >= 0.0 && At(i) <= 1.0);
94  At(i) = 1.0 - At(i);
95  }
96 }
#define IAssert(Cond)
Definition: bd.h:262
int Len() const
Definition: kronecker.h:31
const double & At(const int &Row, const int &Col) const
Definition: kronecker.h:46

Here is the call graph for this function:

Member Data Documentation

const double TKronMtx::NInf = -DBL_MAX
static
TRnd TKronMtx::Rnd = TRnd(0)
static

Definition at line 14 of file kronecker.h.

Referenced by AddRndNoise(), GenDetKronecker(), GenFastKronecker(), GenKronecker(), and PutRndSeed().


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