-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfake_inf.cpp
More file actions
146 lines (120 loc) · 3.62 KB
/
Copy pathfake_inf.cpp
File metadata and controls
146 lines (120 loc) · 3.62 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "option.h"
#include "graph.h"
#include <iostream>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <fstream>
#include <cstring>
#include <random>
#include <omp.h>
using namespace std;
// compute eps-delta approx of INF_F using generalized SRA
float estimateFakeInfluence(Graph &g, int n, double epsilon_prime, double delta_prime) {
int b = n - g.getNumFakeSeeds();
double eps = epsilon_prime * (1 - (epsilon_prime * b)/((2 + 2.0/3.0 * epsilon_prime) * log(2.0 / delta_prime) * b));
long long int gamma = (1 + epsilon_prime) * (2 + 2.0/3.0 * eps) * log(2.0 / delta_prime) * (1.0 / (eps*eps)) * b;
long long int counter = 0;
long long int running_total = 0;
vector<bool> visit(n,false);
vector<int> visit_index(n,0);
while (running_total < gamma) {
running_total += g.generateFakeInfluenceSample(visit, visit_index);
counter++;
}
return (float)running_total / counter;
}
// compute eps-delta approx of INF_F using generalized SRA
float estimateFakeInfluenceParallel(Graph &g, int n, double epsilon_prime, double delta_prime) {
int b = n - g.getNumFakeSeeds();
double eps = epsilon_prime * (1 - (epsilon_prime * b)/((2 + 2.0/3.0 * epsilon_prime) * log(2.0 / delta_prime) * b));
long long int gamma = (1 + epsilon_prime) * (2 + 2.0/3.0 * eps) * log(2.0 / delta_prime) * (1.0 / (eps*eps)) * b;
long long int counter = 0;
long long int global_running_total = 0;
int c = 10000;
#pragma omp parallel
{
vector<bool> visit(n,false);
vector<int> visit_index(n,0);
long long int running_total;
while (global_running_total < gamma) {
running_total = 0;
for (int i = 0; i < c; i++) {
running_total += g.generateFakeInfluenceSample(visit, visit_index);
}
#pragma omp critical
{
global_running_total += running_total;
counter += c;
}
}
}
return (float)global_running_total / counter;
}
int main(int argc, char ** argv)
{
srand(time(NULL));
OptionParser op(argc, argv);
if (!op.validCheck()){
printf("Parameters error, please check the readme.txt file for correct format!\n");
return -1;
}
char * inFile = op.getPara("-i");
if (inFile == NULL){
inFile = (char*)"network";
}
char * outFile = op.getPara("-o");
if (outFile == NULL){
outFile = (char*)"fake.inf";
}
char * fakeSeedsFile = op.getPara("-fakeseeds");
if (fakeSeedsFile == NULL){
fakeSeedsFile = (char*)"fake.seeds";
}
char * tmp = op.getPara("-epsilon");
float epsilon = 0.1;
if (tmp != NULL){
epsilon = atof(tmp);
}
float ew = -1.0;
tmp = op.getPara("-ew");
if (tmp != NULL){
ew = atof(tmp);
}
bool fixed = (ew < 0.0) ? false : true;
Graph g(0, 0, 0.0, 0, false);
g.readGraph(inFile, fixed, ew);
g.readFakeSeeds(fakeSeedsFile);
int n = g.getNumNodes();
float delta = 1.0/n;
tmp = op.getPara("-delta");
if (tmp != NULL){
delta = atof(tmp);
}
cout << "\n*******************" << endl;
cout << "\tSTART" << endl;
cout << "*******************\n" << endl;
double epsilon_prime = epsilon / 2.0;
double delta_prime = delta / 9.0;
double start = omp_get_wtime();
float inf_f = estimateFakeInfluenceParallel(g, n, epsilon_prime, delta_prime);
cout << "Time to estimate INF_F: " << omp_get_wtime()-start << "s" << endl;
cout << "INF_F = " << inf_f << endl;
cout << "fake seed set: ";
const vector<int> &fs = g.getFakeSeeds();
for (unsigned int s = 0; s < g.getNumFakeSeeds(); s++) {
cout << fs[s] << " ";
}
cout << endl;
ofstream out(outFile, ios::app);
out << inf_f << endl;
out.close();
cout << "\n*******************" << endl;
cout << "\tALL DONE" << endl;
cout << "*******************" << endl;
//
// ALL DONE
//
}