SNAP Library 2.1, User Reference  2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
kronecker.h
Go to the documentation of this file.
00001 #ifndef snap_kronecker_h
00002 #define snap_kronecker_h
00003 
00004 #include "Snap.h"
00005 
00007 // Dense Kronecker Matrix
00008 class TKroneckerLL;
00009 typedef TPt<TKroneckerLL> PKroneckerLL;
00010 
00011 class TKronMtx {
00012 public:
00013   static const double NInf;
00014   static TRnd Rnd;
00015 private:
00016   TInt MtxDim;
00017   TFltV SeedMtx;
00018 public:
00019   TKronMtx() : MtxDim(-1), SeedMtx() { }
00020   TKronMtx(const int& Dim) : MtxDim(Dim), SeedMtx(Dim*Dim) { }
00021   TKronMtx(const TFltV& SeedMatrix);
00022   TKronMtx(const TKronMtx& Kronecker) : MtxDim(Kronecker.MtxDim), SeedMtx(Kronecker.SeedMtx) { }
00023   void SaveTxt(const TStr& OutFNm) const;
00024   TKronMtx& operator = (const TKronMtx& Kronecker);
00025   bool operator == (const TKronMtx& Kronecker) const { return SeedMtx==Kronecker.SeedMtx; }
00026   int GetPrimHashCd() const { return SeedMtx.GetPrimHashCd(); }
00027   int GetSecHashCd() const { return SeedMtx.GetSecHashCd(); }
00028 
00029   // seed matrix
00030   int GetDim() const { return MtxDim; }
00031   int Len() const { return SeedMtx.Len(); }
00032   bool Empty() const { return SeedMtx.Empty(); }
00033   bool IsProbMtx() const; // probability (not log-lihelihood) matrix
00034 
00035   TFltV& GetMtx() { return SeedMtx; }
00036   const TFltV& GetMtx() const { return SeedMtx; }
00037   void SetMtx(const TFltV& ParamV) { SeedMtx = ParamV; }
00038   void SetRndMtx(const int& MtxDim, const double& MinProb = 0.0);
00039   void PutAllMtx(const double& Val) { SeedMtx.PutAll(Val); }
00040   void GenMtx(const int& Dim) { MtxDim=Dim;  SeedMtx.Gen(Dim*Dim); }
00041   void SetEpsMtx(const double& Eps1, const double& Eps0, const int& Eps1Val=1, const int& Eps0Val=0);
00042   void SetForEdges(const int& Nodes, const int& Edges); // scales the values to allow E edges
00043   void AddRndNoise(const double& SDev);
00044   TStr GetMtxStr() const;
00045 
00046   const double& At(const int& Row, const int& Col) const { return SeedMtx[MtxDim*Row+Col].Val; }
00047   double& At(const int& Row, const int& Col) { return SeedMtx[MtxDim*Row+Col].Val; }
00048   const double& At(const int& ValN) const { return SeedMtx[ValN].Val; }
00049   double& At(const int& ValN) { return SeedMtx[ValN].Val; }
00050 
00051   int GetNodes(const int& NIter) const;
00052   int GetEdges(const int& NIter) const;
00053   int GetKronIter(const int& Nodes) const;
00054   int GetNZeroK(const PNGraph& Graph) const; // n0^k so that > Graph->GetNodes
00055   double GetEZero(const int& Edges, const int& KronIter) const;
00056   double GetMtxSum() const;
00057   double GetRowSum(const int& RowId) const;
00058   double GetColSum(const int& ColId) const;
00059 
00060   void ToOneMinusMtx();
00061   void GetLLMtx(TKronMtx& LLMtx);
00062   void GetProbMtx(TKronMtx& ProbMtx);
00063   void Swap(TKronMtx& KronMtx);
00064 
00065   // edge probability and log-likelihood
00066   double GetEdgeProb(int NId1, int NId2, const int& NKronIters) const; // given ProbMtx
00067   double GetNoEdgeProb(int NId1, int NId2, const int& NKronIters) const; // given ProbMtx
00068   double GetEdgeLL(int NId1, int NId2, const int& NKronIters) const; // given LLMtx
00069   double GetNoEdgeLL(int NId1, int NId2, const int& NKronIters) const; // given LLMtx
00070   double GetApxNoEdgeLL(int NId1, int NId2, const int& NKronIters) const; // given LLMtx
00071   bool IsEdgePlace(int NId1, int NId2, const int& NKronIters, const double& ProbTresh) const; // place an edge
00072   // derivative of edge log-likelihood
00073   double GetEdgeDLL(const int& ParamId, int NId1, int NId2, const int& NKronIters) const; // given LLMtx
00074   double GetNoEdgeDLL(const int& ParamId, int NId1, int NId2, const int& NKronIters) const; // given LLMtx
00075   double GetApxNoEdgeDLL(const int& ParamId, int NId1, int NId2, const int& NKronIters) const; // given LLMtx
00076 
00077   // edge prob from node signature
00078   static uint GetNodeSig(const double& OneProb = 0.5);
00079   double GetEdgeProb(const uint& NId1Sig, const uint& NId2Sig, const int& NIter) const;
00080 
00081   // from the current (probabilistic) adjacency matrix
00082   PNGraph GenThreshGraph(const double& Thresh) const;
00083   PNGraph GenRndGraph(const double& RndFact=1.0) const;
00084 
00085   static int GetKronIter(const int& GNodes, const int& SeedMtxSz);
00086   // from the seed matrix
00087   static PNGraph GenKronecker(const TKronMtx& SeedMtx, const int& NIter, const bool& IsDir, const int& Seed=0);
00088   static PNGraph GenFastKronecker(const TKronMtx& SeedMtx, const int& NIter, const bool& IsDir, const int& Seed=0);
00089   static PNGraph GenFastKronecker(const TKronMtx& SeedMtx, const int& NIter, const int& Edges, const bool& IsDir, const int& Seed=0);
00090   static PNGraph GenDetKronecker(const TKronMtx& SeedMtx, const int& NIter, const bool& IsDir);
00091   static void PlotCmpGraphs(const TKronMtx& SeedMtx, const PNGraph& Graph, const TStr& OutFNm, const TStr& Desc);
00092   static void PlotCmpGraphs(const TKronMtx& SeedMtx1, const TKronMtx& SeedMtx2, const PNGraph& Graph, const TStr& OutFNm, const TStr& Desc);
00093   static void PlotCmpGraphs(const TVec<TKronMtx>& SeedMtxV, const PNGraph& Graph, const TStr& FNmPref, const TStr& Desc);
00094 
00095   static void KronMul(const TKronMtx& LeftPt, const TKronMtx& RightPt, TKronMtx& OutMtx);
00096   static void KronSum(const TKronMtx& LeftPt, const TKronMtx& RightPt, TKronMtx& OutMtx); // log powering
00097   static void KronPwr(const TKronMtx& KronPt, const int& NIter, TKronMtx& OutMtx);
00098 
00099   void Dump(const TStr& MtxNm = TStr(), const bool& Sort = false) const;
00100   static double GetAvgAbsErr(const TKronMtx& Kron1, const TKronMtx& Kron2); // avg L1 on (sorted) parameters
00101   static double GetAvgFroErr(const TKronMtx& Kron1, const TKronMtx& Kron2); // avg L2 on (sorted) parameters
00102   static TKronMtx GetMtx(TStr MatlabMtxStr);
00103   static TKronMtx GetRndMtx(const int& Dim, const double& MinProb);
00104   static TKronMtx GetInitMtx(const int& Dim, const int& Nodes, const int& Edges);
00105   static TKronMtx GetInitMtx(const TStr& MtxStr, const int& Dim, const int& Nodes, const int& Edges);
00106   static TKronMtx GetMtxFromNm(const TStr& MtxNm);
00107   static TKronMtx LoadTxt(const TStr& MtxFNm);
00108   static void PutRndSeed(const int& Seed) { TKronMtx::Rnd.PutSeed(Seed); }
00109 };
00110 
00112 // Kronecker Log Likelihood
00113 
00114 enum TKronEMType {  kronNodeMiss = 0, kronFutureLink, kronEdgeMiss }; 
00115 
00116 class TKroneckerLL {
00117 public:
00118 private:
00119   TCRef CRef;
00120   PNGraph Graph;         // graph to fit
00121   TInt Nodes, KronIters;
00122 
00123   TFlt PermSwapNodeProb; // permutation proposal distribution (swap edge endpoins vs. swap random nodes)
00124 //  TIntPrV GEdgeV;        // edge vector (for swap edge permutation proposal)
00125   TIntTrV GEdgeV;        // edge vector (for swap edge permutation proposal) /// !!!!! MYUNGHWAN, CHECK!
00126   TIntTrV LEdgeV;        // latent edge vector
00127   TInt LSelfEdge;        // latent self edges
00128   TIntV NodePerm;        // current permutation
00129   TIntV InvertPerm;      // current invert permutation
00130 
00131   TInt RealNodes;       // # of observed nodes (for KronEM)
00132   TInt RealEdges;       // # of observed edges (for link prediction)
00133 
00134   TKronMtx ProbMtx, LLMtx; // Prob and LL matrices (parameters)
00135   TFlt LogLike; // LL at ProbMtx
00136   TFltV GradV;  // DLL at ProbMtx (gradient)
00137 
00138   TKronEMType EMType;   // Latent setting type for EM
00139   TInt MissEdges;               // # of missing edges (if unknown, -1)
00140 
00141   TBool DebugMode;              // Debug mode flag
00142   TFltV LLV;                    // Log-likelihood (per EM iteration)
00143   TVec<TKronMtx> MtxV;  // Kronecker initiator matrix (per EM iteration)
00144 
00145 public:
00146   // RS 07/03/12, changed the order in the constructor initializer list
00147   //    so that it matches the declaration order. This changes also
00148   //    got rid of the compilation warnings. This is the old order:
00149   // TKroneckerLL() : Nodes(-1), KronIters(-1), PermSwapNodeProb(0.2), LogLike(TKronMtx::NInf), EMType(kronNodeMiss), RealNodes(-1), RealEdges(-1), MissEdges(-1), DebugMode(false) { }
00150   TKroneckerLL() : Nodes(-1), KronIters(-1), PermSwapNodeProb(0.2), RealNodes(-1), RealEdges(-1), LogLike(TKronMtx::NInf), EMType(kronNodeMiss), MissEdges(-1), DebugMode(false) { }
00151   TKroneckerLL(const PNGraph& GraphPt, const TFltV& ParamV, const double& PermPSwapNd=0.2);
00152   TKroneckerLL(const PNGraph& GraphPt, const TKronMtx& ParamMtx, const double& PermPSwapNd=0.2);
00153   TKroneckerLL(const PNGraph& GraphPt, const TKronMtx& ParamMtx, const TIntV& NodeIdPermV, const double& PermPSwapNd=0.2);
00154   static PKroneckerLL New() { return new TKroneckerLL(); }
00155   static PKroneckerLL New(const PNGraph& GraphPt, const TKronMtx& ParamMtx, const double& PermPSwapNd=0.1);
00156   static PKroneckerLL New(const PNGraph& GraphPt, const TKronMtx& ParamMtx, const TIntV& NodeIdPermV, const double& PermPSwapNd=0.2);
00157 
00158   int GetNodes() const { return Nodes; }
00159   int GetKronIters() const { return KronIters; }
00160   PNGraph GetGraph() const { return Graph; }
00161   void SetGraph(const PNGraph& GraphPt);
00162   const TKronMtx& GetProbMtx() const { return ProbMtx; }
00163   const TKronMtx& GetLLMtx() const { return LLMtx; }
00164   int GetParams() const { return ProbMtx.Len(); }
00165   int GetDim() const { return ProbMtx.GetDim(); }
00166 
00167   void SetDebug(const bool Debug) { DebugMode = Debug; }
00168   const TFltV& GetLLHist() const { return LLV; }
00169   const TVec<TKronMtx>& GetParamHist() const { return MtxV; }
00170 
00171   // check actual nodes and edges (for KronEM)
00172   bool IsObsNode(const int& NId) const { IAssert(RealNodes > 0);        return (NId < RealNodes);       }
00173   bool IsObsEdge(const int& NId1, const int& NId2) const { IAssert(RealNodes > 0);      return ((NId1 < RealNodes) && (NId2 < RealNodes));      }
00174   bool IsLatentNode(const int& NId) const { return !IsObsNode(NId);     }
00175   bool IsLatentEdge(const int& NId1, const int& NId2) const { return !IsObsEdge(NId1, NId2);    }
00176 
00177   // node permutation
00178   void SetPerm(const char& PermId);
00179   void SetOrderPerm(); // identity
00180   void SetRndPerm();   // random
00181   void SetDegPerm();   // node degrees
00182   void SetBestDegPerm();        // best matched degrees
00183   void SetPerm(const TIntV& NodePermV) { NodePerm = NodePermV; SetIPerm(NodePerm); }
00184   void SetIPerm(const TIntV& Perm);     // construct invert permutation
00185   const TIntV& GetPermV() const { return NodePerm; }
00186 
00187   // handling isolated nodes to fit # of nodes to Kronecker graphs model
00188   void AppendIsoNodes();
00189   void RestoreGraph(const bool RestoreNodes = true);
00190 
00191   // full graph LL
00192   double GetFullGraphLL() const;
00193   double GetFullRowLL(int RowId) const;
00194   double GetFullColLL(int ColId) const;
00195   // empty graph LL
00196   double GetEmptyGraphLL() const;
00197   double GetApxEmptyGraphLL() const;
00198   // graph LL
00199   void InitLL(const TFltV& ParamV);
00200   void InitLL(const TKronMtx& ParamMtx);
00201   void InitLL(const PNGraph& GraphPt, const TKronMtx& ParamMtx);
00202   double CalcGraphLL();
00203   double CalcApxGraphLL();
00204   double GetLL() const { return LogLike; }
00205   double GetAbsErr() const { return fabs(pow((double)Graph->GetEdges(), 1.0/double(KronIters)) - ProbMtx.GetMtxSum()); }
00206   double NodeLLDelta(const int& NId) const;
00207   double SwapNodesLL(const int& NId1, const int& NId2);
00208   bool SampleNextPerm(int& NId1, int& NId2); // sampling from P(perm|graph)
00209 
00210   // derivative of the log-likelihood
00211   double GetEmptyGraphDLL(const int& ParamId) const;
00212   double GetApxEmptyGraphDLL(const int& ParamId) const;
00213   const TFltV& CalcGraphDLL();
00214   const TFltV& CalcFullApxGraphDLL();
00215   const TFltV& CalcApxGraphDLL();
00216   double NodeDLLDelta(const int ParamId, const int& NId) const;
00217   void UpdateGraphDLL(const int& SwapNId1, const int& SwapNId2);
00218   const TFltV& GetDLL() const { return GradV; }
00219   double GetDLL(const int& ParamId) const { return GradV[ParamId]; }
00220 
00221   // gradient
00222   void SampleGradient(const int& WarmUp, const int& NSamples, double& AvgLL, TFltV& GradV);
00223   double GradDescent(const int& NIter, const double& LrnRate, double MnStep, double MxStep, const int& WarmUp, const int& NSamples);
00224   double GradDescent2(const int& NIter, const double& LrnRate, double MnStep, double MxStep, const int& WarmUp, const int& NSamples);
00225 
00226   // KronEM
00227   void SetRandomEdges(const int& NEdges, const bool isDir = true);
00228   void MetroGibbsSampleSetup(const int& WarmUp);
00229   void MetroGibbsSampleNext(const int& WarmUp, const bool DLLUpdate = false);
00230   void RunEStep(const int& GibbsWarmUp, const int& WarmUp, const int& NSamples, TFltV& LLV, TVec<TFltV>& DLLV);
00231   double RunMStep(const TFltV& LLV, const TVec<TFltV>& DLLV, const int& GradIter, const double& LrnRate, double MnStep, double MxStep);
00232   void RunKronEM(const int& EMIter, const int& GradIter, double LrnRate, double MnStep, double MxStep, const int& GibbsWarmUp, const int& WarmUp, const int& NSamples, const TKronEMType& Type = kronNodeMiss, const int& NMissing = -1);
00233 
00234 
00235 
00236   TFltV TestSamplePerm(const TStr& OutFNm, const int& WarmUp, const int& NSamples, const TKronMtx& TrueMtx, const bool& DoPlot=true);
00237   static double CalcChainR2(const TVec<TFltV>& ChainLLV);
00238   static void ChainGelmapRubinPlot(const TVec<TFltV>& ChainLLV, const TStr& OutFNm, const TStr& Desc);
00239   TFltQu TestKronDescent(const bool& DoExact, const bool& TruePerm, double LearnRate, const int& WarmUp, const int& NSamples, const TKronMtx& TrueParam);
00240   void GradDescentConvergence(const TStr& OutFNm, const TStr& Desc1, const bool& SamplePerm, const int& NIters,
00241     double LearnRate, const int& WarmUp, const int& NSamples, const int& AvgKGraphs, const TKronMtx& TrueParam);
00242   static void TestBicCriterion(const TStr& OutFNm, const TStr& Desc1, const PNGraph& G, const int& GradIters,
00243     double LearnRate, const int& WarmUp, const int& NSamples, const int& TrueN0);
00244   static void TestGradDescent(const int& KronIters, const int& KiloSamples, const TStr& Permutation);
00245   friend class TPt<TKroneckerLL>;
00246 };
00247 
00248 
00250 // Add Noise to Graph
00251 class TKronNoise {
00252 public:
00253         TKronNoise() {};
00254         static int RemoveNodeNoise(PNGraph& Graph, const int& NNodes, const bool Random = true);
00255         static int RemoveNodeNoise(PNGraph& Graph, const double& Rate, const bool Random = true);
00256         static int FlipEdgeNoise(PNGraph& Graph, const int& NEdges, const bool Random = true);
00257         static int FlipEdgeNoise(PNGraph& Graph, const double& Rate, const bool Random = true);
00258         static int RemoveEdgeNoise(PNGraph& Graph, const int& NEdges);
00259         static int RemoveEdgeNoise(PNGraph& Graph, const double& Rate);
00260 };
00261 
00262 
00264 // Kronecker Log Likelihood Maximization
00265 class TKronMaxLL {
00266 public:
00267   class TFEval {
00268   public:
00269     TFlt LogLike;
00270     TFltV GradV;
00271   public:
00272     TFEval() : LogLike(0), GradV() { }
00273     TFEval(const TFlt& LL, const TFltV& DLL) : LogLike(LL), GradV(DLL) { }
00274     TFEval(const TFEval& FEval) : LogLike(FEval.LogLike), GradV(FEval.GradV) { }
00275     TFEval& operator = (const TFEval& FEval) { if (this!=&FEval) {
00276       LogLike=FEval.LogLike; GradV=FEval.GradV; } return *this; }
00277   };
00278 private:
00279   //TInt WarmUp, NSamples;
00280   THash<TKronMtx, TFEval> FEvalH; // cached gradients
00281   TKroneckerLL KronLL;
00282 public:
00283   TKronMaxLL(const PNGraph& GraphPt, const TKronMtx& StartParam) : KronLL(GraphPt, StartParam) { }
00284   void SetPerm(const char& PermId);
00285 
00286   void GradDescent(const int& NIter, const double& LrnRate, const double& MnStep, const double& MxStep,
00287     const double& WarmUp, const double& NSamples);
00288 
00289   /*void EvalNewEdgeP(const TKronMtx& ProbMtx);
00290   double GetLL(const TFltV& ThetaV);
00291   void GetDLL(const TFltV& ThetaV, TFltV& DerivV);
00292   double GetDLL(const TFltV& ThetaV, const int& ParamId);
00293   //void MaximizeLL(const int& NWarmUp, const int& Samples);//*/
00294 
00295   static void RoundTheta(const TFltV& ThetaV, TFltV& NewThetaV);
00296   static void RoundTheta(const TFltV& ThetaV, TKronMtx& Kronecker);
00297 
00298   static void Test();
00299 };
00300 
00302 // Kronecker Fitting using Metrod of Moments (by Art Owen)
00303 class TKronMomentsFit {
00304 public:
00305   double Edges, Hairpins, Tripins, Triads;
00306 public:
00307   TKronMomentsFit(const PUNGraph& G) {
00308     Edges=0; Hairpins=0; Tripins=0; Triads=0;
00309     for (TUNGraph::TNodeI NI = G->BegNI(); NI < G->EndNI(); NI++) {
00310       const int d = NI.GetOutDeg();
00311       Edges += d;
00312       Hairpins += d*(d-1.0);
00313       Tripins += d*(d-1.0)*(d-2.0);
00314     }
00315     Edges /= 2.0;
00316     Hairpins /= 2.0;
00317     Tripins /= 6.0;
00318     int64 ot,ct;
00319     Triads = (int) TSnap::GetTriads(G, ot, ct)/3.0;
00320     printf("E:%g\tH:%g\tT:%g\tD:%g\n", Edges, Hairpins, Tripins, Triads);
00321   }
00322 
00323   TFltQu EstABC(const int& R) {
00324     const double Step = 0.01;
00325     double MinScore=TFlt::Mx;
00326     double A=0, B=0, C=0;
00327     //Edges=log(Edges);  Hairpins=log(Hairpins);  Tripins=log(Tripins);  Triads=log(Triads);
00328     for (double a = 1.0; a > Step; a-=Step) {
00329       for (double b = Step; b <= 1.0; b+=Step) {
00330         for (double c = Step; c <= a; c+=Step) {
00331           double EE = ( pow(a+2*b+c, R) - pow(a+c, R) ) / 2.0;
00332           double EH = ( pow(pow(a+b,2) + pow(b+c,2), R)
00333                              -2*pow(a*(a+b)+c*(c+b), R)
00334                              -pow(a*a + 2*b*b + c*c, R)
00335                              +2*pow(a*a + c*c, R) ) / 2.0;
00336           double ET = ( pow(pow(a+b,3)+pow(b+c,3), R)
00337                              -3*pow(a*pow(a+b,2)+c*pow(b+c,2), R)
00338                              -3*pow(a*a*a + c*c*c + b*(a*a+c*c) + b*b*(a+c) + 2*b*b*b ,R)
00339                              +2*pow(a*a*a + 2*b*b*b + c*c*c, R)
00340                              +5*pow(a*a*a + c*c*c + b*b*(a+c), R)
00341                              +4*pow(a*a*a + c*c*c + b*(a*a+c*c), R)
00342                              -6*pow(a*a*a + c*c*c, R) ) / 6.0;
00343           double ED = ( pow(a*a*a + 3*b*b*(a+c) + c*c*c, R)
00344                              -3*pow(a*(a*a+b*b) + c*(b*b+c*c), R)
00345                              +2*pow(a*a*a+c*c*c, R) ) / 6.0;
00346           if (EE < 0) { EE = 1; }
00347           if (EH < 0) { EH = 1; }
00348           if (ET < 0) { ET = 1; }
00349           if (ED < 0) { ED = 1; }
00350           //EE=log(EE); EH=log(EH); ET=log(ET); ED=log(ED);
00351           double Score = pow(Edges-EE,2)/EE + pow(Hairpins-EH ,2)/EH + pow(Tripins-ET, 2)/ET + pow(Triads-ED, 2)/ED;
00352           //double Score = fabs(Edges-EE)/EE + fabs(Hairpins-EH)/EH + fabs(Tripins-ET)/ET + fabs(Triads-ED)/ED;
00353           //double Score = log(pow(Edges-EE,2)/EE) + log(pow(Hairpins-EH,2)/EH) + log(pow(Tripins-ET, 2)/ET) + log(pow(Triads-ED, 2)/ED);
00354           if (MinScore > Score || (a==0.9 && b==0.6 && c==0.2) || (TMath::IsInEps(a-0.99,1e-6) && TMath::IsInEps(b-0.57,1e-6) && TMath::IsInEps(c-0.05,1e-6)))
00355           {
00356             printf("%.03f %.03f %0.03f %10.4f  %10.10g\t%10.10g\t%10.10g\t%10.10g\n", a,b,c, log10(Score), EE, EH, ET, ED);
00357             //printf("%.03f %.03f %0.03f %g\n", a,b,c, log(Score));
00358             A=a; B=b; C=c; MinScore=Score;
00359           }
00360         }
00361       }
00362     }
00363     printf("\t\t\t      %10.10g\t%10.10g\t%10.10g\t%10.10g\n", Edges, Hairpins, Tripins, Triads);
00364     return TFltQu(A,B,C,MinScore);
00365   }
00366 
00367   static void Test() {
00368     TFIn FIn("as20.ngraph");
00369     PUNGraph G = TSnap::ConvertGraph<PUNGraph>(TNGraph::Load(FIn));
00370     //PUNGraph G = TKronMtx::GenFastKronecker(TKronMtx::GetMtx("0.9, 0.6; 0.6, 0.2"), 14, false, 0)->GetUNGraph();
00371     //PUNGraph G = TUNGraph::GetSmallGraph();
00372     TSnap::PrintInfo(G);
00373     TSnap::DelSelfEdges(G);
00374     TSnap::PrintInfo(G);
00375     TKronMomentsFit Fit(G);
00376     printf("iter %d\n", TKronMtx::GetKronIter(G->GetNodes(), 2));
00377     Fit.EstABC(TKronMtx::GetKronIter(G->GetNodes(), 2)); //*/
00378   }
00379 };
00380 
00381 
00383 // Kronecker Phase Plot
00384 /*class TKronPhasePlot {
00385 public:
00386   class TPhasePoint {
00387   public:
00388     TFlt Alpha, Beta;
00389     TGrowthStat GrowthStat;
00390   public:
00391     TPhasePoint() { }
00392     TPhasePoint(const double& A, const double& B, const TGrowthStat& GS) : Alpha(A), Beta(B), GrowthStat(GS) { }
00393     TPhasePoint(TSIn& SIn) : Alpha(SIn), Beta(SIn), GrowthStat(SIn) { }
00394     void Save(TSOut& SOut) const { Alpha.Save(SOut);  Beta.Save(SOut);  GrowthStat.Save(SOut); }
00395   };
00396   typedef TVec<TPhasePoint> TPhasePointV;
00397 public:
00398   TPhasePointV PhaseV;
00399 public:
00400   TKronPhasePlot() { }
00401   TKronPhasePlot(const TKronPhasePlot& Phase) : PhaseV(Phase.PhaseV) { }
00402   TKronPhasePlot(TSIn& SIn) : PhaseV(SIn) { }
00403   void Save(TSOut& SOut) const { PhaseV.Save(SOut);  }
00404   void SaveMatlab(const TStr& OutFNm) const;
00405 
00406   static void KroneckerPhase(const TStr& MtxId, const int& MxIter,
00407     const double& MnAlpha, const double& MxAlpha, const double& AlphaStep,
00408     const double& MnBeta, const double& MxBeta, const double& BetaStep,
00409     const TStr& FNmPref);
00410 };*/
00411 
00412 /*// for conjugate gradient
00413   class TFunc {
00414   private:
00415     TKronMaxLL* CallBack;
00416   public:
00417     TFunc(TKronMaxLL* CallBackPt) : CallBack(CallBackPt) { }
00418     TFunc(const TFunc& Func) : CallBack(Func.CallBack) { }
00419     TFunc& operator = (const TFunc& Func) { CallBack=Func.CallBack; return *this; }
00420     double FVal(const TFltV& Point) { return -CallBack->GetLL(Point); }
00421     void FDeriv(const TFltV& Point, TFltV& DerivV);
00422   };
00423 public:
00424   // log barier
00425   class TLogBarFunc {
00426   private:
00427     TKronMaxLL* CallBack;
00428     double T;
00429   public:
00430     TLogBarFunc(TKronMaxLL* CallBackPt, const double& t=0.5) : CallBack(CallBackPt), T(t) { }
00431     TLogBarFunc(const TLogBarFunc& Func) : CallBack(Func.CallBack), T(Func.T) { }
00432     TLogBarFunc& operator = (const TLogBarFunc& Func) { CallBack=Func.CallBack; T=Func.T; return *this; }
00433     double FVal(const TFltV& Point);
00434     void FDeriv(const TFltV& Point, TFltV& DerivV);
00435   };*/
00436 
00437 #endif