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
TMAGParam< TNodeAttr > Class Template Reference

#include <mag.h>

List of all members.

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 TMAGAffMtxGetMtx (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

Detailed Description

template<class TNodeAttr>
class TMAGParam< TNodeAttr >

Definition at line 146 of file mag.h.


Constructor & Destructor Documentation

template<class TNodeAttr>
TMAGParam< TNodeAttr >::TMAGParam ( ) [inline]

Definition at line 156 of file mag.h.

: NNodes(-1), NAttrs(-1), NodeAttr(), AffMtxV() {}
template<class TNodeAttr>
TMAGParam< TNodeAttr >::TMAGParam ( const int &  NumNodes,
const int &  NumAttrs 
) [inline]

Definition at line 157 of file mag.h.

: NNodes(NumNodes), NAttrs(NumAttrs), NodeAttr(), AffMtxV(NumAttrs) {}
template<class TNodeAttr>
TMAGParam< TNodeAttr >::TMAGParam ( const int &  NumNodes,
const TMAGAffMtxV MtxV 
) [inline]

Definition at line 158 of file mag.h.

: NNodes(NumNodes), NAttrs(MtxV.Len()), NodeAttr(), AffMtxV(MtxV) {}
template<class TNodeAttr>
TMAGParam< TNodeAttr >::TMAGParam ( const int &  NumNodes,
const TStr ConfFNm 
) [inline]

Definition at line 159 of file mag.h.

: NNodes(NumNodes) { LoadTxt(ConfFNm); }
template<class TNodeAttr>
TMAGParam< TNodeAttr >::TMAGParam ( const TMAGParam< TNodeAttr > &  MAGParam) [inline]

Definition at line 160 of file mag.h.

: NNodes(MAGParam.NNodes), NAttrs(MAGParam.NAttrs), NodeAttr(MAGParam.NodeAttr), AffMtxV(MAGParam.AffMtxV) {}
template<class TNodeAttr>
TMAGParam< TNodeAttr >::TMAGParam ( const int &  NumNodes,
const int &  NumAttrs,
const TNodeAttr &  Dist 
) [inline]

Definition at line 161 of file mag.h.

: NNodes(NumNodes), NAttrs(NumAttrs), NodeAttr(Dist), AffMtxV(NumAttrs) {}

Member Function Documentation

template<class TNodeAttr>
void TMAGParam< TNodeAttr >::Clr ( ) [inline]

Definition at line 165 of file mag.h.

{  AffMtxV.Clr();  }
template<class TNodeAttr >
PNGraph TMAGParam< TNodeAttr >::GenAttrMAG ( const TIntVV AttrVV,
const bool &  IsDir = false,
const int &  Seed = 1 
)

Definition at line 250 of file mag.h.

                                                                                                 {
        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;
};
template<class TNodeAttr >
PNGraph TMAGParam< TNodeAttr >::GenMAG ( TIntVV AttrVV,
const bool &  IsDir = false,
const int &  Seed = 1 
)

Definition at line 295 of file mag.h.

                                                                                       {
        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;
*/
};
template<class TNodeAttr>
const int TMAGParam< TNodeAttr >::GetAttrs ( ) const [inline]

Definition at line 174 of file mag.h.

{  return NAttrs;  }
template<class TNodeAttr>
const int TMAGParam< TNodeAttr >::GetDim ( const int &  Attr) const [inline]

Definition at line 179 of file mag.h.

{  return AffMtxV[Attr].GetDim();  }
template<class TNodeAttr >
void TMAGParam< TNodeAttr >::GetDimV ( TIntV DimV) const

Definition at line 242 of file mag.h.

                                                    {
        DimV.Gen(NAttrs);
        for(int i = 0; i < NAttrs; i++) {
                DimV[i] = AffMtxV[i].GetDim();
        }
};
template<class TNodeAttr>
const TMAGAffMtx& TMAGParam< TNodeAttr >::GetMtx ( const int &  Attr) const [inline]

Definition at line 187 of file mag.h.

{  return AffMtxV[Attr];  }
template<class TNodeAttr>
void TMAGParam< TNodeAttr >::GetMtxV ( TMAGAffMtxV MtxV) const [inline]

Definition at line 188 of file mag.h.

{  MtxV = AffMtxV;  }
template<class TNodeAttr>
const double TMAGParam< TNodeAttr >::GetMtxVal ( const int &  Attr,
const int &  Row,
const int &  Col 
) const [inline]

Definition at line 186 of file mag.h.

{  return AffMtxV[Attr].At(Row, Col);  }
template<class TNodeAttr>
const TNodeAttr& TMAGParam< TNodeAttr >::GetNodeAttr ( ) const [inline]

Definition at line 177 of file mag.h.

{  return NodeAttr;  }
template<class TNodeAttr>
const int TMAGParam< TNodeAttr >::GetNodes ( ) const [inline]

Definition at line 171 of file mag.h.

{  return NNodes;  }
template<class TNodeAttr >
void TMAGParam< TNodeAttr >::LoadTxt ( const TStr InFNm)

Definition at line 205 of file mag.h.

                                                    {
        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);
};
template<class TNodeAttr>
TMAGParam< TNodeAttr > & TMAGParam< TNodeAttr >::operator= ( const TMAGParam< TNodeAttr > &  MAGParam)

Definition at line 195 of file mag.h.

                                                                                          {
        NNodes = MAGParam.NNodes;
        NAttrs = MAGParam.NAttrs;
        AffMtxV = MAGParam.AffMtxV;
        NodeAttr = MAGParam.NodeAttr;

        return (*this);
};
template<class TNodeAttr >
void TMAGParam< TNodeAttr >::SaveTxt ( const TStr OutFNm) const

Definition at line 222 of file mag.h.

                                                           {
        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);
};
template<class TNodeAttr >
void TMAGParam< TNodeAttr >::SetAttrs ( const int &  Attrs)

Definition at line 236 of file mag.h.

                                                    {
        NAttrs = Attrs;
        AffMtxV.Gen(Attrs);
};
template<class TNodeAttr>
void TMAGParam< TNodeAttr >::SetMtx ( const int &  Attr,
const TMAGAffMtx Mtx 
) [inline]

Definition at line 183 of file mag.h.

{  AffMtxV[Attr] = Mtx;  }
template<class TNodeAttr>
void TMAGParam< TNodeAttr >::SetMtxAll ( const TMAGAffMtx Mtx) [inline]

Definition at line 185 of file mag.h.

{  AffMtxV.PutAll(Mtx);  }
template<class TNodeAttr>
void TMAGParam< TNodeAttr >::SetMtxV ( const TMAGAffMtxV MtxV) [inline]

Definition at line 184 of file mag.h.

{  NAttrs = AffMtxV.Len();  AffMtxV = MtxV;  }
template<class TNodeAttr>
void TMAGParam< TNodeAttr >::SetMtxVal ( const int &  Attr,
const int &  Row,
const int &  Col,
const double &  Val 
) [inline]

Definition at line 182 of file mag.h.

{  AffMtxV[Attr].At(Row, Col) = Val;  }
template<class TNodeAttr>
void TMAGParam< TNodeAttr >::SetNodeAttr ( const TNodeAttr &  Dist) [inline]

Definition at line 176 of file mag.h.

{  NodeAttr = Dist;  }
template<class TNodeAttr>
void TMAGParam< TNodeAttr >::SetNodes ( const int &  Nodes) [inline]

Definition at line 170 of file mag.h.

{  NNodes = Nodes;  }

Member Data Documentation

template<class TNodeAttr>
TMAGAffMtxV TMAGParam< TNodeAttr >::AffMtxV [private]

Definition at line 153 of file mag.h.

template<class TNodeAttr>
TInt TMAGParam< TNodeAttr >::NAttrs [private]

Definition at line 151 of file mag.h.

template<class TNodeAttr>
TInt TMAGParam< TNodeAttr >::NNodes [private]

Definition at line 150 of file mag.h.

template<class TNodeAttr>
TNodeAttr TMAGParam< TNodeAttr >::NodeAttr [private]

Definition at line 152 of file mag.h.

template<class TNodeAttr>
TRnd TMAGParam< TNodeAttr >::Rnd [static]

Definition at line 148 of file mag.h.


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