Exemplo n.º 1
0
 def testVariance(self):
     data = [1, 2, 3]
     assert stats.mean(data) == 2
     self.assertEqual(stats.pvariance(data), 2/3)
     self.assertEqual(stats.variance(data), 1.0)
     self.assertEqual(stats.pstdev(data), math.sqrt(2/3))
     self.assertEqual(stats.stdev(data), 1.0)
Exemplo n.º 2
0
    def testManyDuplicates(self):
        from stats import pvariance
        # Start with 1000 normally distributed data points.
        data = [random.gauss(7.5, 5.5) for _ in range(1000)]
        expected = pvariance(data)
        # We expect a to be close to the exact result for the variance,
        # namely 5.5**2, but because it's random, it might not be.
        # Either way, it doesn't matter.

        # Duplicating the data points should keep the variance the same.
        for n in (3, 5, 10, 20, 30):
            d = data*n
            actual = pvariance(d)
            self.assertApproxEqual(actual, expected, tol=1e-12)

        # Now try again with a lot of duplicates.
        def big_data():
            for _ in range(500):
                for x in data:
                    yield x

        actual = pvariance(big_data())
        self.assertApproxEqual(actual, expected, tol=1e-12)
Exemplo n.º 3
0
 def testPVar(self):
     result = stats.pvariance(self.data)
     expected = self.expected["pvariance"]
     self.assertAlmostEqual(result, expected, places=self.places)
Exemplo n.º 4
0
 def testPVar(self):
     sx2 = stats.pvariance(self.xdata)
     sy2 = stats.pvariance(self.ydata)
     self.assertAlmostEqual(sx2, 11004687 / 1048576, places=self.places)
     self.assertAlmostEqual(sy2, 4647 / 4096, places=self.places)