MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / run

Method run

libCacheSim/traceAnalyzer/popularity.cpp:47–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47void Popularity::run(obj_info_map_type &obj_map) {
48 /* freq_vec_ is a sorted vec of obj frequency */
49 freq_vec_.reserve(obj_map.size());
50 for (const auto &p : obj_map) {
51 freq_vec_.push_back(p.second.freq);
52 }
53 sort(freq_vec_.begin(), freq_vec_.end(), greater<>());
54
55 if (obj_map.size() < 200) {
56 fit_fail_reason_ = "popularity: too few objects (" +
57 to_string(obj_map.size()) +
58 "), skip the popularity computation";
59 WARN("%s\n", fit_fail_reason_.c_str());
60 return;
61 }
62
63 if (freq_vec_[0] < 200) {
64 fit_fail_reason_ = "popularity: the most popular object has " +
65 to_string(freq_vec_[0]) + " requests ";
66 WARN("%s\n", fit_fail_reason_.c_str());
67 }
68
69 /* calculate Zipf alpha using linear regression */
70 vector<double> log_freq(obj_map.size());
71 vector<double> log_rank(obj_map.size());
72
73 int i = 0;
74 for_each(log_freq.begin(), log_freq.end(),
75 [&](double &item) { item = log(freq_vec_[i++]); });
76 i = 0;
77 for_each(log_rank.begin(), log_rank.end(), [&](double &item) {
78 ++i;
79 item = log(i);
80 });
81
82 /* TODO: a better linear regression with intercept and R2 */
83 slope_ = -PopularityUtils::slope(log_rank, log_freq);
84
85 has_run = true;
86}
87
88vector<uint32_t> freq_vec_{};
89double slope_, intercept_, r2_;

Callers

nothing calls this directly

Calls 6

to_stringFunction · 0.85
logFunction · 0.85
reserveMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected