def testEstimateNormal(self): """ This passes in a known set of data and ensures the estimateNormal function returns the expected results. """ # 100 samples drawn from mean=0.4, stdev = 0.5 samples = numpy.array([ 0.32259025, -0.44936321, -0.15784842, 0.72142628, 0.8794327, 0.06323451, -0.15336159, -0.02261703, 0.04806841, 0.47219226, 0.31102718, 0.57608799, 0.13621071, 0.92446815, 0.1870912, 0.46366935, -0.11359237, 0.66582357, 1.20613048, -0.17735134, 0.20709358, 0.74508479, 0.12450686, -0.15468728, 0.3982757, 0.87924349, 0.86104855, 0.23688469, -0.26018254, 0.10909429, 0.65627481, 0.39238532, 0.77150761, 0.47040352, 0.9676175, 0.42148897, 0.0967786, -0.0087355, 0.84427985, 1.46526018, 1.19214798, 0.16034816, 0.81105554, 0.39150407, 0.93609919, 0.13992161, 0.6494196, 0.83666217, 0.37845278, 0.0368279, -0.10201944, 0.41144746, 0.28341277, 0.36759426, 0.90439446, 0.05669459, -0.11220214, 0.34616676, 0.49898439, -0.23846184, 1.06400524, 0.72202135, -0.2169164, 1.136582, -0.69576865, 0.48603271, 0.72781008, -0.04749299, 0.15469311, 0.52942518, 0.24816816, 0.3483905, 0.7284215, 0.93774676, 0.07286373, 1.6831539, 0.3851082, 0.0637406, -0.92332861, -0.02066161, 0.93709862, 0.82114131, 0.98631562, 0.05601529, 0.72214694, 0.09667526, 0.3857222, 0.50313998, 0.40775344, -0.69624046, -0.4448494, 0.99403206, 0.51639049, 0.13951548, 0.23458214, 1.00712699, 0.40939048, -0.06436434, -0.02753677, -0.23017904 ]) params = an.estimateNormal(samples) self.assertWithinEpsilon(params["mean"], 0.3721) self.assertWithinEpsilon(params["variance"], 0.22294) self.assertWithinEpsilon(params["stdev"], 0.47216) self.assertEqual(params["name"], "normal")
def testEstimateNormal(self): """ This passes in a known set of data and ensures the estimateNormal function returns the expected results. """ # 100 samples drawn from mean=0.4, stdev = 0.5 samples = numpy.array( [0.32259025, -0.44936321, -0.15784842, 0.72142628, 0.8794327, 0.06323451, -0.15336159, -0.02261703, 0.04806841, 0.47219226, 0.31102718, 0.57608799, 0.13621071, 0.92446815, 0.1870912, 0.46366935, -0.11359237, 0.66582357, 1.20613048, -0.17735134, 0.20709358, 0.74508479, 0.12450686, -0.15468728, 0.3982757, 0.87924349, 0.86104855, 0.23688469, -0.26018254, 0.10909429, 0.65627481, 0.39238532, 0.77150761, 0.47040352, 0.9676175, 0.42148897, 0.0967786, -0.0087355, 0.84427985, 1.46526018, 1.19214798, 0.16034816, 0.81105554, 0.39150407, 0.93609919, 0.13992161, 0.6494196, 0.83666217, 0.37845278, 0.0368279, -0.10201944, 0.41144746, 0.28341277, 0.36759426, 0.90439446, 0.05669459, -0.11220214, 0.34616676, 0.49898439, -0.23846184, 1.06400524, 0.72202135, -0.2169164, 1.136582, -0.69576865, 0.48603271, 0.72781008, -0.04749299, 0.15469311, 0.52942518, 0.24816816, 0.3483905, 0.7284215, 0.93774676, 0.07286373, 1.6831539, 0.3851082, 0.0637406, -0.92332861, -0.02066161, 0.93709862, 0.82114131, 0.98631562, 0.05601529, 0.72214694, 0.09667526, 0.3857222, 0.50313998, 0.40775344, -0.69624046, -0.4448494, 0.99403206, 0.51639049, 0.13951548, 0.23458214, 1.00712699, 0.40939048, -0.06436434, -0.02753677, -0.23017904]) params = an.estimateNormal(samples) self.assertWithinEpsilon(params["mean"], 0.3721) self.assertWithinEpsilon(params["variance"], 0.22294) self.assertWithinEpsilon(params["stdev"], 0.47216) self.assertEqual(params["name"], "normal")
def testSampleDistribution(self): """ Test that sampleDistribution from a generated distribution returns roughly the same parameters. """ # 1000 samples drawn from mean=0.4, stdev = 0.1 p = {"mean": 0.5, "name": "normal", "stdev": math.sqrt(0.1), "variance": 0.1} samples = _sampleDistribution(p, 1000) # Ensure estimate is reasonable np = an.estimateNormal(samples) self.assertWithinEpsilon(p["mean"], np["mean"], 0.1) self.assertWithinEpsilon(p["variance"], np["variance"], 0.1) self.assertWithinEpsilon(p["stdev"], np["stdev"], 0.1) self.assertTrue(np["name"], "normal")
def testSampleDistribution(self): """ Test that sampleDistribution from a generated distribution returns roughly the same parameters. """ # 1000 samples drawn from mean=0.4, stdev = 0.1 p = {"mean": 0.5, "name": "normal", "stdev": math.sqrt(0.1), "variance": 0.1} samples = _sampleDistribution(p, 1000) # Ensure estimate is reasonable np = an.estimateNormal(samples) self.assertWithinEpsilon(p["mean"], np["mean"], 0.1) self.assertWithinEpsilon(p["variance"], np["variance"], 0.1) self.assertWithinEpsilon(p["stdev"], np["stdev"], 0.1) self.assertTrue(np["name"], "normal")