-
Notifications
You must be signed in to change notification settings - Fork 0
/
hll_network_real_vs_estimate.cpp
177 lines (136 loc) · 4.98 KB
/
hll_network_real_vs_estimate.cpp
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include <iostream>
#include <fstream>
#include <vector>
#include <ctime>
#include <hyperloglog.hpp>
#include <dag.hpp>
#define HLL_DENSE_PERC 10
#define NETWORK_TYPE dag::undirected_temporal_network<uint32_t, double>
using hll_t = hll::HyperLogLog<HLL_DENSE_PERC, 19>;
using temp_net = NETWORK_TYPE;
using temp_vert = typename temp_net::VertexType;
using temp_edge = typename temp_net::EdgeType;
using temp_time = typename temp_edge::TimeType;
enum class prob_dist_types { deterministic, exponential };
#include "measures.hpp"
#include "event_graph.hpp"
#include "network.hpp"
#include "out_component_size_estimate.hpp"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#include "cxxopts.hpp"
#pragma GCC diagnostic pop
cxxopts::Options define_options() {
cxxopts::Options options("largest_out_component",
"largest out-component of a temporal network");
options.add_options()
("s,seed", "random number generator seed (required)",
cxxopts::value<size_t>())
("dt", "delta-t parameter. maximum dt of dag",
cxxopts::value<temp_time>()->default_value("1"))
("h,help", "Print help")
;
options.add_options("Event List File")
("temporal-reserve", "estimated size of temporal network",
cxxopts::value<size_t>()->default_value("0"))
("n,network", "network in event-list format (required)",
cxxopts::value<std::string>())
;
options.add_options("Output")
("out-component-sizes", "file to store out-component sizes of all events",
cxxopts::value<std::string>())
;
return options;
}
template <prob_dist_types dist_type>
double prob_dist(const temp_edge& a, const temp_edge& b, temp_time dt);
template <>
double prob_dist<prob_dist_types::deterministic>(
const temp_edge& a, const temp_edge& b, temp_time max_dt) {
if (b.time > a.effect_time() && b.time - a.effect_time() < max_dt)
return 1;
else
return 0;
}
struct options_t {
public:
size_t seed;
uint32_t hll_seed;
std::string out_comps_filename;
size_t temporal_reserve = 0;
std::string network_filename;
prob_dist_types prob_dist_type;
std::function<double(const temp_edge& a, const temp_edge& b, temp_time dt)>
prob_dist;
temp_time dt;
};
options_t parse_options(int argc, const char* argv[]) {
cxxopts::Options option_defs = define_options();
auto options = option_defs.parse(argc, argv);
options_t opts;
if (options.count("help") != 0) {
std::cerr << option_defs.help({"", "Event List File", "Output"})
<< std::endl;
std::exit(0);
}
if (options.count("seed") == 0) {
std::cerr << "ERROR: needs a seed argument" << std::endl;
std::cerr << option_defs.help({"", "Event List File", "Output"})
<< std::endl;
std::exit(1);
}
opts.seed = options["seed"].as<size_t>();
std::mt19937_64 gen(opts.seed);
std::uniform_int_distribution<uint32_t> sd;
opts.hll_seed = sd(gen);
if (options.count("network") == 0) {
std::cerr << "ERROR: needs a network argument" << std::endl;
std::cerr << option_defs.help({"", "Event List File", "Output"})
<< std::endl;
std::exit(1);
}
opts.network_filename = options["network"].as<std::string>();
if (options.count("temporal-reserve") != 0)
opts.temporal_reserve = options["temporal-reserve"].as<size_t>();
if (options.count("out-component-sizes") == 0) {
std::cerr << "ERROR: needs an out-component-sizes argument" << std::endl;
std::cerr << option_defs.help({"", "Event List File", "Output"})
<< std::endl;
std::exit(1);
}
opts.out_comps_filename = options["out-component-sizes"].as<std::string>();
opts.dt = options["dt"].as<temp_time>();
opts.prob_dist = prob_dist<prob_dist_types::deterministic>;
return opts;
}
int main(int argc, const char* argv[]) {
options_t opts = parse_options(argc, argv);
std::vector<temp_edge> events = event_list<temp_edge>(
opts.network_filename,
opts.temporal_reserve);
auto eg = event_graph<temp_edge>(events, opts.dt, opts.prob_dist, opts.seed,
opts.prob_dist_type == prob_dist_types::deterministic);
using probabilistic_counter = counter<temp_edge, hll_estimator_readonly>;
std::vector<std::pair<temp_edge, probabilistic_counter>>
out_comp_size = out_component_size_estimate<temp_edge>(
eg, opts.hll_seed, false); // return the estimation for all events
std::ofstream out_comps_file;
out_comps_file.open(opts.out_comps_filename);
out_comps_file
<< "S_e-real" << " "
<< "S_e-est" << " "
<< "S_n-real" << " "
<< "S_n-est" << "\n";
for (auto&& p: out_comp_size) {
temp_time start, end;
std::tie(start, end) = p.second.lifetime();
auto out_comp = out_component(eg, p.first,
static_cast<size_t>(p.second.node_set().estimate()+0.5),
static_cast<size_t>(p.second.edge_set().estimate()+0.5));
out_comps_file
<< out_comp.edge_set().size() << " "
<< p.second.edge_set().estimate() << " "
<< out_comp.node_set().size() << " "
<< p.second.node_set().estimate() << "\n";
}
}