SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
TMAGParam< TNodeAttr > Class Template Reference

#include <mag.h>

Collaboration diagram for TMAGParam< TNodeAttr >:

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:575
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:1022
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.

References TNGraph::AddEdge(), TNGraph::AddNode(), TVVec< TVal, TSizeTy >::At(), TVVec< TVal, TSizeTy >::GetYDim(), IAssert, and TNGraph::New().

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:481
TMAGAffMtxV AffMtxV
Definition: mag.h:153
TSizeTy GetYDim() const
Definition: ds.h:2251
TInt NAttrs
Definition: mag.h:151
Definition: bd.h:196
TInt NNodes
Definition: mag.h:150
const TVal & At(const TSizeTy &X, const TSizeTy &Y) const
Definition: ds.h:2256

Here is the call graph for this function:

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.

References TVVec< TVal, TSizeTy >::At(), TVVec< TVal, TSizeTy >::GetYDim(), and IAssert.

Referenced by TMAGFitBern::PlotProperties().

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
TSizeTy GetYDim() const
Definition: ds.h:2251
TNodeAttr NodeAttr
Definition: mag.h:152
TInt NAttrs
Definition: mag.h:151
Definition: bd.h:196
TInt NNodes
Definition: mag.h:150
const TVal & At(const TSizeTy &X, const TSizeTy &Y) const
Definition: ds.h:2256

Here is the call graph for this function:

Here is the caller graph for this function:

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.

References TVec< TVal, TSizeTy >::Gen().

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:523

Here is the call graph for this function:

template<class TNodeAttr>
const TMAGAffMtx& TMAGParam< TNodeAttr >::GetMtx ( const int &  Attr) const
inline
template<class TNodeAttr>
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().

188 { MtxV = AffMtxV; }
TMAGAffMtxV AffMtxV
Definition: mag.h:153

Here is the caller graph for this function:

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 >
void TMAGParam< TNodeAttr >::LoadTxt ( const TStr InFNm)

Definition at line 205 of file mag.h.

References TStr::CStr(), and TMAGAffMtx::GetMtx().

Referenced by TMAGParam< TMAGNodeBern >::TMAGParam().

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:523
TFltV & GetMtx()
Definition: mag.h:31
char * CStr()
Definition: dt.h:479
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TNodeAttr>
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.

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.

References TStr::CStr(), TStr::GetSubStr(), and TStr::Len().

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:490
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:479

Here is the call graph for this function:

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:523
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:1229
template<class TNodeAttr>
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().

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:575
TInt NAttrs
Definition: mag.h:151

Here is the caller graph for this function:

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.

Referenced by TMAGFitBern::Init(), TMAGFitBern::PlotProperties(), TMAGFitBern::RandomInit(), TMAGFitBern::SetMuV(), and TMAGFitBern::UpdateMu().

176 { NodeAttr = Dist; }
TNodeAttr NodeAttr
Definition: mag.h:152

Here is the caller graph for this function:

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.

Referenced by TMAGParam< TMAGNodeBern >::GetMtxV(), and TMAGParam< TNodeAttr >::operator=().

template<class TNodeAttr>
TInt TMAGParam< TNodeAttr >::NAttrs
private
template<class TNodeAttr>
TInt TMAGParam< TNodeAttr >::NNodes
private
template<class TNodeAttr>
TNodeAttr TMAGParam< TNodeAttr >::NodeAttr
private
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: