import math


def calculate_ransac_iterations(min_points_per_sample, outlier_rate, desired_success_probability):
    """Estimates how many RANSAC iterations you should run.

    Args:
        min_points_per_sample: Minimum number of points to build a model hypothesis.
        outlier_rate: Float, 0-1, how often outliers are expected.
        desired_success_probability: Float, 0-1 exclusive, desired certainty that the
            RANSAC run will find the correct model. Higher certainty requires more iterations.

    Returns:
        Number of iterations.
    """
    if not 0 < desired_success_probability < 1:
        raise ValueError('desired_success_probability should fall between 0 and 1, exclusive.')
    if not 0 <= outlier_rate <= 1:
        raise ValueError('outlier_rate should fall between 0 and 1.')
    if min_points_per_sample <= 0:
        raise ValueError('min_points_per_sample must be a positive integer.')
    assert 0 < desired_success_probability < 1
    return math.ceil(math.log(1 - desired_success_probability) /
                     math.log((1 - (1 - outlier_rate) ** min_points_per_sample)))