Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_BASE_QUANTILE_ESTIMATOR_H_ | |
| 6 #define NET_BASE_QUANTILE_ESTIMATOR_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "net/base/net_export.h" | |
| 11 | |
| 12 namespace net { | |
| 13 | |
| 14 // This class estimates statistical quantiles (e.g. 10%l, 50%l) for | |
| 15 // integer distributions presented in stream form. These estimates adjust | |
| 16 // automatically when the stream distribution changes. | |
| 17 // TODO(rdsmith): Expand to floating point, when there's a use case for that | |
|
mmenke
2016/09/19 15:26:17
Expand what to floating point? The estimate, or t
Randy Smith (Not in Mondays)
2016/09/22 21:52:27
The estimate. Clarified the commetn.
| |
| 18 // that deserves the extra complexity and pitfalls of floating point | |
| 19 // arithmetic. | |
| 20 class NET_EXPORT QuantileEstimator { | |
| 21 public: | |
| 22 using RandomNumberCallback = base::Callback<int(void)>; | |
| 23 | |
| 24 static const int kMedianQuantile = 50; | |
| 25 | |
| 26 // |quantile| is a number between 0 and 100 indicating what quantile | |
| 27 // should be estimated (e.g. 50 would be a median estimate). | |
| 28 // |initial_estimate| is the value the class is seeded with; in other | |
| 29 // words, if AddSample() is never called, | |
| 30 // |CurrentEstimate() == initial_estimate|. | |
| 31 QuantileEstimator(int quantile, int initial_estimate); | |
|
mmenke
2016/09/19 15:26:17
I think this should technically be Percentile, not
Randy Smith (Not in Mondays)
2016/09/22 21:52:27
That sounds right to me. Ok, one large scale name
| |
| 32 | |
| 33 ~QuantileEstimator(); | |
| 34 | |
| 35 int current_estimate() const { return current_estimate_; } | |
| 36 void AddSample(int sample); | |
| 37 | |
| 38 // Specify a callback that will generate a "random" number | |
| 39 // in the range [0,99] on each call. Used so that tests can | |
| 40 // rely on reproducible behavior. | |
| 41 void SetRandomNumberGeneratorForTesting( | |
| 42 RandomNumberCallback generator_callback); | |
| 43 | |
| 44 private: | |
| 45 const int quantile_; | |
| 46 | |
| 47 bool sign_positive_; | |
| 48 int current_estimate_; | |
| 49 int current_step_; | |
| 50 | |
| 51 RandomNumberCallback generator_callback_; | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(QuantileEstimator); | |
| 54 }; | |
| 55 | |
| 56 } // namespace net | |
| 57 | |
| 58 #endif // NET_BASE_QUANTILE_ESTIMATOR_H_ | |
| OLD | NEW |