Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4518)

Unified Diff: base/metrics/field_trial.cc

Issue 23710041: Fix inconsistent FieldTrial group assignment due to float errors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/field_trial.h ('k') | base/metrics/field_trial_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/field_trial.cc
===================================================================
--- base/metrics/field_trial.cc (revision 222861)
+++ base/metrics/field_trial.cc (working copy)
@@ -38,10 +38,25 @@
return Time::FromLocalExploded(exploded);
}
+// Returns the boundary value for comparing against the FieldTrial's added
+// groups for a given |divisor| (total probability) and |entropy_value|.
+FieldTrial::Probability GetGroupBoundaryValue(
+ FieldTrial::Probability divisor,
+ double entropy_value) {
+ // Add a tiny epsilon value to get consistent results when converting floating
+ // points to int. Without it, boundary values have inconsistent results, e.g.:
jar (doing other things) 2013/09/16 21:54:40 Isn't what you really want is rounding, rather tha
Alexei Svitkine (slow) 2013/09/16 22:30:46 I don't think so, let me see if you agree. Here's
jar (doing other things) 2013/09/18 01:38:24 I think rounding is incorrect (I should have looke
Alexei Svitkine (slow) 2013/09/18 16:39:53 I agree that this is a potential issue. I think it
+ //
+ // static_cast<FieldTrial::Probability>(100 * 0.56) == 56
+ // static_cast<FieldTrial::Probability>(100 * 0.57) == 56
+ // static_cast<FieldTrial::Probability>(100 * 0.58) == 57
+ // static_cast<FieldTrial::Probability>(100 * 0.59) == 59
+ const double kEpsilon = 1e-8;
+ return static_cast<FieldTrial::Probability>(divisor * entropy_value +
+ kEpsilon);
+}
+
} // namespace
-static const char kHistogramFieldTrialSeparator('_');
-
// statics
const int FieldTrial::kNotFinalized = -1;
const int FieldTrial::kDefaultGroupNumber = 0;
@@ -60,7 +75,7 @@
: trial_name_(trial_name),
divisor_(total_probability),
default_group_name_(default_group_name),
- random_(static_cast<Probability>(divisor_ * entropy_value)),
+ random_(GetGroupBoundaryValue(total_probability, entropy_value)),
accumulated_group_probability_(0),
next_group_number_(kDefaultGroupNumber + 1),
group_(kNotFinalized),
« no previous file with comments | « base/metrics/field_trial.h ('k') | base/metrics/field_trial_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698