private void CheckMinMaxAvg( string label, int level, double count, double abs_error, double min_value, double max_value, double avg_value, S2.Metric min_metric, S2.Metric max_metric, S2.Metric avg_metric) { // All metrics are minimums, maximums, or averages of differential // quantities, and therefore will not be exact for cells at any finite // level. The differential minimum is always a lower bound, and the maximum // is always an upper bound, but these minimums and maximums may not be // achieved for two different reasons. First, the cells at each level are // sampled and we may miss the most extreme examples. Second, the actual // metric for a cell is obtained by integrating the differential quantity, // which is notant across the cell. Therefore cells at low levels // (bigger cells) have smaller variations. // // The "tolerance" below is an attempt to model both of these effects. // At low levels, error is dominated by the variation of differential // quantities across the cells, while at high levels error is dominated by // the effects of random sampling. double tolerance = (max_metric.GetValue(level) - min_metric.GetValue(level)) / Math.Sqrt(Math.Min(count, 0.5 * (1 << level))); if (tolerance == 0) { tolerance = abs_error; } double min_error = min_value - min_metric.GetValue(level); double max_error = max_metric.GetValue(level) - max_value; double avg_error = Math.Abs(avg_metric.GetValue(level) - avg_value); _logger.WriteLine("%-10s (%6.0f samples, tolerance %8.3g) - min %9.4g (%9.3g : %9.3g) " + "max %9.4g (%9.3g : %9.3g), avg %9.4g (%9.3g : %9.3g)", label, count, tolerance, min_value, min_error / min_value, min_error / tolerance, max_value, max_error / max_value, max_error / tolerance, avg_value, avg_error / avg_value, avg_error / tolerance); Assert.True(min_metric.GetValue(level) <= min_value + abs_error); Assert.True(min_metric.GetValue(level) >= min_value - tolerance); Assert.True(max_metric.GetValue(level) <= max_value + tolerance); Assert.True(max_metric.GetValue(level) >= max_value - abs_error); Assert2.Near(avg_metric.GetValue(level), avg_value, 10 * tolerance); }
public MetricBundle(Metric min, Metric max, Metric avg) { min_ = min; max_ = max; avg_ = avg; }