xref: /aosp_15_r20/external/cronet/components/metrics/metrics_data_validation.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2021 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker #ifndef COMPONENTS_METRICS_METRICS_DATA_VALIDATION_H_
6*6777b538SAndroid Build Coastguard Worker #define COMPONENTS_METRICS_METRICS_DATA_VALIDATION_H_
7*6777b538SAndroid Build Coastguard Worker 
8*6777b538SAndroid Build Coastguard Worker #include "base/feature_list.h"
9*6777b538SAndroid Build Coastguard Worker #include "base/metrics/field_trial_params.h"
10*6777b538SAndroid Build Coastguard Worker #include "base/time/time.h"
11*6777b538SAndroid Build Coastguard Worker 
12*6777b538SAndroid Build Coastguard Worker // Features and functions in this file are necessary to set up artificial A / B
13*6777b538SAndroid Build Coastguard Worker // experiments that help us better assess the accuracy and power of our field
14*6777b538SAndroid Build Coastguard Worker // trial data. All code in this file should not have any impact on client's
15*6777b538SAndroid Build Coastguard Worker // experience.
16*6777b538SAndroid Build Coastguard Worker namespace metrics {
17*6777b538SAndroid Build Coastguard Worker 
18*6777b538SAndroid Build Coastguard Worker // Only used for testing.
19*6777b538SAndroid Build Coastguard Worker namespace internal {
20*6777b538SAndroid Build Coastguard Worker BASE_DECLARE_FEATURE(kPseudoMetricsEffectFeature);
21*6777b538SAndroid Build Coastguard Worker }  // namespace internal
22*6777b538SAndroid Build Coastguard Worker 
23*6777b538SAndroid Build Coastguard Worker // Used to assess the reliability of field trial data by sending artificial
24*6777b538SAndroid Build Coastguard Worker // non-uniform data drawn from a log normal distribution.
25*6777b538SAndroid Build Coastguard Worker BASE_DECLARE_FEATURE(kNonUniformityValidationFeature);
26*6777b538SAndroid Build Coastguard Worker 
27*6777b538SAndroid Build Coastguard Worker // The parameters for the log normal distribution. They refer to the default
28*6777b538SAndroid Build Coastguard Worker // mean, the delta that would be applied to the default mean (the actual mean
29*6777b538SAndroid Build Coastguard Worker // equals mean + log(1 + delta)) and the standard deviation of the distribution
30*6777b538SAndroid Build Coastguard Worker // that's being generated. These parameters are carefully calculated so that
31*6777b538SAndroid Build Coastguard Worker // ~0.01% of data drawn from the distribution would fall in the underflow bucket
32*6777b538SAndroid Build Coastguard Worker // and ~0.01% of data in the overflow bucket. And they also leave us enough
33*6777b538SAndroid Build Coastguard Worker // wiggle room to shift mean using delta in experiments without losing precision
34*6777b538SAndroid Build Coastguard Worker // badly because of data in the overflow bucket.
35*6777b538SAndroid Build Coastguard Worker //
36*6777b538SAndroid Build Coastguard Worker // The way we get these numbers are based on the following calculation:
37*6777b538SAndroid Build Coastguard Worker // u := the lower threshold for the overflow bucket (in this case, 10000).
38*6777b538SAndroid Build Coastguard Worker // l := the upper threshold for the smallest bucket (in this case, 1).
39*6777b538SAndroid Build Coastguard Worker // p := the probability that an observation will fall in the highest bucket (in
40*6777b538SAndroid Build Coastguard Worker //   this case, 0.01%) and also the probability that an observation will fall in
41*6777b538SAndroid Build Coastguard Worker //   the lowest bucket.
42*6777b538SAndroid Build Coastguard Worker //
43*6777b538SAndroid Build Coastguard Worker // mean = (log(u) + log(l)) / 2
44*6777b538SAndroid Build Coastguard Worker // sd = (log(u) - log(l)) / (2 * qnorm(1-p))
45*6777b538SAndroid Build Coastguard Worker //
46*6777b538SAndroid Build Coastguard Worker // At this point, experiments should only control the delta but not mean and
47*6777b538SAndroid Build Coastguard Worker // stdDev. Putting them in feature params so that we can configure them from the
48*6777b538SAndroid Build Coastguard Worker // server side if we want.
49*6777b538SAndroid Build Coastguard Worker extern const base::FeatureParam<double> kLogNormalMean;
50*6777b538SAndroid Build Coastguard Worker extern const base::FeatureParam<double> kLogNormalDelta;
51*6777b538SAndroid Build Coastguard Worker extern const base::FeatureParam<double> kLogNormalStdDev;
52*6777b538SAndroid Build Coastguard Worker 
53*6777b538SAndroid Build Coastguard Worker // In order to assess if we're able to accurately detect a statistically
54*6777b538SAndroid Build Coastguard Worker // significant difference in our field trial data, we set up pseudo metrics for
55*6777b538SAndroid Build Coastguard Worker // some of our key metrics. Values of these pseudo metrics are the linear
56*6777b538SAndroid Build Coastguard Worker // transformation (ax + b) of real values (x). The multiplicative factor (a) and
57*6777b538SAndroid Build Coastguard Worker // additive factor (b) are controlled by field trial experiments.
58*6777b538SAndroid Build Coastguard Worker //
59*6777b538SAndroid Build Coastguard Worker // Returns the sample value for a pseudo metric given the |sample| from the real
60*6777b538SAndroid Build Coastguard Worker // metric and the assigned field trial group. The input type is double because
61*6777b538SAndroid Build Coastguard Worker // we don't want to lose precision before applying transformation.
62*6777b538SAndroid Build Coastguard Worker double GetPseudoMetricsSample(double sample);
63*6777b538SAndroid Build Coastguard Worker 
64*6777b538SAndroid Build Coastguard Worker // Returns the TimeDelta for a pseudo metric given the |sample| from the real
65*6777b538SAndroid Build Coastguard Worker // metric and the assigned field trial group. The unit of the additive factor
66*6777b538SAndroid Build Coastguard Worker // (b) is milliseconds.
67*6777b538SAndroid Build Coastguard Worker base::TimeDelta GetPseudoMetricsSample(base::TimeDelta sample);
68*6777b538SAndroid Build Coastguard Worker 
69*6777b538SAndroid Build Coastguard Worker }  // namespace metrics
70*6777b538SAndroid Build Coastguard Worker 
71*6777b538SAndroid Build Coastguard Worker #endif  // COMPONENTS_METRICS_METRICS_DATA_VALIDATION_H_
72