def _print_metric(prefix, key, unit, frac_digits=0): def format_frac(k, sign=False): format_string = '%' if sign: format_string += '+' format_string += '.%d' % frac_digits format_string += 'f' return (format_string % k) + unit ctrl_sample = ctrl_perfs[key] expt_sample = expt_perfs[key] ctrl_median = statistics.compute_median(ctrl_sample) expt_median = statistics.compute_median(expt_sample) diff_estimate_lower, diff_estimate_upper = ( bootstrap_estimation( ctrl_sample, expt_sample, statistics.compute_median, parsed_args.confidence_level)) if diff_estimate_upper < 0: significance = '[--]' elif diff_estimate_lower > 0: significance = '[++]' else: significance = '[not sgfnt.]' print ' %s: ctrl=%s, expt=%s, diffCI=(%s,%s) %s' % ( prefix, format_frac(ctrl_median), format_frac(expt_median), format_frac(diff_estimate_lower, sign=True), format_frac(diff_estimate_upper, sign=True), significance)
def _print_metric(prefix, key, unit, frac_digits=0): def format_frac(k, sign=False): format_string = '%' if sign: format_string += '+' format_string += '.%d' % frac_digits format_string += 'f' return (format_string % k) + unit ctrl_sample = ctrl_perfs[key] expt_sample = expt_perfs[key] ctrl_median = statistics.compute_median(ctrl_sample) expt_median = statistics.compute_median(expt_sample) diff_estimate_lower, diff_estimate_upper = (bootstrap_estimation( ctrl_sample, expt_sample, statistics.compute_median, parsed_args.confidence_level)) if diff_estimate_upper < 0: significance = '[--]' elif diff_estimate_lower > 0: significance = '[++]' else: significance = '[not sgfnt.]' print ' %s: ctrl=%s, expt=%s, diffCI=(%s,%s) %s' % ( prefix, format_frac(ctrl_median), format_frac(expt_median), format_frac(diff_estimate_lower, sign=True), format_frac(diff_estimate_upper, sign=True), significance)
def test_compute_percentiles(self): self.assertTrue( all(map(math.isnan, statistics.compute_percentiles([])))) self.assertEquals(statistics.compute_median([5, 8]), statistics.compute_percentiles([5, 8], [50])[0]) self.assertEquals(statistics.compute_median([2, 3, 7]), statistics.compute_percentiles([2, 3, 7], [50])[0]) # All expected values below agree with Google Docs. self.assertEquals((42, 42), statistics.compute_percentiles([42])) self.assertEquals((6.5, 7.7), statistics.compute_percentiles([5, 8])) self.assertEquals((3, 6.2), statistics.compute_percentiles([2, 3, 7])) self.assertEquals((5, 8.4), statistics.compute_percentiles([2, 3, 7, 9])) self.assertEquals((7, 63.6), statistics.compute_percentiles([2, 3, 7, 9, 100])) self.assertEquals((39.5, 43.4), statistics.compute_percentiles( [6, 7, 15, 36, 39, 40, 41, 42, 43, 47])) self.assertEquals((40.0, 47.0), statistics.compute_percentiles( [6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49])) self.assertEquals( (37.5, 40.5), statistics.compute_percentiles([7, 15, 36, 39, 40, 41])) self.assertEquals( (39, 42.2), statistics.compute_percentiles([6, 7, 15, 36, 39, 40, 41, 42, 43]))
def test_compute_percentiles(self): self.assertTrue(all(map(math.isnan, statistics.compute_percentiles([])))) self.assertEquals(statistics.compute_median([5, 8]), statistics.compute_percentiles([5, 8], [50])[0]) self.assertEquals(statistics.compute_median([2, 3, 7]), statistics.compute_percentiles([2, 3, 7], [50])[0]) # All expected values below agree with Google Docs. self.assertEquals((42, 42), statistics.compute_percentiles([42])) self.assertEquals((6.5, 7.7), statistics.compute_percentiles([5, 8])) self.assertEquals((3, 6.2), statistics.compute_percentiles([2, 3, 7])) self.assertEquals((5, 8.4), statistics.compute_percentiles([2, 3, 7, 9])) self.assertEquals((7, 63.6), statistics.compute_percentiles([2, 3, 7, 9, 100])) self.assertEquals((39.5, 43.4), statistics.compute_percentiles([6, 7, 15, 36, 39, 40, 41, 42, 43, 47])) self.assertEquals((40.0, 47.0), statistics.compute_percentiles([6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49])) self.assertEquals((37.5, 40.5), statistics.compute_percentiles([7, 15, 36, 39, 40, 41])) self.assertEquals((39, 42.2), statistics.compute_percentiles([6, 7, 15, 36, 39, 40, 41, 42, 43]))
def test_compute_median(self): self.assertTrue(math.isnan(statistics.compute_median([]))) self.assertEquals(42, statistics.compute_median([42])) self.assertEquals(6.5, statistics.compute_median([5, 8])) self.assertEquals(3, statistics.compute_median([2, 3, 7]))