Пример #1
0
 def test_blend_percentiles(self):
     """Test blend_percentile function works"""
     weights = np.array([0.38872692, 0.33041788, 0.2808552])
     percentiles = np.array(
         [0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0]
     )
     result = PercentileBlendingAggregator.blend_percentiles(
         PERCENTILE_VALUES, percentiles, weights
     )
     expected_result_array = np.array(
         [
             12.70237152,
             16.65161847,
             17.97408712,
             18.86356829,
             19.84089805,
             20.77406153,
             21.39078426,
             21.73778353,
             22.22440125,
             23.53863876,
             24.64542338,
         ]
     )
     self.assertArrayAlmostEqual(result, expected_result_array)
 def test_only_one_point_to_blend(self):
     """Test case where there is only one point in the coordinate we are
        blending over."""
     weights = np.array([1.0])
     percentiles = np.array([20.0, 50.0, 80.0])
     percentile_values = np.array([[5.0, 6.0, 7.0]])
     result = PercentileBlendingAggregator.blend_percentiles(
         percentile_values, percentiles, weights)
     expected_result = np.array([5.0, 6.0, 7.0])
     self.assertArrayAlmostEqual(result, expected_result)
 def test_three_percentiles_symmetric_case(self):
     """Test that when three percentiles are provided the correct values
        are returned, not a simple average"""
     weights = np.array([0.5, 0.5])
     percentiles = np.array([20.0, 50.0, 80.0])
     percentile_values = np.array([[5.0, 6.0, 7.0], [5.0, 6.5, 7.0]])
     result = PercentileBlendingAggregator.blend_percentiles(
         percentile_values, percentiles, weights)
     expected_result = np.array([5.0, 6.2, 7.0])
     self.assertArrayAlmostEqual(result, expected_result)
 def test_two_percentiles(self):
     """Test that when two percentiles are provided, the extreme values in
        the set of thresholds we are blending are returned"""
     weights = np.array([0.5, 0.5])
     percentiles = np.array([30., 60.])
     percentile_values = np.array([[5.0, 8.0], [6.0, 7.0]])
     result = PercentileBlendingAggregator.blend_percentiles(
         percentile_values, percentiles, weights)
     expected_result = np.array([5.0, 8.0])
     self.assertArrayAlmostEqual(result, expected_result)