PoseLib
PoseLib copied to clipboard
Error in Cauchy Loss Computation
Hello,
I noticed a potential error in the Cauchy Loss computation:
https://github.com/PoseLib/PoseLib/blob/b3691b791bcedccd5451621b2275a1df0d9dcdeb/PoseLib/robust/robust_loss.h#L111-L115
As I understand it the weight
function should calculate the derivative of the loss w.r.t. squared residual. However in that case the correct function should be:
double weight(double r2) const {
return std::max(std::numeric_limits<double>::min(), inv_sq_thr / (1.0 + r2 * inv_sq_thr));
}
Or alternatively, the problem could also be caused by an error in the loss
function.
I found this when comparing my own jacobian implementation for a custom problem against numerically estimated gradient. After the suggested fix the checks were passing.
Nice catch. Indeed it should be the derivative w.r.t. r^2. A uniform rescaling of the weights should not change the optimization. It could potentially affect the numerics, or in the future if we ever use different loss functions for different residuals. It's probably best to make it correct. Will you a make a PR for it?
I created PR #98 with the fix, but you are right that it does not actually affect performance.