ceres中的loss函数实现探查,包括Huber,Cauchy,Tolerant图像实现及源码
各个损失函数的趋势图:
Ceres内嵌的loss functions原理:
以CauchyLoss方法为例,其头文件为:
// Inspired by the Cauchy distribution
// rho(s) = log(1 + s).
// At s = 0: rho = [0, 1, -1].
class CERES_EXPORT CauchyLoss : public LossFunction {
public:
explicit CauchyLoss(double a) : b_(a * a), c_(1 / b_) {}
void Evaluate(double, double*) const override;
//可以看出CauchyLoss()中的参数为尺度参数。
private:
// b = a^2.
const double b_;
// c = 1 / a^2.
const double c_;
};
具体实现为:
void CauchyLoss::Evaluate(double s, double rho[3]) const {
const double sum = 1.0 + s * c_;
const double inv = 1.0 / sum;
// 'sum' and 'inv' are always positive, assuming that 's' is.
rho[0] = b_ * log(sum);
rho[1] = std::max(std::numeric_limits<double>::min(), inv);
rho[2] = - c_ * (inv * inv);
}