| 
    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 <mag.h>

Public Member Functions | |
| TMAGParam () | |
| TMAGParam (const int &NumNodes, const int &NumAttrs) | |
| TMAGParam (const int &NumNodes, const TMAGAffMtxV &MtxV) | |
| TMAGParam (const int &NumNodes, const TStr &ConfFNm) | |
| TMAGParam (const TMAGParam< TNodeAttr > &MAGParam) | |
| TMAGParam (const int &NumNodes, const int &NumAttrs, const TNodeAttr &Dist) | |
| TMAGParam< TNodeAttr > & | operator= (const TMAGParam< TNodeAttr > &MAGParam) | 
| void | Clr () | 
| void | LoadTxt (const TStr &InFNm) | 
| void | SaveTxt (const TStr &OutFNm) const | 
| void | SetNodes (const int &Nodes) | 
| const int | GetNodes () const | 
| void | SetAttrs (const int &Attrs) | 
| const int | GetAttrs () const | 
| void | SetNodeAttr (const TNodeAttr &Dist) | 
| const TNodeAttr & | GetNodeAttr () const | 
| const int | GetDim (const int &Attr) const | 
| void | GetDimV (TIntV &DimV) const | 
| void | SetMtxVal (const int &Attr, const int &Row, const int &Col, const double &Val) | 
| void | SetMtx (const int &Attr, const TMAGAffMtx &Mtx) | 
| void | SetMtxV (const TMAGAffMtxV &MtxV) | 
| void | SetMtxAll (const TMAGAffMtx &Mtx) | 
| const double | GetMtxVal (const int &Attr, const int &Row, const int &Col) const | 
| const TMAGAffMtx & | GetMtx (const int &Attr) const | 
| void | GetMtxV (TMAGAffMtxV &MtxV) const | 
| PNGraph | GenMAG (TIntVV &AttrVV, const bool &IsDir=false, const int &Seed=1) | 
| PNGraph | GenAttrMAG (const TIntVV &AttrVV, const bool &IsDir=false, const int &Seed=1) | 
Static Public Attributes | |
| static TRnd | Rnd | 
Private Attributes | |
| TInt | NNodes | 
| TInt | NAttrs | 
| TNodeAttr | NodeAttr | 
| TMAGAffMtxV | AffMtxV | 
| TMAGParam< TNodeAttr >::TMAGParam | ( | const int & | NumNodes, | 
| const TMAGAffMtxV & | MtxV | ||
| ) |  [inline] | 
        
| PNGraph TMAGParam< TNodeAttr >::GenAttrMAG | ( | const TIntVV & | AttrVV, | 
| const bool & | IsDir = false,  | 
        ||
| const int & | Seed = 1  | 
        ||
| ) | 
Definition at line 250 of file mag.h.
References TNGraph::AddEdge(), TNGraph::AddNode(), TVVec< TVal >::At(), TVVec< TVal >::GetYDim(), IAssert, and TNGraph::New().
                                                                                                 {
        PNGraph Graph = TNGraph::New(NNodes, -1);
        for(int i = 0; i < NNodes; i++) {
                Graph->AddNode(i);
        }
        if(Seed > 0) {
                TNodeAttr::Rnd.PutSeed(Seed);
        }
        IAssert(AttrVV.GetYDim() == NAttrs);
        for(int i = 0; i < NNodes; i++) {
                for(int l = 0; l < NAttrs; l++) {
                        IAssert(AttrVV.At(i, l) < AffMtxV[l].GetDim());
                }
        }
        for(int i = 0; i < NNodes; i++) {
                for(int j = i; j < NNodes; j++) {
                        double Prob = 1.0;
                        for(int l = 0; l < NAttrs; l++) {
                                Prob *= AffMtxV[l].At(AttrVV.At(i, l), AttrVV.At(j, l));
                        }
                        
                        if(TNodeAttr::Rnd.GetUniDev() < Prob) {
                                Graph->AddEdge(i, j);
                                if(! IsDir && i != j) {  Graph->AddEdge(j, i);  }
                        }
                        if(IsDir && i != j) {
                                Prob = 1.0;
                                for(int l = 0; l < NAttrs; l++) {
                                        Prob *= AffMtxV[l].At(AttrVV.At(j, l), AttrVV.At(i, l));
                                }
                                if(TNodeAttr::Rnd.GetUniDev() < Prob) {
                                        Graph->AddEdge(j, i);
                                }
                        }
                }
        }
        return Graph;
};

| PNGraph TMAGParam< TNodeAttr >::GenMAG | ( | TIntVV & | AttrVV, | 
| const bool & | IsDir = false,  | 
        ||
| const int & | Seed = 1  | 
        ||
| ) | 
Definition at line 295 of file mag.h.
References TVVec< TVal >::At(), TVVec< TVal >::GetYDim(), and IAssert.
Referenced by TMAGFitBern::PlotProperties().
                                                                                       {
        TNodeAttr::Rnd.PutSeed(Seed);
        NodeAttr.AttrGen(AttrVV, NNodes);
        IAssert(AttrVV.GetYDim() == NAttrs);
        for(int i = 0; i < NNodes; i++) {
                for(int l = 0; l < NAttrs; l++) {
                        IAssert(AttrVV.At(i, l) < AffMtxV[l].GetDim());
                }
        }
        PNGraph Graph = GenAttrMAG(AttrVV, IsDir, 0);
        return Graph;
/*
        for(int i = 0; i < NNodes; i++) {
                for(int j = i; j < NNodes; j++) {
                        double Prob = 1.0;
                        for(int l = 0; l < NAttrs; l++) {
                                Prob *= AffMtxV[l].At(AttrVV.At(i, l), AttrVV.At(j, l));
                        }
                        if(TNodeAttr::Rnd.GetUniDev() < Prob) {
                                Graph->AddEdge(i, j);
                                if(! IsDir && i != j) {  Graph->AddEdge(j, i);  }
                        }
                        if(IsDir && i != j) {
                                Prob = 1.0;
                                for(int l = 0; l < NAttrs; l++) {
                                        Prob *= AffMtxV[l].At(AttrVV.At(j, l), AttrVV.At(i, l));
                                }
                                if(TNodeAttr::Rnd.GetUniDev() < Prob) {
                                        Graph->AddEdge(j, i);
                                }
                        }
                }
        }
        return Graph;
*/
};


Definition at line 174 of file mag.h.
Referenced by TMAGFitBern::ComputeApxAdjLL(), TMAGFitBern::ComputeApxLL(), TMAGFitBern::ComputeJointAdjLL(), TMAGFitBern::ComputeJointLL(), TMAGFitBern::ComputeJointOneLL(), TMAGFitBern::DoEMAlg(), TMAGFitBern::DoEStep(), TMAGFitBern::DoEStepApxOneIter(), TMAGFitBern::DoEStepOneIter(), TMAGFitBern::DoMStep(), TMAGFitBern::GetAttrs(), TMAGFitBern::GetAvgProdLinWeight(), TMAGFitBern::GetAvgProdSqWeight(), TMAGFitBern::GetProdLinWeight(), TMAGFitBern::GetProdSqWeight(), TMAGFitBern::Init(), TMAGFitBern::PlotProperties(), TMAGFitBern::RandomInit(), TMAGFitBern::SaveTxt(), TMAGFitBern::SetPhiVV(), TMAGFitBern::TMAGFitBern(), TMAGFitBern::UpdateAffMtxV(), TMAGFitBern::UpdateApxPhiMI(), and TMAGFitBern::UpdatePhiMI().
{  return NAttrs;  }

| const TMAGAffMtx& TMAGParam< TNodeAttr >::GetMtx | ( | const int & | Attr | ) |  const [inline] | 
        
Definition at line 187 of file mag.h.
Referenced by TMAGFitBern::ComputeApxAdjLL(), TMAGFitBern::ComputeApxLL(), TMAGFitBern::GetAvgSqThetaLL(), TMAGFitBern::GetAvgThetaLL(), TMAGFitBern::GetSqThetaLL(), TMAGFitBern::GetThetaLL(), TMAGFitBern::UpdateAffMtx(), TMAGFitBern::UpdateApxPhiMI(), TMAGFitBern::UpdatePhi(), and TMAGFitBern::UpdatePhiMI().
{  return AffMtxV[Attr];  }

| void TMAGParam< TNodeAttr >::GetMtxV | ( | TMAGAffMtxV & | MtxV | ) |  const [inline] | 
        
Definition at line 188 of file mag.h.
Referenced by TMAGFitBern::ComputeJointAdjLL(), TMAGFitBern::ComputeJointOneLL(), TMAGFitBern::DoEMAlg(), TMAGFitBern::GetMtxV(), TMAGFitBern::PlotProperties(), TMAGFitBern::SaveTxt(), and TMAGFitBern::UpdateAffMtxV().
{  MtxV = AffMtxV;  }

| const TNodeAttr& TMAGParam< TNodeAttr >::GetNodeAttr | ( | ) |  const [inline] | 
        
Definition at line 177 of file mag.h.
Referenced by TMAGFitBern::ComputeApxAdjLL(), TMAGFitBern::ComputeApxLL(), TMAGFitBern::ComputeJointAdjLL(), TMAGFitBern::ComputeJointOneLL(), TMAGFitBern::DoEMAlg(), TMAGFitBern::GetEstNoEdgeLL(), TMAGFitBern::GetMuV(), TMAGFitBern::GetNodeAttr(), TMAGFitBern::GetProbMu(), TMAGFitBern::PlotProperties(), TMAGFitBern::SetMuV(), TMAGFitBern::UpdateAffMtxV(), TMAGFitBern::UpdateApxPhiMI(), TMAGFitBern::UpdateMu(), TMAGFitBern::UpdatePhi(), and TMAGFitBern::UpdatePhiMI().
{  return NodeAttr;  }

Definition at line 171 of file mag.h.
Referenced by TMAGFitBern::ComputeApxAdjLL(), TMAGFitBern::ComputeApxLL(), TMAGFitBern::ComputeJointAdjLL(), TMAGFitBern::ComputeJointLL(), TMAGFitBern::ComputeJointOneLL(), TMAGFitBern::DoEMAlg(), TMAGFitBern::DoEStep(), TMAGFitBern::DoEStepApxOneIter(), TMAGFitBern::DoEStepOneIter(), TMAGFitBern::GetAvgInCoeff(), TMAGFitBern::GetAvgOutCoeff(), TMAGFitBern::GetNodes(), TMAGFitBern::GetProbMu(), TMAGFitBern::GradAffMtx(), TMAGFitBern::GradApxAffMtx(), TMAGFitBern::Init(), TMAGFitBern::NormalizeAffMtxV(), TMAGFitBern::PlotProperties(), TMAGFitBern::PrepareUpdateAffMtx(), TMAGFitBern::PrepareUpdateApxAffMtx(), TMAGFitBern::RandomInit(), TMAGFitBern::SaveTxt(), TMAGFitBern::SetPhiVV(), TMAGFitBern::UnNormalizeAffMtxV(), TMAGFitBern::UpdateAffMtxV(), TMAGFitBern::UpdateApxPhiMI(), TMAGFitBern::UpdateMu(), TMAGFitBern::UpdatePhi(), and TMAGFitBern::UpdatePhiMI().
{  return NNodes;  }

Definition at line 205 of file mag.h.
References TStr::CStr(), and TMAGAffMtx::GetMtx().
Referenced by TMAGParam< TMAGNodeBern >::TMAGParam().
                                                    {
        NodeAttr.LoadTxt(InFNm);
        char buf[1024];
        FILE *fp = fopen(InFNm.CStr(), "r");
        NAttrs = 0;
        AffMtxV.Gen(10, 0);
        while(fgets(buf, sizeof(buf), fp) != NULL) {
                strtok(buf, "&");
                char *token = strtok(NULL, "\r\n");
                NAttrs++;
                AffMtxV.Add(TMAGAffMtx::GetMtx(TStr(token)));
        }
        fclose(fp);
};


| TMAGParam< TNodeAttr > & TMAGParam< TNodeAttr >::operator= | ( | const TMAGParam< TNodeAttr > & | MAGParam | ) | 
Definition at line 195 of file mag.h.
References TMAGParam< TNodeAttr >::AffMtxV, TMAGParam< TNodeAttr >::NAttrs, TMAGParam< TNodeAttr >::NNodes, and TMAGParam< TNodeAttr >::NodeAttr.
Definition at line 222 of file mag.h.
References TStr::CStr(), TStr::GetSubStr(), and TStr::Len().
                                                           {
        TStrV OutStrV;
        NodeAttr.SaveTxt(OutStrV);
        FILE *fp = fopen(OutFNm.CStr(), "w");
        fprintf(fp, "# %d nodes with %d attributes\n", NNodes(), NAttrs());
        for(int i = 0; i < NAttrs; i++) {
                TStr MtxStr = AffMtxV[i].GetMtxStr();
                fprintf(fp, "%s & %s\n", OutStrV[i].CStr(), MtxStr.GetSubStr(1, MtxStr.Len()-2).CStr());
        }
        fclose(fp);
};

| void TMAGParam< TNodeAttr >::SetMtx | ( | const int & | Attr, | 
| const TMAGAffMtx & | Mtx | ||
| ) |  [inline] | 
        
| void TMAGParam< TNodeAttr >::SetMtxAll | ( | const TMAGAffMtx & | Mtx | ) |  [inline] | 
        
| void TMAGParam< TNodeAttr >::SetMtxV | ( | const TMAGAffMtxV & | MtxV | ) |  [inline] | 
        
Definition at line 184 of file mag.h.
Referenced by TMAGFitBern::DoEMAlg(), TMAGFitBern::Init(), TMAGFitBern::PlotProperties(), TMAGFitBern::RandomInit(), TMAGFitBern::SetMtxV(), and TMAGFitBern::UpdateAffMtxV().

| void TMAGParam< TNodeAttr >::SetNodeAttr | ( | const TNodeAttr & | Dist | ) |  [inline] | 
        
Definition at line 176 of file mag.h.
Referenced by TMAGFitBern::Init(), TMAGFitBern::PlotProperties(), TMAGFitBern::RandomInit(), TMAGFitBern::SetMuV(), and TMAGFitBern::UpdateMu().
{  NodeAttr = Dist;  }

TMAGAffMtxV TMAGParam< TNodeAttr >::AffMtxV [private] | 
        
Definition at line 153 of file mag.h.
Referenced by TMAGParam< TMAGNodeBern >::Clr(), TMAGParam< TMAGNodeBern >::GetDim(), TMAGParam< TMAGNodeBern >::GetMtx(), TMAGParam< TMAGNodeBern >::GetMtxV(), TMAGParam< TMAGNodeBern >::GetMtxVal(), TMAGParam< TNodeAttr >::operator=(), TMAGParam< TMAGNodeBern >::SetMtx(), TMAGParam< TMAGNodeBern >::SetMtxAll(), TMAGParam< TMAGNodeBern >::SetMtxV(), and TMAGParam< TMAGNodeBern >::SetMtxVal().
Definition at line 151 of file mag.h.
Referenced by TMAGParam< TMAGNodeBern >::GetAttrs(), TMAGParam< TNodeAttr >::operator=(), and TMAGParam< TMAGNodeBern >::SetMtxV().
Definition at line 150 of file mag.h.
Referenced by TMAGParam< TMAGNodeBern >::GetNodes(), TMAGParam< TNodeAttr >::operator=(), and TMAGParam< TMAGNodeBern >::SetNodes().
Definition at line 152 of file mag.h.
Referenced by TMAGParam< TMAGNodeBern >::GetNodeAttr(), TMAGParam< TNodeAttr >::operator=(), and TMAGParam< TMAGNodeBern >::SetNodeAttr().