随机采样一致性(RANSAC)
和一般的最小二乘拟合的区别是:RANSAC可以在有大量噪声的情况下拟合出令人满意的效果。
算法步骤如下:
首先从输入的数据中随机选择一些点并计算用户给定模型的参数,对数据集中的所有点设置距离阈值,如果点到模型的距离在距离阈值的范围内,则将该点归为局内点,否则为局外点,然后统计所有局内点的个数,判断是否大于设定的阈值,如果是,则用内殿重新估计模型,作为模型输出,存储所有内点作为分割结果,如果不是,则与当前最大的内点个数对比,如果大于则取代当前最大局内点个数,并存储当前的模型系数,然后进行迭代计算,直到分割出用户满意的模型。
下面上伪码:
Given:
data – a set of observed data points
model – a model that can be fitted to data points
n – the minimum number of data values required to fit the model
k – the maximum number of iterations allowed in the algorithm
t – a threshold value for determining when a data point fits a model
d – the number of close data values required to assert that a model fits well to data
Return:
bestfit – model parameters which best fit the data (or nul if no good model is found)
iterations = 0
bestfit = nul
besterr = something really large
while iterations < k {
maybeinliers = n randomly selected values from data
maybemodel = model parameters fitted to maybeinliers
alsoinliers = empty set
for every point in data not in maybeinliers {
if point fits maybemodel with an error smaller than t
add point to alsoinliers
}
if the number of elements in alsoinliers is > d {
% this implies that we may have found a good model
% now test how good it is
bettermodel = model parameters fitted to all points in maybeinliers and alsoinliers
thiserr = a measure of how well model fits these points
if thiserr < besterr {
bestfit = bettermodel
besterr = thiserr
}
}
increment iterations
}
return bestfit
RANSAC的缺点是它计算参数的迭代次数没有上限