コード例 #1
0
    def test_get_bounds_from_histogram(self):
        """Get bounds from histogram finds upper and lower tails of distribution at specified confidence levels"""

        #Test a simple array

        test_hist = array([0.01, 0.98, 0.01])
        test_bin_edges = arange(3)
        obs_lower, obs_upper = get_bounds_from_histogram(test_hist,
                                                         test_bin_edges,
                                                         confidence=0.90)
        #Upper and lower bounds should be conservative, and therefore exclude the center
        exp_lower = 1
        exp_upper = 2
        self.assertFloatEqual(obs_lower, exp_lower)
        self.assertFloatEqual(obs_upper, exp_upper)

        # Confirm that summing the histogram over given indices
        # gives <= confidence % of the mass

        obs_sum_lower = sum(test_hist[:obs_lower])
        self.assertTrue(obs_sum_lower <= 0.05 * sum(test_hist))
        obs_sum_upper = sum(test_hist[obs_upper:])
        self.assertTrue(obs_sum_upper <= 0.05 * sum(test_hist))

        #Repeat for a more complex test case

        test_hist = array(
            [1.0, 2.0, 0.0, 5.0, 25.0, 2.0, 50.0, 10.0, 5.0, 1.0])
        test_bin_edges = array(arange(len(test_hist) + 1))
        obs_lower, obs_upper = get_bounds_from_histogram(test_hist,
                                                         test_bin_edges,
                                                         confidence=0.90)

        exp_lower = 3
        exp_upper = 9
        self.assertFloatEqual(obs_lower, exp_lower)
        self.assertFloatEqual(obs_upper, exp_upper)

        obs_sum_lower = sum(test_hist[:obs_lower])
        self.assertTrue(obs_sum_lower <= 0.05 * sum(test_hist))
        obs_sum_upper = sum(test_hist[obs_upper:])
        self.assertTrue(obs_sum_upper <= 0.05 * sum(test_hist))
コード例 #2
0
ファイル: test_predict_traits.py プロジェクト: adamrp/picrust
    def test_get_bounds_from_histogram(self):
        """Get bounds from histogram finds upper and lower tails of distribution at specified confidence levels"""
        
        #Test a simple array

        test_hist = array([0.01,0.98,0.01])
        test_bin_edges = arange(3)
        obs_lower,obs_upper = get_bounds_from_histogram(test_hist,test_bin_edges,confidence=0.90)
        #Upper and lower bounds should be conservative, and therefore exclude the center
        exp_lower = 1
        exp_upper = 2
        self.assertFloatEqual(obs_lower,exp_lower)
        self.assertFloatEqual(obs_upper,exp_upper)
        
        # Confirm that summing the histogram over given indices
        # gives <= confidence % of the mass

        obs_sum_lower = sum(test_hist[:obs_lower])
        self.assertTrue(obs_sum_lower <= 0.05*sum(test_hist))
        obs_sum_upper = sum(test_hist[obs_upper:])
        self.assertTrue(obs_sum_upper <= 0.05*sum(test_hist))

        #Repeat for a more complex test case

        test_hist =array([1.0,2.0,0.0,5.0,25.0,2.0,50.0,10.0,5.0,1.0])
        test_bin_edges = array(arange(len(test_hist)+1))
        obs_lower,obs_upper = get_bounds_from_histogram(test_hist,test_bin_edges,confidence=0.90)
        
        exp_lower = 3
        exp_upper = 9
        self.assertFloatEqual(obs_lower,exp_lower)
        self.assertFloatEqual(obs_upper,exp_upper)

        obs_sum_lower = sum(test_hist[:obs_lower])
        self.assertTrue(obs_sum_lower <= 0.05*sum(test_hist))
        obs_sum_upper = sum(test_hist[obs_upper:])
        self.assertTrue(obs_sum_upper <= 0.05*sum(test_hist))