#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, const double &ParamP, const double &ParamQ, TWNet::TNodeI NI, int64 &NCnt, const bool &Verbose) |
|
void | PreprocessTransitionProbs (PWNet &InNet, const double &ParamP, const double &ParamQ, const 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, const int &WalkLen, TRnd &Rnd, TIntV &WalkV) |
| Simulates one walk and writes it into Walk vector. More...
|
|
Definition at line 51 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) {
37 while(UnderV.
Len() > 0){
42 while(OverV.
Len() > 0){
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 119 of file biasedrandomwalk.cpp.
121 for (
TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
122 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, |
|
|
const double & |
ParamP, |
|
|
const double & |
ParamQ, |
|
|
TWNet::TNodeI |
NI, |
|
|
int64 & |
NCnt, |
|
|
const bool & |
Verbose |
|
) |
| |
Definition at line 58 of file biasedrandomwalk.cpp.
60 if (Verbose && NCnt%100 == 0) {
61 printf(
"\rPreprocessing progress: %.2lf%% ",(
double)NCnt*100/(
double)(InNet->GetNodes()));fflush(stdout);
75 if (!(InNet->GetEDat(CurrI.
GetId(), FId, Weight))){
continue; }
76 if (FId==NI.
GetId()) {
77 PTable.
Add(Weight / ParamP);
78 Psum += Weight / ParamP;
79 }
else if (NbrH.
IsKey(FId)) {
83 PTable.
Add(Weight / ParamQ);
84 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, |
|
|
const double & |
ParamP, |
|
|
const double & |
ParamQ, |
|
|
const bool & |
Verbose |
|
) |
| |
Preprocesses transition probabilities for random walks. Has to be called once before SimulateWalk calls.
Definition at line 97 of file biasedrandomwalk.cpp.
98 for (
TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
101 for (
TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
102 for (
int64 i = 0; i < NI.GetOutDeg(); i++) {
109 for (
TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
110 NIds.
Add(NI.GetId());
112 #pragma omp parallel for schedule(dynamic)
113 for (
int64 i = 0; i < NIds.
Len(); i++) {
114 PreprocessNode(InNet, ParamP, ParamQ, InNet->GetNI(NIds[i]), NCnt, Verbose);
116 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.
void PreprocessNode(PWNet &InNet, const double &ParamP, const double &ParamQ, TWNet::TNodeI NI, int64 &NCnt, const bool &Verbose)
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
const TNodeData & GetDat() const
void SimulateWalk |
( |
PWNet & |
InNet, |
|
|
int64 |
StartNId, |
|
|
const int & |
WalkLen, |
|
|
TRnd & |
Rnd, |
|
|
TIntV & |
WalkV |
|
) |
| |
Simulates one walk and writes it into Walk vector.
Definition at line 131 of file biasedrandomwalk.cpp.
133 if (WalkLen == 1) {
return; }
134 if (InNet->GetNI(StartNId).GetOutDeg() == 0) {
return; }
135 WalkV.
Add(InNet->GetNI(StartNId).GetNbrNId(Rnd.
GetUniDevInt(InNet->GetNI(StartNId).GetOutDeg())));
136 while (WalkV.
Len() < WalkLen) {
139 if (InNet->GetNI(Dst).GetOutDeg() == 0) {
return; }
141 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.