0

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?

werty37
  • 53
  • 11

2 Answers2

0

Did you see my comment on the answer you linked to?

The easiest way to use a library in Processing is to drag the library's .jar file into the Processing editor. Just do that for all of the .jar files you need. (You might have to delete the library directory you already created first.)

Shameless self-promotion: I wrote a tutorial on using libraries in Processing available here.

See also: https://stackoverflow.com/a/35674067/873165

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
  • Hi @Kevin I have dragged and dropped the Lemmingapex and Apache math3 library jar files. I can see Processing creates a code folder in the sketch folder and jar files are place there. Now i am having 2 error. The type LevenbergMarquardtOptimizer is ambiguous. No library found for org.apache.commons.math3.fitting.leastsquares.LeastSquareOptimizer Please let me know. – werty37 Jan 08 '18 at 17:06
  • @Werty37 If you have a follow-up question, please post it in its own question post. Please include an updated [mcve] as well as links to the documentation for the library you're using. – Kevin Workman Jan 08 '18 at 17:23
0

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.

werty37
  • 53
  • 11