-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroundTruth.h
87 lines (81 loc) · 2.46 KB
/
GroundTruth.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// Created by lostrong on 11/4/19.
//
#ifndef RADARPUSHIMPL_GROUNDTRUTH_H
#define RADARPUSHIMPL_GROUNDTRUTH_H
#include <chrono>
#include <random>
#include "graph.h"
class groundtruth {
public:
Graph* graph;
double alpha;
int K;
groundtruth(Graph& graph_v, double alpha_v, int K_v){
graph=&graph_v;
alpha = alpha_v;
K = K_v;
}
void compute() {
std::default_random_engine generator;
std::geometric_distribution<int> distribution(alpha);
vector<int> lengths;
int total_walks = K*graph->n;
for(int i=0;i<total_walks;i++){
int walk_length = distribution(generator);
lengths.push_back(walk_length);
}
int ind = 0;
vector<int> end_counts;
for(int i=0;i<graph->n;i++){
end_counts.push_back(0);
}
for (int i = 0;i < graph->n;i++) {
cout << i << endl;
for (int j = 0; j < K; j++) {
int walk = lengths[ind++];
int current_node = i;
for (int z = 0; z < walk; z++) {
int neighbor_cnt = ((graph->g)[current_node]).size();
int next_node = graph->g[current_node][rand() % neighbor_cnt];
current_node = next_node;
if(z==walk-1){
end_counts[current_node]++;
}
}
}
}
ofstream out("groundtruth.txt");
if (!out){
cout<<"file cannot open"<<endl;
}
for(int i=0;i<graph->n;i++){
out<<i<<"\t"<<1.0*end_counts[i]/total_walks<<endl;
}
out.close();
}
void power_iteration(){
vector<double>residue(graph->n, 1.0/graph->n);
vector<double>reserve(graph->n, 0);
for(int round = 0; round < 1000; round++){
INFO(round);
for(int u = 0; u < graph->n; u++){
double increment = (1 - alpha) * residue[u] / graph->g[u].size();
reserve[u] += alpha * residue[u];
residue[u] = 0;
for(auto v : graph->g[u]){
residue[v] += increment;
}
}
}
ofstream out("groundtruth.txt");
if (!out){
cout<<"file cannot open"<<endl;
}
for(int i=0;i<graph->n;i++){
out<<i<<"\t"<<reserve[i]<<endl;
}
out.close();
}
};
#endif //RADARPUSHIMPL_GROUNDTRUTH_H