4 void node2vec(
PWNet& InNet,
double& ParamP,
double& ParamQ,
int& Dimensions,
5 int& WalkLen,
int& NumWalks,
int& WinSize,
int& Iter,
bool& Verbose,
10 for (
TWNet::TNodeI NI = InNet->BegNI(); NI < InNet->EndNI(); NI++) {
11 NIdsV.
Add(NI.GetId());
18 for (
int64 i = 0; i < NumWalks; i++) {
20 #pragma omp parallel for schedule(dynamic)
21 for (
int64 j = 0; j < NIdsV.
Len(); j++) {
22 if ( Verbose && WalksDone%10000 == 0 ) {
23 printf(
"\rWalking Progress: %.2lf%%",(
double)WalksDone*100/(
double)AllWalks);fflush(stdout);
27 for (
int64 k = 0; k < WalkV.
Len(); k++) {
28 WalksVV.
PutXY(i*NIdsV.
Len()+j, k, WalkV[k]);
38 LearnEmbeddings(WalksVV, Dimensions, WinSize, Iter, Verbose, EmbeddingsHV);
42 int& WalkLen,
int& NumWalks,
int& WinSize,
int& Iter,
bool& Verbose,
46 if (!NewNet->IsNode(EI.GetSrcNId())) { NewNet->AddNode(EI.GetSrcNId()); }
47 if (!NewNet->IsNode(EI.GetDstNId())) { NewNet->AddNode(EI.GetDstNId()); }
48 NewNet->AddEdge(EI.GetSrcNId(), EI.GetDstNId(), 1.0);
50 node2vec(NewNet, ParamP, ParamQ, Dimensions, WalkLen, NumWalks, WinSize, Iter,
51 Verbose, EmbeddingsHV);
55 int& Dimensions,
int& WalkLen,
int& NumWalks,
int& WinSize,
int& Iter,
bool& Verbose,
59 if (!NewNet->IsNode(EI.GetSrcNId())) { NewNet->AddNode(EI.GetSrcNId()); }
60 if (!NewNet->IsNode(EI.GetDstNId())) { NewNet->AddNode(EI.GetDstNId()); }
61 NewNet->AddEdge(EI.GetSrcNId(), EI.GetDstNId(), InNet->GetFltAttrDatE(EI,
"weight"));
63 node2vec(NewNet, ParamP, ParamQ, Dimensions, WalkLen, NumWalks, WinSize, Iter,
64 Verbose, EmbeddingsHV);
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
TSizeTy Len() const
Returns the number of elements in the vector.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
void SimulateWalk(PWNet &InNet, int64 StartNId, int &WalkLen, TRnd &Rnd, TIntV &WalkV)
Simulates one walk and writes it into Walk vector.
Edge iterator. Only forward iteration (operator++) is supported.
void node2vec(PWNet &InNet, double &ParamP, double &ParamQ, int &Dimensions, int &WalkLen, int &NumWalks, int &WinSize, int &Iter, bool &Verbose, TIntFltVH &EmbeddingsHV)
Calculates node2vec feature representation for nodes and writes them into EmbeddinsHV, see http://arxiv.org/pdf/1607.00653v1.pdf.
Node iterator. Only forward iteration (operator++) is supported.
void PreprocessTransitionProbs(PWNet &InNet, double &ParamP, double &ParamQ, bool &Verbose)
Preprocesses transition probabilities for random walks. Has to be called once before SimulateWalk cal...
Edge iterator. Only forward iteration (operator++) is supported.
void LearnEmbeddings(TVVec< TInt, int64 > &WalksVV, int &Dimensions, int &WinSize, int &Iter, bool &Verbose, TIntFltVH &EmbeddingsHV)
Learns embeddings using SGD, Skip-gram with negative sampling.
void PutXY(const TSizeTy &X, const TSizeTy &Y, const TVal &Val)
void Shuffle(TRnd &Rnd)
Randomly shuffles the elements of the vector.
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.