| 
    SNAP Library 2.0, Developer 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.
Referenced by GetMtxFromNm().

| 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.
References At(), Dump(), TRnd::GetNrmDev(), Len(), and Rnd.
Referenced by GetInitMtx().
                                             {
  Dump("before");
  double NewVal;
  int c =0;
  for (int i = 0; i < Len(); i++) {
    for(c = 0; ((NewVal = At(i)*Rnd.GetNrmDev(1, SDev, 0.8, 1.2)) < 0.01 || NewVal>0.99) && c <1000; c++) { }
    if (c < 999) { At(i) = NewVal; } else { printf("XXXXX\n"); }
  }
  Dump("after");
}


| const double& TKronMtx::At | ( | const int & | Row, | 
| const int & | Col | ||
| ) |  const [inline] | 
        
Definition at line 46 of file kronecker.h.
References MtxDim, and SeedMtx.
Referenced by AddRndNoise(), GenFastKronecker(), GenRndGraph(), GenThreshGraph(), TKroneckerLL::GetApxEmptyGraphDLL(), TKroneckerLL::GetApxEmptyGraphLL(), GetApxNoEdgeDLL(), GetColSum(), GetEdgeDLL(), GetEdgeLL(), GetEdgeProb(), GetInitMtx(), GetLLMtx(), GetMtx(), GetMtxStr(), GetMtxSum(), GetNoEdgeDLL(), GetProbMtx(), GetRowSum(), TKroneckerLL::GradDescent(), TKroneckerLL::GradDescent2(), TKroneckerLL::GradDescentConvergence(), IsEdgePlace(), IsProbMtx(), KronMul(), KronSum(), LoadTxt(), TKronMaxLL::RoundTheta(), TKroneckerLL::RunMStep(), SaveTxt(), TKroneckerLL::SetBestDegPerm(), SetEpsMtx(), SetForEdges(), TKroneckerLL::SetRandomEdges(), TKroneckerLL::TestKronDescent(), and ToOneMinusMtx().

| double& TKronMtx::At | ( | const int & | Row, | 
| const int & | Col | ||
| ) |  [inline] | 
        
| const double& TKronMtx::At | ( | const int & | ValN | ) |  const [inline] | 
        
| double& TKronMtx::At | ( | const int & | ValN | ) |  [inline] | 
        
| 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().
                                                             {
  /*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.
References TVec< TVal, TSizeTy >::Empty(), and SeedMtx.
Referenced by TKroneckerLL::GradDescentConvergence(), and TKroneckerLL::TestSamplePerm().


| 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.
                                                                                              {
  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.
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().
                                                                                                                {
  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.
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.
                                                                                                                                  {
  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.
References TNGraph::AddEdge(), TNGraph::AddNode(), TNGraph::GetEdges(), GetNodes(), TExeTm::GetTmStr(), TRnd::GetUniDev(), IsEdgePlace(), TNGraph::New(), Rnd, and SeedMtx.
Referenced by PlotCmpGraphs().
                                                                                                            {
  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.
References TVec< TVal, TSizeTy >::Gen(), MtxDim, and SeedMtx.
Referenced by GetLLMtx(), GetProbMtx(), KronMul(), KronSum(), and TKronMaxLL::RoundTheta().


| 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().
                                                         {
  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.
References TNGraph::AddEdge(), TNGraph::AddNode(), At(), GetDim(), and TNGraph::New().
                                                           {
  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 (At(r, c) >= Thresh) { Graph->AddEdge(r, c); }
    }
  }
  return Graph;
}

| 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().
                                                                                                    {
  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.
References GetEdgeLL().
Referenced by TKroneckerLL::CalcApxGraphLL(), TKroneckerLL::MetroGibbsSampleNext(), TKroneckerLL::NodeLLDelta(), and TKroneckerLL::SwapNodesLL().
                                                                               {
  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] | 
        
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().
                                                                          {
  TFltV P1 = Kron1.GetMtx();
  TFltV P2 = Kron2.GetMtx();
  IAssert(P1.Len() == P2.Len());
  P1.Sort();  P2.Sort();
  double delta = 0.0;
  for (int i = 0; i < P1.Len(); i++) {
    delta += fabs(P1[i] - P2[i]);
  }
  return delta/P1.Len();
}


| 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().
                                                                          {
  TFltV P1 = Kron1.GetMtx();
  TFltV P2 = Kron2.GetMtx();
  IAssert(P1.Len() == P2.Len());
  P1.Sort();  P2.Sort();
  double delta = 0.0;
  for (int i = 0; i < P1.Len(); i++) {
    delta += pow(P1[i] - P2[i], 2);
  }
  return sqrt(delta/P1.Len());
}

| double TKronMtx::GetColSum | ( | const int & | ColId | ) | const | 
Definition at line 154 of file kronecker.cpp.
References At(), and GetDim().
Referenced by TKroneckerLL::GetFullColLL().


| int TKronMtx::GetDim | ( | ) |  const [inline] | 
        
Definition at line 30 of file kronecker.h.
References MtxDim.
Referenced by TKroneckerLL::AppendIsoNodes(), Dump(), GenFastKronecker(), GenRndGraph(), GenThreshGraph(), GetApxNoEdgeDLL(), GetColSum(), TKroneckerLL::GetDim(), GetEdgeDLL(), GetEdgeProb(), TKroneckerLL::GetFullColLL(), TKroneckerLL::GetFullGraphLL(), TKroneckerLL::GetFullRowLL(), GetKronIter(), GetMtxStr(), GetNodes(), GetNoEdgeDLL(), GetRowSum(), KronMul(), KronSum(), TKroneckerLL::MetroGibbsSampleSetup(), TKroneckerLL::RunMStep(), SaveTxt(), TKroneckerLL::SetBestDegPerm(), TKroneckerLL::SetGraph(), and TKroneckerLL::SetRandomEdges().
{ return MtxDim; }

| 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().
                                                                                               {
  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 | 
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().
                                                                          {
  double LL = 0.0;
  for (int level = 0; level < NKronIters; level++) {
    const double& LLVal = At(NId1 % MtxDim, NId2 % MtxDim);
    if (LLVal == NInf) return NInf;
    LL += LLVal;
    NId1 /= MtxDim;  NId2 /= MtxDim;
  }
  return LL;
}


| double TKronMtx::GetEdgeProb | ( | int | NId1, | 
| int | NId2, | ||
| const int & | NKronIters | ||
| ) | const | 
Definition at line 161 of file kronecker.cpp.
Referenced by GetNoEdgeProb().
                                                                            {
  double Prob = 1.0;
  for (int level = 0; level < NKronIters; level++) {
    Prob *= At(NId1 % MtxDim, NId2 % MtxDim);
    if (Prob == 0.0) { return 0.0; }
    NId1 /= MtxDim;  NId2 /= MtxDim;
  }
  return Prob;
}


| 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().
                                                                                             {
  Assert(GetDim() == 2);
  double Prob = 1.0;
  for (int i = 0; i < NIter; i++) {
    const uint Mask = (1u<<i);
    const uint Bit1 = NId1Sig & Mask;
    const uint Bit2 = NId2Sig & Mask;
    Prob *= At(int(Bit1!=0), int(Bit2!=0));
  }
  return Prob;
}

| 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().
                                             {
  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.
References TRnd::GetUniDev(), TVec< TVal, TSizeTy >::Len(), TVec< TVal, TSizeTy >::PutAll(), and SetForEdges().
Referenced by GetInitMtx(), and TKroneckerLL::TestBicCriterion().
                                                                                {
  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.
References AddRndNoise(), At(), FailR, GetInitMtx(), GetMtx(), GetRndMtx(), TRnd::GetUniDev(), TCh::IsNum(), and SetForEdges().
                                                                                                    {
  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.
References GetDim().
Referenced by GetNZeroK(), PlotCmpGraphs(), SetForEdges(), and TKronMomentsFit::Test().
                                                {
  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 | ) | 
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().
                                       {
  LLMtx.GenMtx(MtxDim);
  for (int i = 0; i < Len(); i++) {
    if (At(i) != 0.0) { LLMtx.At(i) = log(At(i)); }
    else { LLMtx.At(i) = NInf; }
  }
}


| 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().
{ return SeedMtx; }

| const TFltV& TKronMtx::GetMtx | ( | ) |  const [inline] | 
        
| 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().
                                           {
  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.
References TStr::CStr(), FailR, TStr::Fmt(), GetMtx(), and TKronMtx().
                                                 {
  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 | 
Definition at line 80 of file kronecker.cpp.
References At(), TStr::Fmt(), GetDim(), and Len().
Referenced by PlotCmpGraphs().
                               {
  TChA ChA("[");
  for (int i = 0; i < Len(); i++) {
    ChA += TStr::Fmt("%g", At(i));
    if ((i+1)%GetDim()==0 && (i+1<Len())) { ChA += "; "; }
    else if (i+1<Len()) { ChA += ", "; }
  }
  ChA += "]";
  return TStr(ChA);
}


| double TKronMtx::GetMtxSum | ( | ) | const | 
Definition at line 140 of file kronecker.cpp.
Referenced by GenFastKronecker(), TKroneckerLL::GetAbsErr(), GetEdges(), TKroneckerLL::GetFullGraphLL(), TKroneckerLL::GradDescent(), TKroneckerLL::GradDescent2(), TKroneckerLL::GradDescentConvergence(), TKroneckerLL::MetroGibbsSampleSetup(), TKroneckerLL::RunMStep(), SetForEdges(), TKroneckerLL::SetRandomEdges(), and TKroneckerLL::TestKronDescent().


| 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().
                                             {
  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.
References At(), GetDim(), and MtxDim.
Referenced by TKroneckerLL::CalcGraphDLL(), and TKroneckerLL::GetEmptyGraphDLL().
                                                                                                 {
  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.
References GetEdgeLL().
Referenced by TKroneckerLL::CalcGraphLL(), and TKroneckerLL::GetEmptyGraphLL().
                                                                            {
  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.
References GetEdgeProb().
                                                                              {
  return 1.0 - GetEdgeProb(NId1, NId2, NKronIters);
}

| int TKronMtx::GetNZeroK | ( | const PNGraph & | Graph | ) | const | 
Definition at line 132 of file kronecker.cpp.
References GetKronIter(), GetNodes(), and TNGraph::GetNodes().
                                                  {
 return GetNodes(GetKronIter(Graph->GetNodes()));
}

| int TKronMtx::GetPrimHashCd | ( | ) |  const [inline] | 
        
Definition at line 26 of file kronecker.h.
References TVec< TVal, TSizeTy >::GetPrimHashCd(), and SeedMtx.
{ 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.
References SetRndMtx().
Referenced by GetInitMtx().


| double TKronMtx::GetRowSum | ( | const int & | RowId | ) | const | 
Definition at line 147 of file kronecker.cpp.
References At(), and GetDim().
Referenced by TKroneckerLL::GetFullRowLL().


| int TKronMtx::GetSecHashCd | ( | ) |  const [inline] | 
        
Definition at line 27 of file kronecker.h.
References TVec< TVal, TSizeTy >::GetSecHashCd(), and SeedMtx.
{ return SeedMtx.GetSecHashCd(); }

| bool TKronMtx::IsEdgePlace | ( | int | NId1, | 
| int | NId2, | ||
| const int & | NKronIters, | ||
| const double & | ProbTresh | ||
| ) | const | 
Definition at line 196 of file kronecker.cpp.
Referenced by GenDetKronecker(), and GenKronecker().
                                                                                                   {
  double Prob = 1.0;
  for (int level = 0; level < NKronIters; level++) {
    Prob *= At(NId1 % MtxDim, NId2 % MtxDim);
    if (ProbTresh > Prob) { return false; }
    NId1 /= MtxDim;  NId2 /= MtxDim;
  }
  return true;
}


| bool TKronMtx::IsProbMtx | ( | ) | const | 
Definition at line 33 of file kronecker.cpp.
Referenced by TKroneckerLL::InitLL().


| 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().
                                                                                    {
  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] | 
        
| 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.
                                                                                    {
  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.
References TVec< TVal, TSizeTy >::Len(), and SeedMtx.
Referenced by AddRndNoise(), TKroneckerLL::CalcApxGraphDLL(), TKroneckerLL::CalcFullApxGraphDLL(), TKroneckerLL::CalcGraphDLL(), TKroneckerLL::GetApxEmptyGraphDLL(), TKroneckerLL::GetApxEmptyGraphLL(), GetLLMtx(), GetMtxStr(), GetMtxSum(), TKroneckerLL::GetParams(), GetProbMtx(), IsProbMtx(), TKroneckerLL::MetroGibbsSampleNext(), TKroneckerLL::SampleGradient(), SetEpsMtx(), SetForEdges(), TKroneckerLL::SetGraph(), ToOneMinusMtx(), and TKroneckerLL::UpdateGraphDLL().


| TKronMtx TKronMtx::LoadTxt | ( | const TStr & | MtxFNm | ) |  [static] | 
        
Definition at line 768 of file kronecker.cpp.
References At(), IAssert, IAssertR, and ssfTabSep.
                                             {
  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.
References SeedMtx.
| 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.
                                                                                                                 {
  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.
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.
                                                                                                                                            {
  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.
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.
                                                                                                                        {
  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.
References TVec< TVal, TSizeTy >::PutAll(), and SeedMtx.

| static void TKronMtx::PutRndSeed | ( | const int & | Seed | ) |  [inline, static] | 
        
Definition at line 108 of file kronecker.h.
References TRnd::PutSeed(), and Rnd.
Referenced by TKronMaxLL::Test().
{ TKronMtx::Rnd.PutSeed(Seed); }


| void TKronMtx::SaveTxt | ( | const TStr & | OutFNm | ) | const | 
Definition at line 14 of file kronecker.cpp.
References At(), TStr::CStr(), and GetDim().
                                               {
  FILE *F = fopen(OutFNm.CStr(), "wt");
  for (int i = 0; i < GetDim(); i++) {
    for (int j = 0; j < GetDim(); j++) {
      if (j > 0) fprintf(F, "\t");
      fprintf(F, "%f", At(i,j)); }
    fprintf(F, "\n");
  }
  fclose(F);
}

| void TKronMtx::SetEpsMtx | ( | const double & | Eps1, | 
| const double & | Eps0, | ||
| const int & | Eps1Val = 1,  | 
        ||
| const int & | Eps0Val = 0  | 
        ||
| ) | 
| 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().
                                                             {
  const int KronIter = GetKronIter(Nodes);
  const double EZero = pow((double) Edges, 1.0/double(KronIter));
  const double Factor = EZero / GetMtxSum();
  for (int i = 0; i < Len(); i++) {
    At(i) *= Factor;
    if (At(i) > 1) { At(i) = 1; }
  }
}


| void TKronMtx::SetMtx | ( | const TFltV & | ParamV | ) |  [inline] | 
        
| 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().
                                                                    {
  MtxDim = PrmMtxDim;
  SeedMtx.Gen(MtxDim*MtxDim);
  for (int p = 0; p < SeedMtx.Len(); p++) {
    do {
      SeedMtx[p] = TKronMtx::Rnd.GetUniDev();
    } while (SeedMtx[p] < MinProb);
  }
}


| void TKronMtx::Swap | ( | TKronMtx & | KronMtx | ) | 
| void TKronMtx::ToOneMinusMtx | ( | ) | 
TInt TKronMtx::MtxDim [private] | 
        
Definition at line 16 of file kronecker.h.
Referenced by At(), GenFastKronecker(), GenMtx(), GetApxNoEdgeDLL(), GetDim(), GetEdgeDLL(), GetEdgeLL(), GetEdgeProb(), GetLLMtx(), GetNoEdgeDLL(), GetProbMtx(), IsEdgePlace(), operator=(), SetRndMtx(), Swap(), and TKronMtx().
const double TKronMtx::NInf = -DBL_MAX [static] | 
        
Definition at line 13 of file kronecker.h.
Referenced by GetApxNoEdgeDLL(), GetEdgeLL(), GetLLMtx(), GetProbMtx(), TKroneckerLL::InitLL(), and KronSum().
TRnd TKronMtx::Rnd = TRnd(0) [static] | 
        
Definition at line 14 of file kronecker.h.
Referenced by AddRndNoise(), GenDetKronecker(), GenFastKronecker(), GenKronecker(), and PutRndSeed().
TFltV TKronMtx::SeedMtx [private] | 
        
Definition at line 17 of file kronecker.h.
Referenced by At(), Dump(), Empty(), GenDetKronecker(), GenFastKronecker(), GenKronecker(), GenMtx(), GetMtx(), GetPrimHashCd(), GetSecHashCd(), Len(), operator=(), operator==(), PutAllMtx(), SetMtx(), SetRndMtx(), Swap(), and TKronMtx().