SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TMAGNodeBern Class Reference

#include <mag.h>

Public Member Functions

 TMAGNodeBern ()
 
 TMAGNodeBern (const int &_Dim, const double &_Mu=0.5)
 
 TMAGNodeBern (const TFltV &_MuV)
 
 TMAGNodeBern (const TMAGNodeBern &Dist)
 
TMAGNodeBernoperator= (const TMAGNodeBern &Dist)
 
void SetMuV (const TFltV &_MuV)
 
const TFltVGetMuV () const
 
void SetMu (const int &Attr, const double &Prob)
 
double GetMu (const int &Attr) const
 
void LoadTxt (const TStr &InFNm)
 
void SaveTxt (TStrV &OutStrV) const
 
void AttrGen (TIntVV &AttrVV, const int &NNodes)
 

Static Public Attributes

static TRnd Rnd = TRnd(0)
 

Private Attributes

TFltV MuV
 
TInt Dim
 

Detailed Description

Definition at line 88 of file mag.h.

Constructor & Destructor Documentation

TMAGNodeBern::TMAGNodeBern ( )
inline

Definition at line 95 of file mag.h.

95 : MuV(), Dim(-1) {}
TInt Dim
Definition: mag.h:93
TFltV MuV
Definition: mag.h:92
TMAGNodeBern::TMAGNodeBern ( const int &  _Dim,
const double &  _Mu = 0.5 
)
inline

Definition at line 96 of file mag.h.

96 : MuV(_Dim), Dim(_Dim) { IAssert(_Mu >= 0.0 && _Mu <= 1.0); MuV.PutAll(_Mu); }
#define IAssert(Cond)
Definition: bd.h:262
TInt Dim
Definition: mag.h:93
TFltV MuV
Definition: mag.h:92
void PutAll(const TVal &Val)
Sets all elements of the vector to value Val.
Definition: ds.h:1166
TMAGNodeBern::TMAGNodeBern ( const TFltV _MuV)
inline

Definition at line 97 of file mag.h.

97 : MuV(_MuV), Dim(_MuV.Len()) {}
TInt Dim
Definition: mag.h:93
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TFltV MuV
Definition: mag.h:92
TMAGNodeBern::TMAGNodeBern ( const TMAGNodeBern Dist)
inline

Definition at line 98 of file mag.h.

98 : MuV(Dist.MuV), Dim(Dist.Dim) {}
TInt Dim
Definition: mag.h:93
TFltV MuV
Definition: mag.h:92

Member Function Documentation

void TMAGNodeBern::AttrGen ( TIntVV AttrVV,
const int &  NNodes 
)

Definition at line 250 of file mag.cpp.

250  {
251  IAssert(Dim > 0);
252  AttrVV.Gen(NNodes, Dim);
253  AttrVV.PutAll(0);
254 
255  for(int i = 0; i < NNodes; i++) {
256  for(int l = 0; l < Dim; l++) {
257  if((TMAGNodeBern::Rnd).GetUniDev() > MuV[l]) {
258  AttrVV.At(i, l) = 1;
259  }
260  }
261  }
262 }
#define IAssert(Cond)
Definition: bd.h:262
TInt Dim
Definition: mag.h:93
TFltV MuV
Definition: mag.h:92
void Gen(const int &_XDim, const int &_YDim)
Definition: ds.h:2181
static TRnd Rnd
Definition: mag.h:90
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:2190
void PutAll(const TVal &Val)
Definition: ds.h:2202
double TMAGNodeBern::GetMu ( const int &  Attr) const
inline

Definition at line 105 of file mag.h.

105 { return MuV[Attr]; }
TFltV MuV
Definition: mag.h:92
const TFltV& TMAGNodeBern::GetMuV ( ) const
inline

Definition at line 103 of file mag.h.

103 { return MuV; }
TFltV MuV
Definition: mag.h:92
void TMAGNodeBern::LoadTxt ( const TStr InFNm)

Definition at line 264 of file mag.cpp.

264  {
265  FILE *fp = fopen(InFNm.CStr(), "r");
266  IAssertR(fp != NULL, "File does not exist: " + InFNm);
267 
268  Dim = 0;
269  MuV.Gen(10, 0);
270 
271  char buf[128];
272  char *token;
273  TStr TokenStr;
274  TFlt Val;
275 
276  while(fgets(buf, sizeof(buf), fp) != NULL) {
277  token = strtok(buf, "&");
278  token = strtok(token, " \t");
279  TokenStr = TStr(token);
280  MuV.Add(TokenStr.GetFlt(Val));
281  }
282  Dim = MuV.Len();
283 
284  fclose(fp);
285 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
TInt Dim
Definition: mag.h:93
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
Definition: dt.h:1293
double GetFlt() const
Definition: dt.h:628
TFltV MuV
Definition: mag.h:92
Definition: dt.h:412
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
char * CStr()
Definition: dt.h:476
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
TMAGNodeBern & TMAGNodeBern::operator= ( const TMAGNodeBern Dist)

Definition at line 244 of file mag.cpp.

244  {
245  MuV = Dist.MuV;
246  Dim = Dist.Dim;
247  return (*this);
248 }
TInt Dim
Definition: mag.h:93
TFltV MuV
Definition: mag.h:92
void TMAGNodeBern::SaveTxt ( TStrV OutStrV) const

Definition at line 287 of file mag.cpp.

287  {
288  OutStrV.Gen(Dim, 0);
289 
290  for(int i = 0; i < Dim; i++) {
291  OutStrV.Add(TStr::Fmt("%f", double(MuV[i])));
292  }
293 }
TInt Dim
Definition: mag.h:93
TFltV MuV
Definition: mag.h:92
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
void TMAGNodeBern::SetMu ( const int &  Attr,
const double &  Prob 
)
inline

Definition at line 104 of file mag.h.

104 { IAssert(Prob >= 0.0 && Prob <= 1.0); MuV[Attr] = Prob; }
#define IAssert(Cond)
Definition: bd.h:262
TFltV MuV
Definition: mag.h:92
void TMAGNodeBern::SetMuV ( const TFltV _MuV)
inline

Definition at line 102 of file mag.h.

102 { MuV = _MuV; }
TFltV MuV
Definition: mag.h:92

Member Data Documentation

TInt TMAGNodeBern::Dim
private

Definition at line 93 of file mag.h.

TFltV TMAGNodeBern::MuV
private

Definition at line 92 of file mag.h.

TRnd TMAGNodeBern::Rnd = TRnd(0)
static

Definition at line 90 of file mag.h.


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