def test_distance_of_0_0_from_flat_line_yintercept_is_zero(self): x = LineModel(0, 1, -3) test_point = Point(0, 0) distance_actual = x.compute_distance(test_point) distance_expected = 3 self.assertEqual(distance_actual, distance_expected) pass
def test_distance_of_1_0_from_slope_45degrees_yintercept_is_zero(self): x = LineModel(-1, 1, 0) test_point = Point(1, 0) distance_actual = x.compute_distance(test_point) distance_expected = 1 / math.sqrt(2) self.assertEqual(distance_actual, distance_expected) pass
def test_distance_of_origin_from_slope_45degrees_yintercept_is_zero(self): x = LineModel(-1, 1, 0) test_origin = Point(0, 0) distance_actual = x.compute_distance(test_origin) distance_expected = 0 self.assertEqual(distance_actual, distance_expected) pass
def compute_average_distance(self, model: LineModel, points: list) -> float: lst_distances = list() for p in points: distance = model.compute_distance(p) lst_distances.append(distance) mean = statistics.mean(lst_distances) return mean
def compute_mean_squared_distance(self, model: LineModel, points: list) -> float: lst_distances = list() for p in points: distance = model.compute_distance(p) lst_distances.append(distance**2) sum_of_squared_distances = sum(lst_distances) sqroot = sum_of_squared_distances**0.5 mean = sqroot / len(lst_distances) return mean
def get_inliers_from_model(self, model: LineModel, points_old_inliers: list) -> list: lst_inliers = list() for p in self.points: if ((p in points_old_inliers) == True): continue distance_from_model: float = model.compute_distance(p) if (distance_from_model > self.threshold_error): continue lst_inliers.append(p) return lst_inliers