mapillary / OpenSfM

Open source Structure-from-Motion pipeline
https://www.opensfm.org/
BSD 2-Clause "Simplified" License
3.3k stars 848 forks source link

What is the rationale behind using logarithmic scale within error terms in BA? #855

Open melhashash opened 2 years ago

melhashash commented 2 years ago

Hello,

I noticed on a few occasions (listed below), a logarithmic scale is used instead of linear. What is the rationale behind this and is it found to be more stable than the linear one?

Also, when these priors/error terms are jointly minimized with reprojection errors, how do you make sure they are not dominated by reprojection errors? For instance, thousands of observations for reprojection errors, with one prior for focal length, or even hundreds for camera poses.

https://github.com/mapillary/OpenSfM/blob/343d1c349a008507f3b7e4be84e31e74c52f92f5/opensfm/src/bundle/error/parameters_errors.h#L7

https://github.com/mapillary/OpenSfM/blob/343d1c349a008507f3b7e4be84e31e74c52f92f5/opensfm/src/bundle/error/parameters_errors.h#L18

https://github.com/mapillary/OpenSfM/blob/ae250d3ebcf7b0a9d589daee8ada3aa68941d5e2/opensfm/src/bundle/error/prior_error.h#L82

YanNoun commented 2 years ago

Hi @melhashash ,

Indeed, you're right : we don't have global balance weighting factors between the different terms, as we don't want to - theoretically - bias the estimation toward some error term. But practically you're also right : projection terms might dominate and drive some terminating criteria of the bundle adjuster.

The StdDeviationConstraint isn't used as it is for now. When used, it is used for optimized the variance of a given error term (here, for GPS estimating GPS variance), when you formulate bundle adjustment as a MAP estimation (hence why a log appears).

The ParameterBarrier uses log for log-barrier-like constraint, i,.e. constraining parameters to stay in some range (more efficient than simple box-cut + line-search in the optimizer itself).

Finally, the log for prior on camera parameter is because we might want more sensitivity on some parameters, such as focal.

Let me know if that answers your questions,

Yann

melhashash commented 2 years ago

Hi @YanNoun,

Thanks for your reply.

I see your point regarding using the log to formulate as a MAP estimation and to provide a soft constraint instead of using SetParameterLowerBound and SetParameterUpperBound within Ceres, but isn't it mathematically equivalent to just using ScaleType::LINEAR (define error through subtraction) or is the logarithmic scale found to be better?