def cal_avg_distance(points, a, b, d, threshold_inlier):
    """
    return average distance of points to the line model.

    Parameter
    ---------
    points : array like
            [[x1,y1],[x2,y2],...]
    a : float
    b : float
    d : float
    thereshold_inlier :  float
            the threshold of discriminating whether the point is the inlier

    Return
    ------
    avg_dis : float
            average distance
    inlier_rate : float
            inliers rate
    """ 
    dis_sum = 0
    inlier_num = 0
    point_num = len(points)
    for point in points:
        dis = (a * point[0] + b * point[1] - d) ** 2
        dis_sum += dis 

        if dis < threshold_inlier:
            inlier_num += 1

    avg_dis = dis_sum / point_num
    inlier_rate = inlier_num / point_num
    return avg_dis, inlier_rate