|
SNAP Library 2.0, User Reference
2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <kronecker.h>
Public Member Functions | |
| TKronMtx () | |
| TKronMtx (const int &Dim) | |
| TKronMtx (const TFltV &SeedMatrix) | |
| TKronMtx (const TKronMtx &Kronecker) | |
| void | SaveTxt (const TStr &OutFNm) const |
| TKronMtx & | operator= (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 |
| TFltV & | GetMtx () |
| const TFltV & | GetMtx () 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 |
Definition at line 11 of file kronecker.h.
| TKronMtx::TKronMtx | ( | ) | [inline] |
Definition at line 19 of file kronecker.h.
| TKronMtx::TKronMtx | ( | const int & | Dim | ) | [inline] |
Definition at line 20 of file kronecker.h.
| TKronMtx::TKronMtx | ( | const TFltV & | SeedMatrix | ) |
| TKronMtx::TKronMtx | ( | const TKronMtx & | Kronecker | ) | [inline] |
| void TKronMtx::AddRndNoise | ( | const double & | SDev | ) |
Definition at line 69 of file kronecker.cpp.
| const double& TKronMtx::At | ( | const int & | Row, |
| const int & | Col | ||
| ) | const [inline] |
Definition at line 46 of file kronecker.h.
| double& TKronMtx::At | ( | const int & | Row, |
| const int & | Col | ||
| ) | [inline] |
Definition at line 47 of file kronecker.h.
| const double& TKronMtx::At | ( | const int & | ValN | ) | const [inline] |
Definition at line 48 of file kronecker.h.
{ return SeedMtx[ValN].Val; }
| double& TKronMtx::At | ( | const int & | ValN | ) | [inline] |
Definition at line 49 of file kronecker.h.
{ return SeedMtx[ValN].Val; }
| void TKronMtx::Dump | ( | const TStr & | MtxNm = TStr(), |
| const bool & | Sort = false |
||
| ) | const |
Definition at line 636 of file kronecker.cpp.
{
/*printf("%s: %d x %d\n", MtxNm.Empty()?"Mtx":MtxNm.CStr(), GetDim(), GetDim());
for (int r = 0; r < GetDim(); r++) {
for (int c = 0; c < GetDim(); c++) { printf(" %8.2g", At(r, c)); }
printf("\n");
}*/
if (! MtxNm.Empty()) printf("%s\n", MtxNm.CStr());
double Sum=0.0;
TFltV ValV = SeedMtx;
if (Sort) { ValV.Sort(false); }
for (int i = 0; i < ValV.Len(); i++) {
printf(" %10.4g", ValV[i]());
Sum += ValV[i];
if ((i+1) % GetDim() == 0) { printf("\n"); }
}
printf(" (sum:%.4f)\n", Sum);
}
| bool TKronMtx::Empty | ( | ) | const [inline] |
Definition at line 32 of file kronecker.h.
| PNGraph TKronMtx::GenDetKronecker | ( | const TKronMtx & | SeedMtx, |
| const int & | NIter, | ||
| const bool & | IsDir | ||
| ) | [static] |
Definition at line 458 of file kronecker.cpp.
{
const TKronMtx& SeedGraph = SeedMtx;
const int NNodes = SeedGraph.GetNodes(NIter);
printf(" Deterministic Kronecker: %d nodes, %s...\n", NNodes, IsDir ? "Directed":"UnDirected");
PNGraph Graph = TNGraph::New(NNodes, -1);
TExeTm ExeTm;
int edges = 0;
for (int node1 = 0; node1 < NNodes; node1++) { Graph->AddNode(node1); }
for (int node1 = 0; node1 < NNodes; node1++) {
for (int node2 = 0; node2 < NNodes; node2++) {
if (SeedGraph.IsEdgePlace(node1, node2, NIter, Rnd.GetUniDev())) {
Graph->AddEdge(node1, node2);
edges++;
}
}
if (node1 % 1000 == 0) printf("\r...%dk, %dk", node1/1000, edges/1000);
}
return Graph;
}
| 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.
{
const TKronMtx& SeedGraph = SeedMtx;
const int MtxDim = SeedGraph.GetDim();
const double MtxSum = SeedGraph.GetMtxSum();
const int NNodes = SeedGraph.GetNodes(NIter);
const int NEdges = SeedGraph.GetEdges(NIter);
//const double DiagEdges = NNodes * pow(SeedGraph.At(0,0), double(NIter));
//const int NEdges = (int) TMath::Round(((pow(double(SeedGraph.GetMtxSum()), double(NIter)) - DiagEdges) /2.0));
printf(" FastKronecker: %d nodes, %d edges, %s...\n", NNodes, NEdges, IsDir ? "Directed":"UnDirected");
PNGraph Graph = TNGraph::New(NNodes, -1);
TRnd Rnd(Seed);
TExeTm ExeTm;
// prepare cell probability vector
TVec<TFltIntIntTr> ProbToRCPosV; // row, col position
double CumProb = 0.0;
for (int r = 0; r < MtxDim; r++) {
for (int c = 0; c < MtxDim; c++) {
const double Prob = SeedGraph.At(r, c);
if (Prob > 0.0) {
CumProb += Prob;
ProbToRCPosV.Add(TFltIntIntTr(CumProb/MtxSum, r, c));
}
}
}
// add nodes
for (int i = 0; i < NNodes; i++) {
Graph->AddNode(i); }
// add edges
int Rng, Row, Col, Collision=0, n = 0;
for (int edges = 0; edges < NEdges; ) {
Rng=NNodes; Row=0; Col=0;
for (int iter = 0; iter < NIter; iter++) {
const double& Prob = Rnd.GetUniDev();
n = 0; while(Prob > ProbToRCPosV[n].Val1) { n++; }
const int MtxRow = ProbToRCPosV[n].Val2;
const int MtxCol = ProbToRCPosV[n].Val3;
Rng /= MtxDim;
Row += MtxRow * Rng;
Col += MtxCol * Rng;
}
if (! Graph->IsEdge(Row, Col)) { // allow self-loops
Graph->AddEdge(Row, Col); edges++;
if (! IsDir) {
if (Row != Col) Graph->AddEdge(Col, Row);
edges++;
}
} else { Collision++; }
//if (edges % 1000 == 0) printf("\r...%dk", edges/1000);
}
//printf(" %d edges [%s]\n", Graph->GetEdges(), ExeTm.GetTmStr());
printf(" collisions: %d (%.4f)\n", Collision, Collision/(double)Graph->GetEdges());
return Graph;
}
| 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.
{
const TKronMtx& SeedGraph = SeedMtx;
const int MtxDim = SeedGraph.GetDim();
const double MtxSum = SeedGraph.GetMtxSum();
const int NNodes = SeedGraph.GetNodes(NIter);
const int NEdges = Edges;
//const double DiagEdges = NNodes * pow(SeedGraph.At(0,0), double(NIter));
//const int NEdges = (int) TMath::Round(((pow(double(SeedGraph.GetMtxSum()), double(NIter)) - DiagEdges) /2.0));
printf(" RMat Kronecker: %d nodes, %d edges, %s...\n", NNodes, NEdges, IsDir ? "Directed":"UnDirected");
PNGraph Graph = TNGraph::New(NNodes, -1);
TRnd Rnd(Seed);
TExeTm ExeTm;
// prepare cell probability vector
TVec<TFltIntIntTr> ProbToRCPosV; // row, col position
double CumProb = 0.0;
for (int r = 0; r < MtxDim; r++) {
for (int c = 0; c < MtxDim; c++) {
const double Prob = SeedGraph.At(r, c);
if (Prob > 0.0) {
CumProb += Prob;
ProbToRCPosV.Add(TFltIntIntTr(CumProb/MtxSum, r, c));
}
}
}
// add nodes
for (int i = 0; i < NNodes; i++) {
Graph->AddNode(i); }
// add edges
int Rng, Row, Col, Collision=0, n = 0;
for (int edges = 0; edges < NEdges; ) {
Rng=NNodes; Row=0; Col=0;
for (int iter = 0; iter < NIter; iter++) {
const double& Prob = Rnd.GetUniDev();
n = 0; while(Prob > ProbToRCPosV[n].Val1) { n++; }
const int MtxRow = ProbToRCPosV[n].Val2;
const int MtxCol = ProbToRCPosV[n].Val3;
Rng /= MtxDim;
Row += MtxRow * Rng;
Col += MtxCol * Rng;
}
if (! Graph->IsEdge(Row, Col)) { // allow self-loops
Graph->AddEdge(Row, Col); edges++;
if (! IsDir) {
if (Row != Col) Graph->AddEdge(Col, Row);
edges++;
}
} else { Collision++; }
//if (edges % 1000 == 0) printf("\r...%dk", edges/1000);
}
//printf(" %d edges [%s]\n", Graph->GetEdges(), ExeTm.GetTmStr());
printf(" collisions: %d (%.4f)\n", Collision, Collision/(double)Graph->GetEdges());
return Graph;
}
| 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.
{
const TKronMtx& SeedGraph = SeedMtx;
const int NNodes = SeedGraph.GetNodes(NIter);
printf(" Kronecker: %d nodes, %s...\n", NNodes, IsDir ? "Directed":"UnDirected");
PNGraph Graph = TNGraph::New(NNodes, -1);
TExeTm ExeTm;
TRnd Rnd(Seed);
int edges = 0;
for (int node1 = 0; node1 < NNodes; node1++) {
Graph->AddNode(node1); }
if (IsDir) {
for (int node1 = 0; node1 < NNodes; node1++) {
for (int node2 = 0; node2 < NNodes; node2++) {
if (SeedGraph.IsEdgePlace(node1, node2, NIter, Rnd.GetUniDev())) {
Graph->AddEdge(node1, node2);
edges++;
}
}
if (node1 % 1000 == 0) printf("\r...%dk, %dk", node1/1000, edges/1000);
}
} else {
for (int node1 = 0; node1 < NNodes; node1++) {
for (int node2 = node1; node2 < NNodes; node2++) {
if (SeedGraph.IsEdgePlace(node1, node2, NIter, Rnd.GetUniDev())) {
Graph->AddEdge(node1, node2);
Graph->AddEdge(node2, node1);
edges++;
}
}
if (node1 % 1000 == 0) printf("\r...%dk, %dk", node1/1000, edges/1000);
}
}
printf("\r %d edges [%s]\n", Graph->GetEdges(), ExeTm.GetTmStr());
return Graph;
}
| void TKronMtx::GenMtx | ( | const int & | Dim | ) | [inline] |
Definition at line 40 of file kronecker.h.
| PNGraph TKronMtx::GenRndGraph | ( | const double & | RndFact = 1.0 | ) | const |
Definition at line 295 of file kronecker.cpp.
{
PNGraph Graph = TNGraph::New();
for (int i = 0; i < GetDim(); i++) {
Graph->AddNode(i); }
for (int r = 0; r < GetDim(); r++) {
for (int c = 0; c < GetDim(); c++) {
if (RndFact * At(r, c) >= TKronMtx::Rnd.GetUniDev()) { Graph->AddEdge(r, c); }
}
}
return Graph;
}
| PNGraph TKronMtx::GenThreshGraph | ( | const double & | Thresh | ) | const |
Definition at line 283 of file kronecker.cpp.
| double TKronMtx::GetApxNoEdgeDLL | ( | const int & | ParamId, |
| int | NId1, | ||
| int | NId2, | ||
| const int & | NKronIters | ||
| ) | const |
Definition at line 240 of file kronecker.cpp.
{
const int& ThetaX = ParamId % GetDim();
const int& ThetaY = ParamId / GetDim();
int ThetaCnt = 0;
double DLL = 0;//, LL = 0;
for (int level = 0; level < NKronIters; level++) {
const int X = NId1 % MtxDim;
const int Y = NId2 % MtxDim;
const double LVal = At(X, Y); IAssert(LVal > NInf);
if (X == ThetaX && Y == ThetaY) {
if (ThetaCnt != 0) { DLL += LVal; }
ThetaCnt++;
} else { DLL += LVal; }
//LL += LVal;
NId1 /= MtxDim; NId2 /= MtxDim;
}
//return -ThetaCnt*exp(DLL)*(1.0 + exp(LL)); // -x'/(1+x) WRONG!
// deriv = -(ax^(a-1)*y^b..) - a*x^(2a-1)*y^2b..
// = - (ax^(a-1)*y^b..) - a*x*(x^(a-1)*y^b..)^2
return -ThetaCnt*exp(DLL) - ThetaCnt*exp(At(ThetaX, ThetaY)+2*DLL);
}
| double TKronMtx::GetApxNoEdgeLL | ( | int | NId1, |
| int | NId2, | ||
| const int & | NKronIters | ||
| ) | const |
Definition at line 191 of file kronecker.cpp.
{
const double EdgeLL = GetEdgeLL(NId1, NId2, NKronIters);
return -exp(EdgeLL) - 0.5*exp(2*EdgeLL);
}
| double TKronMtx::GetAvgAbsErr | ( | const TKronMtx & | Kron1, |
| const TKronMtx & | Kron2 | ||
| ) | [static] |
| double TKronMtx::GetAvgFroErr | ( | const TKronMtx & | Kron1, |
| const TKronMtx & | Kron2 | ||
| ) | [static] |
| double TKronMtx::GetColSum | ( | const int & | ColId | ) | const |
Definition at line 154 of file kronecker.cpp.
| int TKronMtx::GetDim | ( | ) | const [inline] |
Definition at line 30 of file kronecker.h.
{ return MtxDim; }
| double TKronMtx::GetEdgeDLL | ( | const int & | ParamId, |
| int | NId1, | ||
| int | NId2, | ||
| const int & | NKronIters | ||
| ) | const |
Definition at line 207 of file kronecker.cpp.
{
const int ThetaX = ParamId % GetDim();
const int ThetaY = ParamId / GetDim();
int ThetaCnt = 0;
for (int level = 0; level < NKronIters; level++) {
if ((NId1 % MtxDim) == ThetaX && (NId2 % MtxDim) == ThetaY) {
ThetaCnt++; }
NId1 /= MtxDim; NId2 /= MtxDim;
}
return double(ThetaCnt) / exp(At(ParamId));
}
| double TKronMtx::GetEdgeLL | ( | int | NId1, |
| int | NId2, | ||
| const int & | NKronIters | ||
| ) | const |
| double TKronMtx::GetEdgeProb | ( | int | NId1, |
| int | NId2, | ||
| const int & | NKronIters | ||
| ) | const |
| double TKronMtx::GetEdgeProb | ( | const uint & | NId1Sig, |
| const uint & | NId2Sig, | ||
| const int & | NIter | ||
| ) | const |
| int TKronMtx::GetEdges | ( | const int & | NIter | ) | const |
Definition at line 123 of file kronecker.cpp.
{
return (int) pow(double(GetMtxSum()), double(NIter));
}
| double TKronMtx::GetEZero | ( | const int & | Edges, |
| const int & | KronIter | ||
| ) | const |
Definition at line 136 of file kronecker.cpp.
{
return pow((double) Edges, 1.0/double(KronIters));
}
| TKronMtx TKronMtx::GetInitMtx | ( | const int & | Dim, |
| const int & | Nodes, | ||
| const int & | Edges | ||
| ) | [static] |
Definition at line 705 of file kronecker.cpp.
{
const double MxParam = 0.8+TKronMtx::Rnd.GetUniDev()/5.0;
const double MnParam = 0.2-TKronMtx::Rnd.GetUniDev()/5.0;
const double Step = (MxParam-MnParam) / (Dim*Dim-1);
TFltV ParamV(Dim*Dim);
if (Dim == 1) { ParamV.PutAll(0.5); } // random graph
else {
for (int p = 0; p < ParamV.Len(); p++) {
ParamV[p] = MxParam - p*Step; }
}
//IAssert(ParamV[0]==MxParam && ParamV.Last()==MnParam);
TKronMtx Mtx(ParamV);
Mtx.SetForEdges(Nodes, Edges);
return Mtx;
}
| TKronMtx TKronMtx::GetInitMtx | ( | const TStr & | MtxStr, |
| const int & | Dim, | ||
| const int & | Nodes, | ||
| const int & | Edges | ||
| ) | [static] |
Definition at line 721 of file kronecker.cpp.
{
TKronMtx Mtx(Dim);
if (TCh::IsNum(MtxStr[0])) { Mtx = TKronMtx::GetMtx(MtxStr); }
else if (MtxStr[0] == 'r') { Mtx = TKronMtx::GetRndMtx(Dim, 0.1); }
else if (MtxStr[0] == 'a') {
const double Prob = TKronMtx::Rnd.GetUniDev();
if (Prob < 0.4) {
Mtx = TKronMtx::GetInitMtx(Dim, Nodes, Edges); }
else { // interpolate so that there are in the corners 0.9, 0.5, 0.1, 0.5
const double Max = 0.9+TKronMtx::Rnd.GetUniDev()/10.0;
const double Min = 0.1-TKronMtx::Rnd.GetUniDev()/10.0;
const double Med = (Max-Min)/2.0;
Mtx.At(0,0) = Max; Mtx.At(0,Dim-1) = Med;
Mtx.At(Dim-1, 0) = Med; Mtx.At(Dim-1, Dim-1) = Min;
for (int i = 1; i < Dim-1; i++) {
Mtx.At(i,i) = Max - double(i)*(Max-Min)/double(Dim-1);
Mtx.At(i, 0) = Mtx.At(0, i) = Max - double(i)*(Max-Med)/double(Dim-1);
Mtx.At(i, Dim-1) = Mtx.At(Dim-1, i) = Med - double(i)*(Med-Min)/double(Dim-1);
}
for (int i = 1; i < Dim-1; i++) {
for (int j = 1; j < Dim-1; j++) {
if (i >= j) { continue; }
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);
}
}
Mtx.AddRndNoise(0.1);
}
} else { FailR("Wrong mtx: matlab str, or random (r), or all (a)"); }
Mtx.SetForEdges(Nodes, Edges);
return Mtx;
}
| int TKronMtx::GetKronIter | ( | const int & | Nodes | ) | const |
Definition at line 127 of file kronecker.cpp.
{
return (int) ceil(log(double(Nodes)) / log(double(GetDim()))); // upper bound
//return (int) TMath::Round(log(double(Nodes)) / log(double(GetDim()))); // round to nearest power
}
| int TKronMtx::GetKronIter | ( | const int & | GNodes, |
| const int & | SeedMtxSz | ||
| ) | [static] |
Definition at line 307 of file kronecker.cpp.
{
return (int) ceil(log(double(GNodes)) / log(double(SeedMtxSz)));
}
| void TKronMtx::GetLLMtx | ( | TKronMtx & | LLMtx | ) |
| TFltV& TKronMtx::GetMtx | ( | ) | [inline] |
Definition at line 35 of file kronecker.h.
{ return SeedMtx; }
| const TFltV& TKronMtx::GetMtx | ( | ) | const [inline] |
Definition at line 36 of file kronecker.h.
{ return SeedMtx; }
| TKronMtx TKronMtx::GetMtx | ( | TStr | MatlabMtxStr | ) | [static] |
Definition at line 681 of file kronecker.cpp.
{
TStrV RowStrV, ColStrV;
MatlabMtxStr.ChangeChAll(',', ' ');
MatlabMtxStr.SplitOnAllCh(';', RowStrV); IAssert(! RowStrV.Empty());
RowStrV[0].SplitOnWs(ColStrV); IAssert(! ColStrV.Empty());
const int Rows = RowStrV.Len();
const int Cols = ColStrV.Len();
IAssert(Rows == Cols);
TKronMtx Mtx(Rows);
for (int r = 0; r < Rows; r++) {
RowStrV[r].SplitOnWs(ColStrV);
IAssert(ColStrV.Len() == Cols);
for (int c = 0; c < Cols; c++) {
Mtx.At(r, c) = (double) ColStrV[c].GetFlt(); }
}
return Mtx;
}
| TKronMtx TKronMtx::GetMtxFromNm | ( | const TStr & | MtxNm | ) | [static] |
Definition at line 753 of file kronecker.cpp.
{
if (MtxNm == "3chain") return TKronMtx::GetMtx("1 1 0; 1 1 1; 0 1 1");
else if (MtxNm == "4star") return TKronMtx::GetMtx("1 1 1 1; 1 1 0 0 ; 1 0 1 0; 1 0 0 1");
else if (MtxNm == "4chain") return TKronMtx::GetMtx("1 1 0 0; 1 1 1 0 ; 0 1 1 1; 0 0 1 1");
else if (MtxNm == "4square") return TKronMtx::GetMtx("1 1 0 1; 1 1 1 0 ; 0 1 1 1; 1 0 1 1");
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");
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");
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");
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");
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");
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");
FailR(TStr::Fmt("Unknow matrix: '%s'", MtxNm.CStr()).CStr());
return TKronMtx();
}
| TStr TKronMtx::GetMtxStr | ( | ) | const |
| double TKronMtx::GetMtxSum | ( | ) | const |
Definition at line 140 of file kronecker.cpp.
| int TKronMtx::GetNodes | ( | const int & | NIter | ) | const |
Definition at line 119 of file kronecker.cpp.
{
return (int) pow(double(GetDim()), double(NIter));
}
| uint TKronMtx::GetNodeSig | ( | const double & | OneProb = 0.5 | ) | [static] |
Definition at line 262 of file kronecker.cpp.
{
uint Sig = 0;
for (int i = 0; i < (int)(8*sizeof(uint)); i++) {
if (TKronMtx::Rnd.GetUniDev() < OneProb) {
Sig |= (1u<<i); }
}
return Sig;
}
| double TKronMtx::GetNoEdgeDLL | ( | const int & | ParamId, |
| int | NId1, | ||
| int | NId2, | ||
| const int & | NKronIters | ||
| ) | const |
Definition at line 220 of file kronecker.cpp.
{
const int& ThetaX = ParamId % GetDim();
const int& ThetaY = ParamId / GetDim();
int ThetaCnt = 0;
double DLL = 0, LL = 0;
for (int level = 0; level < NKronIters; level++) {
const int X = NId1 % MtxDim;
const int Y = NId2 % MtxDim;
const double LVal = At(X, Y);
if (X == ThetaX && Y == ThetaY) {
if (ThetaCnt != 0) { DLL += LVal; }
ThetaCnt++;
} else { DLL += LVal; }
LL += LVal;
NId1 /= MtxDim; NId2 /= MtxDim;
}
return -ThetaCnt*exp(DLL) / (1.0 - exp(LL));
}
| double TKronMtx::GetNoEdgeLL | ( | int | NId1, |
| int | NId2, | ||
| const int & | NKronIters | ||
| ) | const |
Definition at line 186 of file kronecker.cpp.
{
return log(1.0 - exp(GetEdgeLL(NId1, NId2, NKronIters)));
}
| double TKronMtx::GetNoEdgeProb | ( | int | NId1, |
| int | NId2, | ||
| const int & | NKronIters | ||
| ) | const |
Definition at line 171 of file kronecker.cpp.
{
return 1.0 - GetEdgeProb(NId1, NId2, NKronIters);
}
| int TKronMtx::GetNZeroK | ( | const PNGraph & | Graph | ) | const |
Definition at line 132 of file kronecker.cpp.
{
return GetNodes(GetKronIter(Graph->GetNodes()));
}
| int TKronMtx::GetPrimHashCd | ( | ) | const [inline] |
Definition at line 26 of file kronecker.h.
{ return SeedMtx.GetPrimHashCd(); }
| void TKronMtx::GetProbMtx | ( | TKronMtx & | ProbMtx | ) |
| TKronMtx TKronMtx::GetRndMtx | ( | const int & | Dim, |
| const double & | MinProb | ||
| ) | [static] |
Definition at line 699 of file kronecker.cpp.
| double TKronMtx::GetRowSum | ( | const int & | RowId | ) | const |
Definition at line 147 of file kronecker.cpp.
| int TKronMtx::GetSecHashCd | ( | ) | const [inline] |
Definition at line 27 of file kronecker.h.
{ return SeedMtx.GetSecHashCd(); }
| bool TKronMtx::IsEdgePlace | ( | int | NId1, |
| int | NId2, | ||
| const int & | NKronIters, | ||
| const double & | ProbTresh | ||
| ) | const |
| bool TKronMtx::IsProbMtx | ( | ) | const |
Definition at line 33 of file kronecker.cpp.
| void TKronMtx::KronMul | ( | const TKronMtx & | LeftPt, |
| const TKronMtx & | RightPt, | ||
| TKronMtx & | OutMtx | ||
| ) | [static] |
Definition at line 591 of file kronecker.cpp.
{
const int LDim = Left.GetDim();
const int RDim = Right.GetDim();
Result.GenMtx(LDim * RDim);
for (int r1 = 0; r1 < LDim; r1++) {
for (int c1 = 0; c1 < LDim; c1++) {
const double& Val = Left.At(r1, c1);
for (int r2 = 0; r2 < RDim; r2++) {
for (int c2 = 0; c2 < RDim; c2++) {
Result.At(r1*RDim+r2, c1*RDim+c2) = Val * Right.At(r2, c2);
}
}
}
}
}
| void TKronMtx::KronPwr | ( | const TKronMtx & | KronPt, |
| const int & | NIter, | ||
| TKronMtx & | OutMtx | ||
| ) | [static] |
Definition at line 626 of file kronecker.cpp.
| void TKronMtx::KronSum | ( | const TKronMtx & | LeftPt, |
| const TKronMtx & | RightPt, | ||
| TKronMtx & | OutMtx | ||
| ) | [static] |
Definition at line 607 of file kronecker.cpp.
{
const int LDim = Left.GetDim();
const int RDim = Right.GetDim();
Result.GenMtx(LDim * RDim);
for (int r1 = 0; r1 < LDim; r1++) {
for (int c1 = 0; c1 < LDim; c1++) {
const double& Val = Left.At(r1, c1);
for (int r2 = 0; r2 < RDim; r2++) {
for (int c2 = 0; c2 < RDim; c2++) {
if (Val == NInf || Right.At(r2, c2) == NInf) {
Result.At(r1*RDim+r2, c1*RDim+c2) = NInf; }
else {
Result.At(r1*RDim+r2, c1*RDim+c2) = Val + Right.At(r2, c2); }
}
}
}
}
}
| int TKronMtx::Len | ( | ) | const [inline] |
Definition at line 31 of file kronecker.h.
| TKronMtx TKronMtx::LoadTxt | ( | const TStr & | MtxFNm | ) | [static] |
Definition at line 768 of file kronecker.cpp.
{
PSs Ss = TSs::LoadTxt(ssfTabSep, MtxFNm);
IAssertR(Ss->GetXLen() == Ss->GetYLen(), "Not a square matrix");
IAssert(Ss->GetYLen() == Ss->GetXLen());
TKronMtx Mtx(Ss->GetYLen());
for (int r = 0; r < Ss->GetYLen(); r++) {
for (int c = 0; c < Ss->GetXLen(); c++) {
Mtx.At(r, c) = (double) Ss->At(c, r).GetFlt(); }
}
return Mtx;
}
| bool TKronMtx::operator== | ( | const TKronMtx & | Kronecker | ) | const [inline] |
Definition at line 25 of file kronecker.h.
| void TKronMtx::PlotCmpGraphs | ( | const TKronMtx & | SeedMtx, |
| const PNGraph & | Graph, | ||
| const TStr & | OutFNm, | ||
| const TStr & | Desc | ||
| ) | [static] |
Definition at line 479 of file kronecker.cpp.
{
const int KronIters = SeedMtx.GetKronIter(Graph->GetNodes());
PNGraph KronG, WccG;
const bool FastGen = true;
if (FastGen) { KronG = TKronMtx::GenFastKronecker(SeedMtx, KronIters, true, 0); }
else { KronG = TKronMtx::GenKronecker(SeedMtx, KronIters, true, 0); }
TSnap::DelZeroDegNodes(KronG);
WccG = TSnap::GetMxWcc(KronG);
const TStr Desc1 = TStr::Fmt("%s", Desc.CStr());
TGStatVec GS(tmuNodes, TFSet() | gsdInDeg | gsdOutDeg | gsdWcc | gsdHops | gsdScc | gsdClustCf | gsdSngVec | gsdSngVal);
//gsdHops
//gsWccHops, gsdSngVal, gsdSngVec, gsdClustCf
GS.Add(Graph, TSecTm(1), TStr::Fmt("GRAPH G(%d, %d)", Graph->GetNodes(), Graph->GetEdges()));
GS.Add(KronG, TSecTm(2), TStr::Fmt("KRONECKER K(%d, %d)", KronG->GetNodes(), KronG->GetEdges()));
GS.Add(WccG, TSecTm(3), TStr::Fmt("KRONECKER wccK(%d, %d)", WccG->GetNodes(), WccG->GetEdges()));
const TStr Style = "linewidth 1 pointtype 6 pointsize 1";
GS.ImposeDistr(gsdInDeg, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdInDeg, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdOutDeg, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdOutDeg, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdHops, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdClustCf, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdClustCf, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdSngVal, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdSngVal, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdSngVec, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdSngVec, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdWcc, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdWcc, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdScc, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdScc, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
// typedef enum { distrUndef, distrInDeg, distrOutDeg, distrWcc, distrScc,
// distrHops, distrWccHops, distrSngVal, distrSngVec, distrClustCf, distrMx } TGraphDistr;*/
}
| 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.
{
const int KronIters1 = SeedMtx1.GetKronIter(Graph->GetNodes());
const int KronIters2 = SeedMtx2.GetKronIter(Graph->GetNodes());
PNGraph KronG1, KronG2;
const bool FastGen = true;
if (FastGen) {
KronG1 = TKronMtx::GenFastKronecker(SeedMtx1, KronIters1, true, 0);
KronG2 = TKronMtx::GenFastKronecker(SeedMtx2, KronIters2, false, 0); }
else {
KronG1 = TKronMtx::GenKronecker(SeedMtx1, KronIters1, true, 0);
KronG2 = TKronMtx::GenKronecker(SeedMtx2, KronIters2, true, 0); }
TSnap::DelZeroDegNodes(KronG1);
TSnap::DelZeroDegNodes(KronG2);
const TStr Desc1 = TStr::Fmt("%s", Desc.CStr());
TGStatVec GS(tmuNodes, TFSet() | gsdInDeg | gsdOutDeg | gsdWcc | gsdScc | gsdHops | gsdClustCf | gsdSngVec | gsdSngVal | gsdTriadPart);
//gsdHops
//gsWccHops, gsdSngVal, gsdSngVec, gsdClustCf
GS.Add(Graph, TSecTm(1), TStr::Fmt("GRAPH G(%d, %d)", Graph->GetNodes(), Graph->GetEdges()));
GS.Add(KronG1, TSecTm(2), TStr::Fmt("KRONECKER1 K(%d, %d) %s", KronG1->GetNodes(), KronG1->GetEdges(), SeedMtx1.GetMtxStr().CStr()));
GS.Add(KronG2, TSecTm(3), TStr::Fmt("KRONECKER2 K(%d, %d) %s", KronG2->GetNodes(), KronG2->GetEdges(), SeedMtx2.GetMtxStr().CStr()));
const TStr Style = "linewidth 1 pointtype 6 pointsize 1";
// raw data
GS.ImposeDistr(gsdInDeg, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdOutDeg, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdHops, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdClustCf, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdSngVal, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdSngVec, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdWcc, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdScc, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdTriadPart, FNmPref, Desc1, false, false, gpwLinesPoints, Style);
// smooth
GS.ImposeDistr(gsdInDeg, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdOutDeg, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdClustCf, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdScc, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdWcc, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdSngVec, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdSngVal, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
GS.ImposeDistr(gsdTriadPart, FNmPref+"-B", Desc1, true, false, gpwLinesPoints, Style);
}
| 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.
{
const TStr Desc1 = TStr::Fmt("%s", Desc.CStr());
TGStatVec GS(tmuNodes, TFSet() | gsdInDeg | gsdOutDeg | gsdWcc | gsdScc | gsdHops | gsdClustCf | gsdSngVec | gsdSngVal);
GS.Add(Graph, TSecTm(1), TStr::Fmt("GRAPH G(%d, %d)", Graph->GetNodes(), Graph->GetEdges()));
//gsdHops
//gsWccHops, gsdSngVal, gsdSngVec, gsdClustCf
for (int m = 0; m < SeedMtxV.Len(); m++) {
const int KronIters = SeedMtxV[m].GetKronIter(Graph->GetNodes());
PNGraph KronG1 = TKronMtx::GenFastKronecker(SeedMtxV[m], KronIters, true, 0);
printf("*** K(%d, %d) n0=%d\n", KronG1->GetNodes(), KronG1->GetEdges(), SeedMtxV[m].GetDim());
TSnap::DelZeroDegNodes(KronG1);
printf(" del zero deg K(%d, %d) n0=%d\n", KronG1->GetNodes(), KronG1->GetEdges(), m);
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()));
// plot after each Kronecker is done
const TStr Style = "linewidth 1 pointtype 6 pointsize 1";
GS.ImposeDistr(gsdInDeg, FNmPref, Desc1, false, false, gpwLines, Style);
GS.ImposeDistr(gsdInDeg, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
GS.ImposeDistr(gsdOutDeg, FNmPref, Desc1, false, false, gpwLines, Style);
GS.ImposeDistr(gsdOutDeg, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
GS.ImposeDistr(gsdHops, FNmPref, Desc1, false, false, gpwLines, Style);
GS.ImposeDistr(gsdClustCf, FNmPref, Desc1, false, false, gpwLines, Style);
GS.ImposeDistr(gsdClustCf, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
GS.ImposeDistr(gsdSngVal, FNmPref, Desc1, false, false, gpwLines, Style);
GS.ImposeDistr(gsdSngVal, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
GS.ImposeDistr(gsdSngVec, FNmPref, Desc1, false, false, gpwLines, Style);
GS.ImposeDistr(gsdSngVec, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
GS.ImposeDistr(gsdWcc, FNmPref, Desc1, false, false, gpwLines, Style);
GS.ImposeDistr(gsdWcc, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
GS.ImposeDistr(gsdScc, FNmPref, Desc1, false, false, gpwLines, Style);
GS.ImposeDistr(gsdScc, FNmPref+"-B", Desc1, true, false, gpwLines, Style);
}
// typedef enum { distrUndef, distrInDeg, distrOutDeg, distrWcc, distrScc,
// distrHops, distrWccHops, distrSngVal, distrSngVec, distrClustCf, distrMx } TGraphDistr;*/
}
| void TKronMtx::PutAllMtx | ( | const double & | Val | ) | [inline] |
Definition at line 39 of file kronecker.h.
| static void TKronMtx::PutRndSeed | ( | const int & | Seed | ) | [inline, static] |
Definition at line 108 of file kronecker.h.
{ TKronMtx::Rnd.PutSeed(Seed); }
| void TKronMtx::SaveTxt | ( | const TStr & | OutFNm | ) | const |
| 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.
| void TKronMtx::SetForEdges | ( | const int & | Nodes, |
| const int & | Edges | ||
| ) |
Definition at line 59 of file kronecker.cpp.
| void TKronMtx::SetMtx | ( | const TFltV & | ParamV | ) | [inline] |
Definition at line 37 of file kronecker.h.
{ SeedMtx = ParamV; }
| void TKronMtx::SetRndMtx | ( | const int & | MtxDim, |
| const double & | MinProb = 0.0 |
||
| ) |
| void TKronMtx::Swap | ( | TKronMtx & | KronMtx | ) |
| void TKronMtx::ToOneMinusMtx | ( | ) |
TInt TKronMtx::MtxDim [private] |
Definition at line 16 of file kronecker.h.
const double TKronMtx::NInf = -DBL_MAX [static] |
Definition at line 13 of file kronecker.h.
TRnd TKronMtx::Rnd = TRnd(0) [static] |
Definition at line 14 of file kronecker.h.
TFltV TKronMtx::SeedMtx [private] |
Definition at line 17 of file kronecker.h.