4 void node2vec(
PWNet& InNet,
const double& ParamP,
const double& ParamQ,
5 const int& Dimensions,
const int& WalkLen,
const int& NumWalks,
6 const int& WinSize,
const int& Iter,
const bool& Verbose,
12 for (
TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
13 NIdsV.
Add(NI.GetId());
20 for (
int64 i = 0; i < NumWalks; i++) {
22 #pragma omp parallel for schedule(dynamic)
23 for (
int64 j = 0; j < NIdsV.
Len(); j++) {
24 if ( Verbose && WalksDone%10000 == 0 ) {
25 printf(
"\rWalking Progress: %.2lf%%",(
double)WalksDone*100/(
double)AllWalks);fflush(stdout);
29 for (
int64 k = 0; k < WalkV.
Len(); k++) {
30 WalksVV.
PutXY(i*NIdsV.
Len()+j, k, WalkV[k]);
41 LearnEmbeddings(WalksVV, Dimensions, WinSize, Iter, Verbose, EmbeddingsHV);
46 const int& Dimensions,
const int& WalkLen,
const int& NumWalks,
47 const int& WinSize,
const int& Iter,
const bool& Verbose,
51 node2vec(InNet, ParamP, ParamQ, Dimensions, WalkLen, NumWalks, WinSize,
52 Iter, Verbose, OutputWalks, WalksVV, EmbeddingsHV);
57 const int& Dimensions,
const int& WalkLen,
const int& NumWalks,
58 const int& WinSize,
const int& Iter,
const bool& Verbose,
63 if (!NewNet->IsNode(EI.GetSrcNId())) { NewNet->AddNode(EI.GetSrcNId()); }
64 if (!NewNet->IsNode(EI.GetDstNId())) { NewNet->AddNode(EI.GetDstNId()); }
65 NewNet->AddEdge(EI.GetSrcNId(), EI.GetDstNId(), 1.0);
67 node2vec(NewNet, ParamP, ParamQ, Dimensions, WalkLen, NumWalks, WinSize, Iter,
68 Verbose, OutputWalks, WalksVV, EmbeddingsHV);
72 const int& Dimensions,
const int& WalkLen,
const int& NumWalks,
73 const int& WinSize,
const int& Iter,
const bool& Verbose,
77 node2vec(InNet, ParamP, ParamQ, Dimensions, WalkLen, NumWalks, WinSize,
78 Iter, Verbose, OutputWalks, WalksVV, EmbeddingsHV);
82 const int& Dimensions,
const int& WalkLen,
const int& NumWalks,
83 const int& WinSize,
const int& Iter,
const bool& Verbose,
88 if (!NewNet->IsNode(EI.GetSrcNId())) { NewNet->AddNode(EI.GetSrcNId()); }
89 if (!NewNet->IsNode(EI.GetDstNId())) { NewNet->AddNode(EI.GetDstNId()); }
90 NewNet->AddEdge(EI.GetSrcNId(), EI.GetDstNId(), InNet->GetFltAttrDatE(EI,
"weight"));
92 node2vec(NewNet, ParamP, ParamQ, Dimensions, WalkLen, NumWalks, WinSize, Iter,
93 Verbose, OutputWalks, WalksVV, EmbeddingsHV);
97 const int& Dimensions,
const int& WalkLen,
const int& NumWalks,
98 const int& WinSize,
const int& Iter,
const bool& Verbose,
101 bool OutputWalks = 0;
102 node2vec(InNet, ParamP, ParamQ, Dimensions, WalkLen, NumWalks, WinSize,
103 Iter, Verbose, OutputWalks, WalksVV, EmbeddingsHV);
TSizeTy Len() const
Returns the number of elements in the vector.
void LearnEmbeddings(TVVec< TInt, int64 > &WalksVV, const int &Dimensions, const int &WinSize, const int &Iter, const bool &Verbose, TIntFltVH &EmbeddingsHV)
Learns embeddings using SGD, Skip-gram with negative sampling.
Edge iterator. Only forward iteration (operator++) is supported.
Node iterator. Only forward iteration (operator++) is supported.
void SimulateWalk(PWNet &InNet, int64 StartNId, const int &WalkLen, TRnd &Rnd, TIntV &WalkV)
Simulates one walk and writes it into Walk vector.
Edge iterator. Only forward iteration (operator++) is supported.
void PutXY(const TSizeTy &X, const TSizeTy &Y, const TVal &Val)
void Shuffle(TRnd &Rnd)
Randomly shuffles the elements of the vector.
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 cal...
void node2vec(PWNet &InNet, const double &ParamP, const double &ParamQ, const int &Dimensions, const int &WalkLen, const int &NumWalks, const int &WinSize, const int &Iter, const bool &Verbose, const bool &OutputWalks, TVVec< TInt, int64 > &WalksVV, TIntFltVH &EmbeddingsHV)
Calculates node2vec feature representation for nodes and writes them into EmbeddinsHV, see http://arxiv.org/pdf/1607.00653v1.pdf.
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.