lemmingapex / trilateration

Solves a formulation of n-D space trilateration problem using a nonlinear least squares optimizer
MIT License
398 stars 106 forks source link

Not issue, just question about accuracy #29

Closed kikothemaster closed 4 years ago

kikothemaster commented 4 years ago

Is it possible to get accuracy value from solver?

bleckers commented 4 years ago

You can use the .getSigma() function to obtain an error radius. Something like this should do roughly what you want (RealVector is from org.apache.commons.math3.linear):

NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(trilaterationFunction, new LevenbergMarquardtOptimizer());
Optimum optimum = solver.solve();

RealVector standardDeviation = optimum.getSigma(0);

double errorRadius = ((standardDeviation.getEntry(0) + standardDeviation.getEntry(1)) / 2); //This gets an average of the ellipsoidal radius

You can alternatively get the largest of the two distances:

if (standardDeviation.getEntry(1) > standardDeviation.getEntry(0))
{
   errorRadius = standardDeviation.getEntry(1);
} else {
   errorRadius = standardDeviation.getEntry(0);
}

These above only look at the X,Y values, not the Z value.