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

#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 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.

156 : NNodes(-1), NAttrs(-1), NodeAttr(), AffMtxV() {}
TMAGAffMtxV AffMtxV
Definition: mag.h:153
TNodeAttr NodeAttr
Definition: mag.h:152
TInt NAttrs
Definition: mag.h:151
TInt NNodes
Definition: mag.h:150
template<class TNodeAttr>
TMAGParam< TNodeAttr >::TMAGParam ( const int &  NumNodes,
const int &  NumAttrs 
)
inline

Definition at line 157 of file mag.h.

157 : NNodes(NumNodes), NAttrs(NumAttrs), NodeAttr(), AffMtxV(NumAttrs) {}
TMAGAffMtxV AffMtxV
Definition: mag.h:153
TNodeAttr NodeAttr
Definition: mag.h:152
TInt NAttrs
Definition: mag.h:151
TInt NNodes
Definition: mag.h:150
template<class TNodeAttr>
TMAGParam< TNodeAttr >::TMAGParam ( const int &  NumNodes,
const TMAGAffMtxV MtxV 
)
inline

Definition at line 158 of file mag.h.

158 : NNodes(NumNodes), NAttrs(MtxV.Len()), NodeAttr(), AffMtxV(MtxV) {}
TMAGAffMtxV AffMtxV
Definition: mag.h:153
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TNodeAttr NodeAttr
Definition: mag.h:152
TInt NAttrs
Definition: mag.h:151
TInt NNodes
Definition: mag.h:150
template<class TNodeAttr>
TMAGParam< TNodeAttr >::TMAGParam ( const int &  NumNodes,
const TStr ConfFNm 
)
inline

Definition at line 159 of file mag.h.

159 : NNodes(NumNodes) { LoadTxt(ConfFNm); }
void LoadTxt(const TStr &InFNm)
Definition: mag.h:205
TInt NNodes
Definition: mag.h:150
template<class TNodeAttr>
TMAGParam< TNodeAttr >::TMAGParam ( const TMAGParam< TNodeAttr > &  MAGParam)
inline

Definition at line 160 of file mag.h.

160 : NNodes(MAGParam.NNodes), NAttrs(MAGParam.NAttrs), NodeAttr(MAGParam.NodeAttr), AffMtxV(MAGParam.AffMtxV) {}
TMAGAffMtxV AffMtxV
Definition: mag.h:153
TNodeAttr NodeAttr
Definition: mag.h:152
TInt NAttrs
Definition: mag.h:151
TInt NNodes
Definition: mag.h:150
template<class TNodeAttr>
TMAGParam< TNodeAttr >::TMAGParam ( const int &  NumNodes,
const int &  NumAttrs,
const TNodeAttr &  Dist 
)
inline

Definition at line 161 of file mag.h.

161 : NNodes(NumNodes), NAttrs(NumAttrs), NodeAttr(Dist), AffMtxV(NumAttrs) {}
TMAGAffMtxV AffMtxV
Definition: mag.h:153
TNodeAttr NodeAttr
Definition: mag.h:152
TInt NAttrs
Definition: mag.h:151
TInt NNodes
Definition: mag.h:150

Member Function Documentation

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

Definition at line 165 of file mag.h.

165 { AffMtxV.Clr(); }
TMAGAffMtxV AffMtxV
Definition: mag.h:153
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:971
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.

250  {
251  PNGraph Graph = TNGraph::New(NNodes, -1);
252  for(int i = 0; i < NNodes; i++) {
253  Graph->AddNode(i);
254  }
255 
256  if(Seed > 0) {
257  TNodeAttr::Rnd.PutSeed(Seed);
258  }
259 
260  IAssert(AttrVV.GetYDim() == NAttrs);
261  for(int i = 0; i < NNodes; i++) {
262  for(int l = 0; l < NAttrs; l++) {
263  IAssert(AttrVV.At(i, l) < AffMtxV[l].GetDim());
264  }
265  }
266 
267  for(int i = 0; i < NNodes; i++) {
268  for(int j = i; j < NNodes; j++) {
269  double Prob = 1.0;
270  for(int l = 0; l < NAttrs; l++) {
271  Prob *= AffMtxV[l].At(AttrVV.At(i, l), AttrVV.At(j, l));
272  }
273 
274  if(TNodeAttr::Rnd.GetUniDev() < Prob) {
275  Graph->AddEdge(i, j);
276  if(! IsDir && i != j) { Graph->AddEdge(j, i); }
277  }
278 
279  if(IsDir && i != j) {
280  Prob = 1.0;
281  for(int l = 0; l < NAttrs; l++) {
282  Prob *= AffMtxV[l].At(AttrVV.At(j, l), AttrVV.At(i, l));
283  }
284  if(TNodeAttr::Rnd.GetUniDev() < Prob) {
285  Graph->AddEdge(j, i);
286  }
287  }
288  }
289  }
290 
291  return Graph;
292 };
#define IAssert(Cond)
Definition: bd.h:262
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
Definition: graph.h:425
TMAGAffMtxV AffMtxV
Definition: mag.h:153
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
Definition: graph.cpp:236
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node IDs SrcNId to node DstNId to the graph.
Definition: graph.cpp:321
TInt NAttrs
Definition: mag.h:151
int GetYDim() const
Definition: ds.h:2185
TInt NNodes
Definition: mag.h:150
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:2190
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.

295  {
296  TNodeAttr::Rnd.PutSeed(Seed);
297  NodeAttr.AttrGen(AttrVV, NNodes);
298 
299  IAssert(AttrVV.GetYDim() == NAttrs);
300  for(int i = 0; i < NNodes; i++) {
301  for(int l = 0; l < NAttrs; l++) {
302  IAssert(AttrVV.At(i, l) < AffMtxV[l].GetDim());
303  }
304  }
305 
306  PNGraph Graph = GenAttrMAG(AttrVV, IsDir, 0);
307  return Graph;
308 
309 /*
310  for(int i = 0; i < NNodes; i++) {
311  for(int j = i; j < NNodes; j++) {
312  double Prob = 1.0;
313  for(int l = 0; l < NAttrs; l++) {
314  Prob *= AffMtxV[l].At(AttrVV.At(i, l), AttrVV.At(j, l));
315  }
316  if(TNodeAttr::Rnd.GetUniDev() < Prob) {
317  Graph->AddEdge(i, j);
318  if(! IsDir && i != j) { Graph->AddEdge(j, i); }
319  }
320 
321  if(IsDir && i != j) {
322  Prob = 1.0;
323  for(int l = 0; l < NAttrs; l++) {
324  Prob *= AffMtxV[l].At(AttrVV.At(j, l), AttrVV.At(i, l));
325  }
326  if(TNodeAttr::Rnd.GetUniDev() < Prob) {
327  Graph->AddEdge(j, i);
328  }
329  }
330  }
331  }
332 
333  return Graph;
334 */
335 };
#define IAssert(Cond)
Definition: bd.h:262
PNGraph GenAttrMAG(const TIntVV &AttrVV, const bool &IsDir=false, const int &Seed=1)
Definition: mag.h:250
TMAGAffMtxV AffMtxV
Definition: mag.h:153
TNodeAttr NodeAttr
Definition: mag.h:152
TInt NAttrs
Definition: mag.h:151
int GetYDim() const
Definition: ds.h:2185
TInt NNodes
Definition: mag.h:150
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:2190
template<class TNodeAttr>
const int TMAGParam< TNodeAttr >::GetAttrs ( ) const
inline

Definition at line 174 of file mag.h.

174 { return NAttrs; }
TInt NAttrs
Definition: mag.h:151
template<class TNodeAttr>
const int TMAGParam< TNodeAttr >::GetDim ( const int &  Attr) const
inline

Definition at line 179 of file mag.h.

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

Definition at line 242 of file mag.h.

242  {
243  DimV.Gen(NAttrs);
244  for(int i = 0; i < NAttrs; i++) {
245  DimV[i] = AffMtxV[i].GetDim();
246  }
247 };
TMAGAffMtxV AffMtxV
Definition: mag.h:153
TInt NAttrs
Definition: mag.h:151
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
template<class TNodeAttr>
const TMAGAffMtx& TMAGParam< TNodeAttr >::GetMtx ( const int &  Attr) const
inline

Definition at line 187 of file mag.h.

187 { return AffMtxV[Attr]; }
TMAGAffMtxV AffMtxV
Definition: mag.h:153
template<class TNodeAttr>
void TMAGParam< TNodeAttr >::GetMtxV ( TMAGAffMtxV MtxV) const
inline

Definition at line 188 of file mag.h.

188 { MtxV = AffMtxV; }
TMAGAffMtxV AffMtxV
Definition: mag.h:153
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.

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

Definition at line 177 of file mag.h.

177 { return NodeAttr; }
TNodeAttr NodeAttr
Definition: mag.h:152
template<class TNodeAttr>
const int TMAGParam< TNodeAttr >::GetNodes ( ) const
inline

Definition at line 171 of file mag.h.

171 { return NNodes; }
TInt NNodes
Definition: mag.h:150
template<class TNodeAttr >
void TMAGParam< TNodeAttr >::LoadTxt ( const TStr InFNm)

Definition at line 205 of file mag.h.

205  {
206  NodeAttr.LoadTxt(InFNm);
207 
208  char buf[1024];
209  FILE *fp = fopen(InFNm.CStr(), "r");
210  NAttrs = 0;
211  AffMtxV.Gen(10, 0);
212  while(fgets(buf, sizeof(buf), fp) != NULL) {
213  strtok(buf, "&");
214  char *token = strtok(NULL, "\r\n");
215  NAttrs++;
217  }
218  fclose(fp);
219 };
TMAGAffMtxV AffMtxV
Definition: mag.h:153
TNodeAttr NodeAttr
Definition: mag.h:152
Definition: dt.h:412
TInt NAttrs
Definition: mag.h:151
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
TFltV & GetMtx()
Definition: mag.h:31
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
template<class TNodeAttr>
TMAGParam< TNodeAttr > & TMAGParam< TNodeAttr >::operator= ( const TMAGParam< TNodeAttr > &  MAGParam)

Definition at line 195 of file mag.h.

195  {
196  NNodes = MAGParam.NNodes;
197  NAttrs = MAGParam.NAttrs;
198  AffMtxV = MAGParam.AffMtxV;
199  NodeAttr = MAGParam.NodeAttr;
200 
201  return (*this);
202 };
TMAGAffMtxV AffMtxV
Definition: mag.h:153
TNodeAttr NodeAttr
Definition: mag.h:152
TInt NAttrs
Definition: mag.h:151
TInt NNodes
Definition: mag.h:150
template<class TNodeAttr >
void TMAGParam< TNodeAttr >::SaveTxt ( const TStr OutFNm) const

Definition at line 222 of file mag.h.

222  {
223  TStrV OutStrV;
224  NodeAttr.SaveTxt(OutStrV);
225 
226  FILE *fp = fopen(OutFNm.CStr(), "w");
227  fprintf(fp, "# %d nodes with %d attributes\n", NNodes(), NAttrs());
228  for(int i = 0; i < NAttrs; i++) {
229  TStr MtxStr = AffMtxV[i].GetMtxStr();
230  fprintf(fp, "%s & %s\n", OutStrV[i].CStr(), MtxStr.GetSubStr(1, MtxStr.Len()-2).CStr());
231  }
232  fclose(fp);
233 };
int Len() const
Definition: dt.h:487
TMAGAffMtxV AffMtxV
Definition: mag.h:153
TStr GetSubStr(const int &BChN, const int &EChN) const
Definition: dt.cpp:811
TNodeAttr NodeAttr
Definition: mag.h:152
Definition: dt.h:412
TInt NAttrs
Definition: mag.h:151
TInt NNodes
Definition: mag.h:150
char * CStr()
Definition: dt.h:476
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
template<class TNodeAttr >
void TMAGParam< TNodeAttr >::SetAttrs ( const int &  Attrs)

Definition at line 236 of file mag.h.

236  {
237  NAttrs = Attrs;
238  AffMtxV.Gen(Attrs);
239 };
TMAGAffMtxV AffMtxV
Definition: mag.h:153
TInt NAttrs
Definition: mag.h:151
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
template<class TNodeAttr>
void TMAGParam< TNodeAttr >::SetMtx ( const int &  Attr,
const TMAGAffMtx Mtx 
)
inline

Definition at line 183 of file mag.h.

183 { AffMtxV[Attr] = Mtx; }
TMAGAffMtxV AffMtxV
Definition: mag.h:153
template<class TNodeAttr>
void TMAGParam< TNodeAttr >::SetMtxAll ( const TMAGAffMtx Mtx)
inline

Definition at line 185 of file mag.h.

185 { AffMtxV.PutAll(Mtx); }
TMAGAffMtxV AffMtxV
Definition: mag.h:153
void PutAll(const TVal &Val)
Sets all elements of the vector to value Val.
Definition: ds.h:1166
template<class TNodeAttr>
void TMAGParam< TNodeAttr >::SetMtxV ( const TMAGAffMtxV MtxV)
inline

Definition at line 184 of file mag.h.

184 { NAttrs = AffMtxV.Len(); AffMtxV = MtxV; }
TMAGAffMtxV AffMtxV
Definition: mag.h:153
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TInt NAttrs
Definition: mag.h:151
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.

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

Definition at line 176 of file mag.h.

176 { NodeAttr = Dist; }
TNodeAttr NodeAttr
Definition: mag.h:152
template<class TNodeAttr>
void TMAGParam< TNodeAttr >::SetNodes ( const int &  Nodes)
inline

Definition at line 170 of file mag.h.

170 { NNodes = Nodes; }
TInt NNodes
Definition: mag.h:150

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: