def testSummaryStatsAccumulatorUpdateAccumulator(self): acc1 = utils.SummaryStatsAccumulator() acc2 = utils.SummaryStatsAccumulator() for i in range(2, 26, 2): acc1.UpdateOneValue(i) for i in range(26, 52, 2): acc2.UpdateOneValue(i) acc1.UpdateAccumulator(acc2) self.assertEqual(acc1.n, 25) self.assertAlmostEqual(acc1.mean, 26) self.assertAlmostEqual(acc1.M2, 5200) self.assertAlmostEqual(acc1.variance, 216.666666667) self.assertAlmostEqual(acc1.stddev, 14.719601444)
def testSummaryStatsAccumulatorUpdateSubsampleBigNumbers(self): acc1 = utils.SummaryStatsAccumulator() acc2 = utils.SummaryStatsAccumulator() for i in range(1000000002, 1000000026, 2): acc1.UpdateOneValue(i) for i in range(1000000026, 1000000052, 2): acc2.UpdateOneValue(i) acc1.UpdateSubsample(acc2.n, acc2.mean, acc2.M2) self.assertEqual(acc1.n, 25) self.assertAlmostEqual(acc1.mean, 1000000026) self.assertAlmostEqual(acc1.M2, 5200) self.assertAlmostEqual(acc1.variance, 216.666666667) self.assertAlmostEqual(acc1.stddev, 14.719601444) self.assertAlmostEqual(acc1.stderr, 2.9439203)
def testSummaryStatsAccumulatorUpdateSubsampleEmpty(self): acc = utils.SummaryStatsAccumulator() acc.UpdateSubsample(0, 0, 0) self.assertEqual(acc.n, 0) self.assertEqual(acc.mean, 0) self.assertEqual(acc.M2, 0)
def testSummaryStatsAccumulatorNeverUpdated(self): acc = utils.SummaryStatsAccumulator() self.assertEqual(acc.n, 0) self.assertEqual(acc.total, 0) self.assertEqual(acc.mean, 0) self.assertEqual(acc.M2, 0) self.assertTrue(math.isnan(acc.variance), msg="expected NaN") self.assertTrue(math.isnan(acc.stddev), msg="expected NaN") self.assertTrue(math.isnan(acc.stderr), msg="expected NaN")
def testSummaryStatsAccumulatorUpdateOneValueBigNumbers(self): acc = utils.SummaryStatsAccumulator() for i in range(1000000002, 1000000052, 2): acc.UpdateOneValue(i) self.assertEqual(acc.n, 25) self.assertAlmostEqual(acc.mean, 1000000026) self.assertAlmostEqual(acc.M2, 5200) self.assertAlmostEqual(acc.variance, 216.666666667) self.assertAlmostEqual(acc.stddev, 14.719601444) self.assertAlmostEqual(acc.stderr, 2.9439203)
def testSummaryStatsAccumulatorUpdateOneValue(self): acc = utils.SummaryStatsAccumulator() for i in range(2, 52, 2): acc.UpdateOneValue(i) self.assertEqual(acc.n, 25) self.assertEqual(acc.total, 650) self.assertAlmostEqual(acc.mean, 26) self.assertAlmostEqual(acc.M2, 5200) self.assertAlmostEqual(acc.variance, 216.666666667) self.assertAlmostEqual(acc.stddev, 14.719601444) self.assertAlmostEqual(acc.stderr, 2.9439203) self.assertAlmostEqual(acc.cv, 0.5661385)