Exemplo n.º 1
0
 def __init__(self,
              outlier: Type[OutLier] = RemoveOutlierByDistance(),
              use_remove_outliers: bool = False):
     """ init the class"""
     self._use_remove_outliers = use_remove_outliers
     self._outlier = outlier
     self._fit_data = FitData()
Exemplo n.º 2
0
 def test_calc_fit_parab(self):
     outlier_obj = RemoveOutlierByDistance()
     obj = PolynomFit(outlier=outlier_obj, remove_outliers=False, degree=2)
     obj._fit_data.x = np.array([-2, -1, 0, 1, 2])
     obj._fit_data.y = np.array([4, 1, 0, 1, 4])
     obj.fit(obj._fit_data.x, obj._fit_data.y)
     expected_model = {"coefficients": [1, 0, 0]}
     self.assertEqual(obj.get_fit_data().model, expected_model)
Exemplo n.º 3
0
 def test_calc_eval_parab_sad(self):
     outlier_obj = RemoveOutlierByDistance()
     obj = PolynomFit(outlier=outlier_obj, remove_outliers=False, degree=2)
     obj._fit_data.x = np.array([-2, -1, 0, 1, 2])
     obj._fit_data.y = np.array([-4, -1, 0, -1, -4])
     obj._calc_fit()
     obj._calc_eval()
     self.assertEqual(obj.get_fit_data().y_fit.any(), obj.get_fit_data().y.any())
Exemplo n.º 4
0
 def test_calc_fit_linear(self):
     outlier_obj = RemoveOutlierByDistance()
     obj = PolynomFit(outlier=outlier_obj, remove_outliers=False, degree=1)
     obj._fit_data.x = np.array([0, 1, 2, 3])
     obj._fit_data.y = np.array([1, 1, 0, 1])
     obj._calc_fit()
     expected_model = {"coefficients": [-0.1, 0.9]}
     self.assertEqual(obj.get_fit_data().model, expected_model)
Exemplo n.º 5
0
 def test_empty(self):
     outlier_obj = RemoveOutlierByDistance()
     self.assertEqual([outlier_obj.max_error, outlier_obj.min_points],
                      [1, 10])
Exemplo n.º 6
0
 def test_find_outliers_min_points(self):
     outlier_obj = RemoveOutlierByDistance(min_points=3)
     error_vec = np.array([0, 1, 0, 0, 3])
     indexes = outlier_obj.find_outliers(error_vec)
     self.assertEqual(indexes, [4])
Exemplo n.º 7
0
 def test_find_outliers_max_error(self):
     outlier_obj = RemoveOutlierByDistance(max_error=1)
     error_vec = np.array([0, 1, 0, 0, 3, 1, 2, 1, 2, 0, 0, 1, 2, 1])
     indexes = outlier_obj.find_outliers(error_vec)
     self.assertEqual(indexes, [4])
Exemplo n.º 8
0
 def test_find_outliers_picks_first_if_tie(self):
     outlier_obj = RemoveOutlierByDistance()
     error_vec = np.array([0, 1, 0, 0, 3, 1, 2, 1, 2, 0, 0, 1, 2, 1, 3])
     indexes = outlier_obj.find_outliers(error_vec)
     self.assertEqual(indexes, [4])
Exemplo n.º 9
0
 def test_find_outliers_max_error_exceeds_vector(self):
     outlier_obj = RemoveOutlierByDistance(min_points=2, max_error=4)
     error_vec = np.array([0, 1, 0, 0, 3, 1, 2, 1, 2, 0, 0, 1, 2, 1])
     indexes = outlier_obj.find_outliers(error_vec)
     self.assertEqual(indexes, [])
Exemplo n.º 10
0
 def __init__(self, outlier: OutLier=RemoveOutlierByDistance(), remove_outliers: bool =False, degree: int =2):
     self._fit_data = FitData()
     self._outlier = outlier
     self._use_remove_outliers = remove_outliers
     self.degree = degree