#include "stdafx.h"
#include "Snap.h"
#include "biasedrandomwalk.h"
Go to the source code of this file.
|
void | GetNodeAlias (TFltV &PTblV, TIntVFltVPr &NTTable) |
|
int64 | AliasDrawInt (TIntVFltVPr &NTTable, TRnd &Rnd) |
|
void | PreprocessNode (PWNet &InNet, double &ParamP, double &ParamQ, TWNet::TNodeI NI, int64 &NCnt, bool &Verbose) |
|
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...
|
|
int64 | PredictMemoryRequirements (PWNet &InNet) |
|
void | SimulateWalk (PWNet &InNet, int64 StartNId, int &WalkLen, TRnd &Rnd, TIntV &WalkV) |
| Simulates one walk and writes it into Walk vector. More...
|
|
Definition at line 40 of file biasedrandomwalk.cpp.
const TVal1 & GetVal1() const
const TVal2 & GetVal2() const
Definition at line 6 of file biasedrandomwalk.cpp.
10 for (
int64 i = 0; i < N; i++) {
16 for (
int64 i = 0; i < N; i++) {
24 while (UnderV.
Len() > 0 && OverV.
Len() > 0) {
30 UTbl[Large] = UTbl[Large] + UTbl[Small] - 1;
31 if (UTbl[Large] < 1) {
TSizeTy Len() const
Returns the number of elements in the vector.
const TVal & Last() const
Returns a reference to the last element of the vector.
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
void DelLast()
Removes the last element of the vector.
Definition at line 108 of file biasedrandomwalk.cpp.
110 for (
TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
111 for (
int64 i = 0; i < NI.GetOutDeg(); i++) {
int GetOutDeg() const
Returns out-degree of the current node.
Node iterator. Only forward iteration (operator++) is supported.
void PreprocessNode |
( |
PWNet & |
InNet, |
|
|
double & |
ParamP, |
|
|
double & |
ParamQ, |
|
|
TWNet::TNodeI |
NI, |
|
|
int64 & |
NCnt, |
|
|
bool & |
Verbose |
|
) |
| |
Definition at line 47 of file biasedrandomwalk.cpp.
49 if (Verbose && NCnt%100 == 0) {
50 printf(
"\rPreprocessing progress: %.2lf%% ",(
double)NCnt*100/(
double)(InNet->GetNodes()));fflush(stdout);
64 if (!(InNet->GetEDat(CurrI.
GetId(), FId, Weight))){
continue; }
65 if (FId==NI.
GetId()) {
66 PTable.
Add(Weight / ParamP);
67 Psum += Weight / ParamP;
68 }
else if (NbrH.
IsKey(FId)) {
72 PTable.
Add(Weight / ParamQ);
73 Psum += Weight / ParamQ;
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
void GetNodeAlias(TFltV &PTblV, TIntVFltVPr &NTTable)
int GetOutDeg() const
Returns out-degree of the current node.
Node iterator. Only forward iteration (operator++) is supported.
int AddKey(const TKey &Key)
bool IsKey(const TKey &Key) const
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
int GetId() const
Returns ID of the current node.
const TNodeData & GetDat() const
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.
87 for (
TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
90 for (
TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
91 for (
int64 i = 0; i < NI.GetOutDeg(); i++) {
98 for (
TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
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);
105 if(Verbose){ printf(
"\n"); }
THash< TInt, TIntVFltVPr > TIntIntVFltVPrH
TSizeTy Len() const
Returns the number of elements in the vector.
int GetOutDeg() const
Returns out-degree of the current node.
Node iterator. Only forward iteration (operator++) is supported.
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
void PreprocessNode(PWNet &InNet, double &ParamP, double &ParamQ, TWNet::TNodeI NI, int64 &NCnt, bool &Verbose)
const TNodeData & GetDat() const
Simulates one walk and writes it into Walk vector.
Definition at line 120 of file biasedrandomwalk.cpp.
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) {
128 if (InNet->GetNI(Dst).GetOutDeg() == 0) {
return; }
130 WalkV.
Add(InNet->GetNI(Dst).GetNbrNId(Next));
int64 AliasDrawInt(TIntVFltVPr &NTTable, TRnd &Rnd)
TSizeTy Len() const
Returns the number of elements in the vector.
const TVal & LastLast() const
Returns a reference to the one before last element of the vector.
const TVal & Last() const
Returns a reference to the last element of the vector.
int GetUniDevInt(const int &Range=0)
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.