Background:
I'm using non-linear least squares to solve indoor trilateration problem using BLE (bluetooth low energy) beacons. My starting point is this: https://nrr.mit.edu/sites/default/files/documents/Lab_11_Localization.html B part of the document.
(I've been using this JAVA lib for trilateration ( https://github.com/lemmingapex/Trilateration ) which works fine but needed to switch to c++ and I couldn't find a similar lib. So I experimented with google's ceres solver and eigen's levenberg-marquardt lib)
Problem/question:
$(x*,y*) = argmin \sum_{i=0}^n [ri^2-(x-xi)^2 - (y-yi)^2$
For these non-linear optimization libs, you have to define the nonsquared function.
Using this function for L-M algorithm: $\sqrt{(x-xi)^2 + (y-yi)^2} - ri$
c++ code:
fvec[i] = sqrt(pow(matrix(i, 0) - b[0], 2) + pow(matrix(i, 1) - b[1], 2)) - matrix(i, 2);
I get different results when using this: $1 - \frac{\sqrt{(x-xi)^2 + (y-yi)^2}}{ri}$
c++ code:
fvec[i] = 1 - sqrt(pow(matrix(i, 0) - b[0], 2) + pow(matrix(i, 1) - b[1], 2)) / matrix(i, 2);
The latter gives much better results. Shouldn't this function defined in different forms give the exact same result when using L-M algorithm to find minimum? What am I missing?
By the way for predefined problems (in the JAVA github lib tests) both give correct results, but the considerable difference happens when I'm testing with reallife data (many beacons).
Notes:
First defined function (fvec) returns RelativeReductionTooSmall and second (which gives good results) returns with RelativeErrorTooSmall. So I guess the stopping condition may not be set properly. But this shouldn't have an effect on my problem.
I'm new to optimization. I understand how gradient-descent works, but didn't have the time to dig deeper into L-M algorithm. I know it "balances"/switches between gradient descent and Newton-Gauss approach. But my gut says I'm missing something more basic.
I'm treating this function as an eqution (hence the above mentioned 2 forms): $0 = 1 - \frac{\sqrt{(x-xi)^2 + (y-yi)^2}}{ri}$ but maybe I can't treat the left side just as 0? Why not?