NCBI C++ ToolKit
heatmap_by_latency_and_size.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 // To make svn hooks happy
2 #if 0
3 #include <ncbi_pch.hpp>
4 #endif
5 
6 #include <iostream>
7 #include <cmath>
8 #include <vector>
9 #include <algorithm>
10 
11 struct SPoint
12 {
13  double latency;
14  size_t size;
15  double log_latency;
16  double log_size;
17  double heat = 0.0;
18  SPoint(double l, size_t s, double ll, double ls) : latency(l), size(s), log_latency(ll), log_size(ls) {}
19 };
20 
21 int main(int argc, char* argv[])
22 {
23  using namespace std;
24 
25  auto r = [](double v) { return log10(v * 10); };
26 
27  double latency;
28  size_t size;
29  vector<double> log_latency_tics, log_size_tics;
30  vector<SPoint> data;
31 
32  // Reading x and y (latency and size)
33  while (cin >> latency >> size) {
34  auto log_latency = r(latency);
35  auto log_size = r(size);
36  log_latency_tics.push_back(log_latency);
37  log_size_tics.push_back(log_size);
38  data.emplace_back(latency, size, log_latency, log_size);
39  }
40 
41  if (data.size() <= 1) return 0;
42 
43  sort(log_latency_tics.begin(), log_latency_tics.end());
44  sort(log_size_tics.begin(), log_size_tics.end());
45 
46  auto lmax = log_latency_tics.back() - log_latency_tics.front();
47  auto lmaxp2 = lmax * lmax;
48  auto smax = log_size_tics.back() - log_size_tics.front();
49  auto smaxp2 = smax * smax;
50  auto rmax = lmaxp2 + smaxp2;
51 
52  // Writing x, y and z (latency, size and 'heat')
53  for (size_t i = 0; i < data.size(); ++i) {
54  auto& p = data[i];
55 
56  for (size_t j = i + 1; j < data.size(); ++j) {
57  if (j != i) {
58  auto& o = data[j];
59  auto ld = p.log_latency - o.log_latency;
60  auto sd = p.log_size - o.log_size;
61  auto r = ld * ld / lmaxp2 + sd * sd / smaxp2;
62 
63  if (r < rmax / 10000) {
64  auto heat = 1 / (1 + r * r * r * r);
65  p.heat += heat;
66  o.heat += heat;
67  }
68  }
69  }
70 
71  cout << p.latency << ' ' << p.size << ' ' << p.heat << endl;
72  }
73 }
int main(int argc, char *argv[])
int i
constexpr auto sort(_Init &&init)
const struct ncbi::grid::netcache::search::fields::SIZE size
T log10(T x_)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
SPoint(double l, size_t s, double ll, double ls)
Modified on Sun Feb 25 03:03:21 2024 by modify_doxy.py rev. 669887