| 81 | { |
| 82 | } |
| 83 | void AddPoint(float value) { |
| 84 | //Weighted arithmetic mean calculation, where weight is value^3 |
| 85 | // Example: assume "worst" value is 0.5 "good" value is 0.01 and we want |
| 86 | // to get weighted arithmetic mean in range [(0.5 - eps), 0.5) so: |
| 87 | // ( N * 0.01 * 0.01^p + 0.5 * 0.5^p ) / ( N * 0.01^p + 0.5^p ) >= 0.5-eps |
| 88 | // where N = 10000 (expected active connection num) |
| 89 | // eps = 0.1 (accuracy) |
| 90 | // walid if p >= 3 |
| 91 | const float weight = value * value * value; |
| 92 | Sw += weight; |
| 93 | Swx += weight * value; |
| 94 | } |
| 95 | void Update() { |
| 96 | Result.store(Swx / Sw, std::memory_order_release); |
| 97 | Swx = 0.0f; |