Esempio n. 1
0
def test_outliers_line_msac():
    a, b, x, samples = line_data()

    sigma = 2.0
    y = a * x + b + np.random.normal(scale=sigma, size=x.shape[0])

    multiplier = 1.96

    ratio_outliers = 0.4
    outliers_max = 5.0
    add_outliers(ratio_outliers, x, multiplier * sigma,
                 multiplier * outliers_max)

    data = np.array([x, y]).transpose()

    params = pyrobust.RobustEstimatorParams()
    result = pyrobust.ransac_line(data, multiplier * sigma, params,
                                  pyrobust.RansacType.MSAC)

    inliers_count = (1 - ratio_outliers) * samples
    confidence = 0.95  # 1.96*MAD -> 95% rejecting inliers
    assert np.isclose(len(result.inliers_indices),
                      inliers_count,
                      rtol=(1 - confidence),
                      atol=5)
Esempio n. 2
0
def test_outliers_line_LMedS():
    a, b, x, samples = line_data()

    sigma = 2.0
    y = a * x + b + np.random.normal(scale=sigma, size=x.shape[0])

    multiplier = 1.96

    ratio_outliers = 0.4
    outliers_max = 5.0
    add_outliers(ratio_outliers, x, multiplier * sigma,
                 multiplier * outliers_max)

    data = np.array([x, y]).transpose()

    params = pyrobust.RobustEstimatorParams()

    # can't be used with LMedS as an over-estimated sigma will make it stop early
    params.use_iteration_reduction = False

    result = pyrobust.ransac_line(data, multiplier, params,
                                  pyrobust.RansacType.LMedS)

    inliers_count = (1 - ratio_outliers) * samples
    confidence = 0.95  # 1.96*MAD -> 95% rejecting inliers
    assert np.isclose(len(result.inliers_indices),
                      inliers_count,
                      rtol=(1 - confidence),
                      atol=8)
Esempio n. 3
0
def test_uniform_line_ransac():
    a, b, x, samples = line_data()

    scale = 2.0
    y = a * x + b + np.random.rand(x.shape[0]) * scale

    data = np.array([x, y]).transpose()

    params = pyrobust.RobustEstimatorParams()
    result = pyrobust.ransac_line(data, scale, params,
                                  pyrobust.RansacType.RANSAC)

    assert result.score == samples
    assert len(result.inliers_indices) == samples
Esempio n. 4
0
def test_normal_line_msac():
    a, b, x, samples = line_data()

    sigma = 2.0
    y = a * x + b + np.random.normal(scale=sigma, size=x.shape[0])

    multiplier = 1.96

    data = np.array([x, y]).transpose()

    params = pyrobust.RobustEstimatorParams()
    result = pyrobust.ransac_line(data, multiplier * sigma, params,
                                  pyrobust.RansacType.MSAC)

    confidence = 0.95  # 1.96*MAD -> 95% rejecting inliers
    assert np.isclose(len(result.inliers_indices),
                      samples,
                      rtol=(1 - confidence),
                      atol=7)
Esempio n. 5
0
def test_outliers_line_ransac():
    a, b, x, samples = line_data()

    scale = 2.0
    y = a * x + b + np.random.rand(x.shape[0]) * scale

    ratio_outliers = 0.4
    outliers_max = 5.0
    add_outliers(ratio_outliers, x, scale, outliers_max)

    data = np.array([x, y]).transpose()

    params = pyrobust.RobustEstimatorParams()
    result = pyrobust.ransac_line(data, scale, params,
                                  pyrobust.RansacType.RANSAC)

    inliers_count = (1 - ratio_outliers) * samples
    assert result.score == inliers_count
    assert len(result.inliers_indices) == inliers_count