SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
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
biasedrandomwalk.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef TNodeEDatNet
< TIntIntVFltVPrH, TFlt
TWNet
 
typedef TPt< TWNetPWNet
 

Functions

void PreprocessTransitionProbs (PWNet &InNet, double &ParamP, double &ParamQ, bool &verbose)
 Preprocesses transition probabilities for random walks. Has to be called once before SimulateWalk calls. More...
 
void SimulateWalk (PWNet &InNet, int64 StartNId, int &WalkLen, TRnd &Rnd, TIntV &Walk)
 Simulates one walk and writes it into Walk vector. More...
 
int64 PredictMemoryRequirements (PWNet &InNet)
 

Typedef Documentation

typedef TPt<TWNet> PWNet

Definition at line 5 of file biasedrandomwalk.h.

Definition at line 4 of file biasedrandomwalk.h.

Function Documentation

int64 PredictMemoryRequirements ( PWNet InNet)

Definition at line 108 of file biasedrandomwalk.cpp.

References TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetOutDeg().

108  {
109  int64 MemNeeded = 0;
110  for (TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
111  for (int64 i = 0; i < NI.GetOutDeg(); i++) {
112  TWNet::TNodeI CurrI = InNet->GetNI(NI.GetNbrNId(i));
113  MemNeeded += CurrI.GetOutDeg()*(sizeof(TInt) + sizeof(TFlt));
114  }
115  }
116  return MemNeeded;
117 }
Definition: dt.h:1383
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:559
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:537
Definition: dt.h:1134
long long int64
Definition: bd.h:27

Here is the call graph for this function:

void PreprocessTransitionProbs ( PWNet InNet,
double &  ParamP,
double &  ParamQ,
bool &  verbose 
)

Preprocesses transition probabilities for random walks. Has to be called once before SimulateWalk calls.

Definition at line 86 of file biasedrandomwalk.cpp.

References TVec< TVal, TSizeTy >::Add(), TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetDat(), TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetOutDeg(), TVec< TVal, TSizeTy >::Len(), and PreprocessNode().

Referenced by node2vec().

86  {
87  for (TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
88  InNet->SetNDat(NI.GetId(),TIntIntVFltVPrH());
89  }
90  for (TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
91  for (int64 i = 0; i < NI.GetOutDeg(); i++) { //allocating space in advance to avoid issues with multithreading
92  TWNet::TNodeI CurrI = InNet->GetNI(NI.GetNbrNId(i));
93  CurrI.GetDat().AddDat(NI.GetId(),TPair<TIntV,TFltV>(TIntV(CurrI.GetOutDeg()),TFltV(CurrI.GetOutDeg())));
94  }
95  }
96  int64 NCnt = 0;
97  TIntV NIds;
98  for (TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
99  NIds.Add(NI.GetId());
100  }
101 #pragma omp parallel for schedule(dynamic)
102  for (int64 i = 0; i < NIds.Len(); i++) {
103  PreprocessNode(InNet, ParamP, ParamQ, InNet->GetNI(NIds[i]), NCnt, Verbose);
104  }
105  if(Verbose){ printf("\n"); }
106 }
THash< TInt, TIntVFltVPr > TIntIntVFltVPrH
Definition: hash.h:625
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:559
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:537
Definition: ds.h:32
TVec< TFlt > TFltV
Definition: ds.h:1596
long long int64
Definition: bd.h:27
TVec< TInt > TIntV
Definition: ds.h:1594
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
void PreprocessNode(PWNet &InNet, double &ParamP, double &ParamQ, TWNet::TNodeI NI, int64 &NCnt, bool &Verbose)
const TNodeData & GetDat() const
Definition: network.h:581

Here is the call graph for this function:

Here is the caller graph for this function:

void SimulateWalk ( PWNet InNet,
int64  StartNId,
int &  WalkLen,
TRnd Rnd,
TIntV Walk 
)

Simulates one walk and writes it into Walk vector.

Definition at line 120 of file biasedrandomwalk.cpp.

References TVec< TVal, TSizeTy >::Add(), AliasDrawInt(), TRnd::GetUniDevInt(), TVec< TVal, TSizeTy >::Last(), TVec< TVal, TSizeTy >::LastLast(), and TVec< TVal, TSizeTy >::Len().

Referenced by node2vec().

120  {
121  WalkV.Add(StartNId);
122  if (WalkLen == 1) { return; }
123  if (InNet->GetNI(StartNId).GetOutDeg() == 0) { return; }
124  WalkV.Add(InNet->GetNI(StartNId).GetNbrNId(Rnd.GetUniDevInt(InNet->GetNI(StartNId).GetOutDeg())));
125  while (WalkV.Len() < WalkLen) {
126  int64 Dst = WalkV.Last();
127  int64 Src = WalkV.LastLast();
128  if (InNet->GetNI(Dst).GetOutDeg() == 0) { return; }
129  int64 Next = AliasDrawInt(InNet->GetNDat(Dst).GetDat(Src),Rnd);
130  WalkV.Add(InNet->GetNI(Dst).GetNbrNId(Next));
131  }
132 }
int64 AliasDrawInt(TIntVFltVPr &NTTable, TRnd &Rnd)
long long int64
Definition: bd.h:27
int GetUniDevInt(const int &Range=0)
Definition: dt.cpp:39

Here is the call graph for this function:

Here is the caller graph for this function: