Search code examples
javaprocessingapache-commons-math

No library found for org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer


I am importing Apache Commons Math and Lemmingapex Trilateration as external jar libraries in Processing. I followed this instruction from SO:

How to add external libraries in processing

The processing sketch seems to work fine but i am getting the following error printed to console every time i run the sketch.

No library found for org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer

This is the Processing PDE Sketch:

import org.apache.commons.math3.fitting.leastsquares.*;
import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum;
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.linear.RealVector;

import com.lemmingapex.trilateration.*;

void setup() {
  size(1024, 768);

  double[][] positions = new double[][] { { 8.0, 12.0 }, { 15.0, 40.0 }, { 40.0, 20.0 }, { 22, 40 } };
  double[] distances = new double[] { 10.06, 13.97, 23.32, 10.31 };

  NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(new TrilaterationFunction(positions, distances), new LevenbergMarquardtOptimizer());
  Optimum optimum = solver.solve();

  // the answer
  double[] centroid = optimum.getPoint().toArray();
  printArray(centroid);

  // error and geometry information; may throw SingularMatrixException depending the threshold argument provided
  RealVector standardDeviation = optimum.getSigma(0);
  RealMatrix covarianceMatrix = optimum.getCovariances(0);

  printArray(standardDeviation);
  printArray(covarianceMatrix);

  background(37);
  ellipse((float) centroid[0], (float) centroid[1], 20, 20);
}

void draw() {
}

Where am i going wrong? Any pointers?


Solution

  • I was able to make it work using the following imports.

    import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum;
    import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer;
    import com.lemmingapex.trilateration.NonLinearLeastSquaresSolver;
    import com.lemmingapex.trilateration.TrilaterationFunction;
    import com.lemmingapex.trilateration.*;
    

    Thanks Kevin. Hope this helps other.