KumarRobotics / msckf_vio

Robust Stereo Visual Inertial Odometry for Fast Autonomous Flight
Other
1.71k stars 599 forks source link

Huber robust cost #85

Closed moshanATucsd closed 3 years ago

moshanATucsd commented 5 years ago

Hi, for Huber robust cost in void Feature::jacobian, I am wondering how to get the following

  // Compute the weight based on the residual.
  double e = r.norm();
  if (e <= optimization_config.huber_epsilon)
    w = 1.0;
  else
    w = optimization_config.huber_epsilon / (2*e);

shouldn't this be

  double e = r.norm();
  if (e <= optimization_config.huber_epsilon)
    w = 1.0;
  else
    w = np.sqrt( optimization_config.huber_epsilon / (e));

reference TABLE 2 in An Evaluation of Robust Cost Functions for RGB Direct Mapping

ke-sun commented 5 years ago

Nice catch! I did make a poop here :smile:

Something more to double check before fixing this:

The Huber norm is e'=2de - d^2 for large e (e is the error, d is the epsilon in Huber norm). It's a bit different from wikipedia since we don't have 1/2 for the errors. Since d^2 does not involve the variables, the Huber norm here can be safely treated as e'=2de.

Because the code here (how we use the weight and error later): https://github.com/KumarRobotics/msckf_vio/blob/0fc32805fc7b1edb0b7db24dcd594b3464c8e2d9/include/msckf_vio/feature.hpp#L373-L375

the weight should be set as w=sqrt(2de)/e = sqrt(2d/e). What do you think?

moshanATucsd commented 5 years ago

Hi, thanks for the reply! I think you are right. I just found the Huber norm from dso

        float hw = fabsf(residual) < setting_huberTH ? 1 : setting_huberTH / fabsf(residual);
        energyLeft += w*w*hw *residual*residual*(2-hw);

        {
            if(hw < 1) hw = sqrtf(hw);

looks the same as what you said

JzHuai0108 commented 4 years ago

Do we need 2.0 in line? My derivation agrees with the suggestion of @moshanATucsd on Jul 24. Please also refer to the ceres solver for computing the Huber loss first order derivative which is used to rescale the residuals and Jacobians.

moshanATucsd commented 4 years ago

Hi @JzHuai0108, I think I agree with you, even if we do not have 1/2 for the errors, we still don't need the 2, eg refer to eq. 50 in paper. What do you think? @ke-sun