本文整理汇总了Java中org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer类的典型用法代码示例。如果您正苦于以下问题:Java LevenbergMarquardtOptimizer类的具体用法?Java LevenbergMarquardtOptimizer怎么用?Java LevenbergMarquardtOptimizer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LevenbergMarquardtOptimizer类属于org.apache.commons.math3.fitting.leastsquares包,在下文中一共展示了LevenbergMarquardtOptimizer类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLocation
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer; //导入依赖的package包/类
public double[] getLocation(){
NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(new TrilaterationFunction(mPositions, mDistances), new LevenbergMarquardtOptimizer());
LeastSquaresOptimizer.Optimum optimum = solver.solve();
double[] centroid = optimum.getPoint().toArray();
Log.d("centroid",centroid.length+"");
Log.d("centroid",centroid[0]+" : "+centroid[1]+" : "+centroid[2]+"");
return centroid;
}
示例2: refine
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer; //导入依赖的package包/类
/**
* Perform Levenburg-Marquardt non-linear optimisation to get better
* estimates of the parameters
*/
private void refine()
{
final LevenbergMarquardtOptimizer lm = new LevenbergMarquardtOptimizer();
final RealVector start = buildInitialVector();
final RealVector observed = buildObservedVector();
final int maxEvaluations = 1000;
final int maxIterations = 1000;
final MultivariateVectorFunction value = new Value();
final MultivariateMatrixFunction jacobian = new Jacobian();
final MultivariateJacobianFunction model = LeastSquaresFactory.model(value, jacobian);
final Optimum result = lm.optimize(LeastSquaresFactory.create(model,
observed, start, null, maxEvaluations, maxIterations));
updateEstimates(result.getPoint());
}
示例3: applyToNetwork
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer; //导入依赖的package包/类
@Override
public double applyToNetwork(final MixedClearingNetwork network) {
Preconditions.checkNotNull(network);
final VectorCostFunction function = super.getVectorCostFunction(network);
final MultivariateJacobianFunction model =
LeastSquaresFactory.model(function, super.getJacobianMatrixFunction(network));
final RealVector
observed = new ArrayRealVector(super.calculateTarget(network)),
start = new ArrayRealVector(network.getNumberOfEdges());
for(int i = 0; i< network.getNumberOfEdges(); ++i)
start.setEntry(i, network.getEdges().get(i).getMaximumRateAdmissibleByBothParties());
start.set(1.0);
final ConvergenceChecker<LeastSquaresProblem.Evaluation> evaluationChecker =
LeastSquaresFactory.evaluationChecker(
new SimpleVectorValueChecker(relErrorTarget, absErrorTarget));
final LeastSquaresProblem problem =
LeastSquaresFactory.create(
model, observed, start, evaluationChecker, maximumEvaluations, maximumIterations);
final LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
final Optimum result = optimizer.optimize(problem);
final double residualCost = result.getRMS();
System.out.println("Network cleared: residual cost: " + residualCost + ".");
return residualCost;
}
示例4: getOptimizer
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected LevenbergMarquardtOptimizer getOptimizer(Collection<WeightedObservedPoint> observations) {
// Prepare least-squares problem.
final int len = observations.size();
final double[] target = new double[len];
final double[] weights = new double[len];
int i = 0;
for (WeightedObservedPoint obs : observations) {
target[i] = obs.getY();
weights[i] = obs.getWeight();
++i;
}
final AbstractCurveFitter.TheoreticalValuesFunction model
= new AbstractCurveFitter.TheoreticalValuesFunction(FUNCTION,
observations);
final double[] startPoint = initialGuess != null ?
initialGuess :
// Compute estimation.
new ParameterGuesser(observations).guess();
// Return a new optimizer set up to fit a Gaussian curve to the
// observed points.
return LevenbergMarquardtOptimizer.create()
.withMaxEvaluations(Integer.MAX_VALUE)
.withMaxIterations(maxIter)
.withStartPoint(startPoint)
.withTarget(target)
.withWeight(new DiagonalMatrix(weights))
.withModelAndJacobian(model.getModelFunction(),
model.getModelFunctionJacobian());
}
示例5: optimiseLeastSquares
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer; //导入依赖的package包/类
private double[] optimiseLeastSquares(float[] x, float[] y, double[] initialSolution)
{
// Least-squares optimisation using numerical gradients
final SkewNormalDifferentiableFunction function = new SkewNormalDifferentiableFunction(initialSolution);
function.addData(x, y);
LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
//@formatter:off
LeastSquaresProblem problem = new LeastSquaresBuilder()
.maxEvaluations(Integer.MAX_VALUE)
.maxIterations(3000)
.start(initialSolution)
.target(function.calculateTarget())
.weight(new DiagonalMatrix(function.calculateWeights()))
.model(function, new MultivariateMatrixFunction() {
public double[][] value(double[] point) throws IllegalArgumentException
{
return function.jacobian(point);
}} )
.build();
//@formatter:on
Optimum optimum = optimizer.optimize(problem);
double[] skewParameters = optimum.getPoint().toArray();
return skewParameters;
}
示例6: testCase
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer; //导入依赖的package包/类
private void testCase() {
TrilaterationFunction trilaterationFunction = new TrilaterationFunction(positions, distances);
LinearLeastSquaresSolver lSolver = new LinearLeastSquaresSolver(trilaterationFunction);
NonLinearLeastSquaresSolver nlSolver = new NonLinearLeastSquaresSolver(trilaterationFunction, new LevenbergMarquardtOptimizer());
linearCalculatedPosition = lSolver.solve();
nonLinearOptimum = nlSolver.solve();
}
示例7: findOptimum
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer; //导入依赖的package包/类
public static LeastSquaresOptimizer.Optimum findOptimum(double[][] positions, double[] distances) {
TrilaterationFunction trilaterationFunction = new TrilaterationFunction(positions, distances);
LeastSquaresOptimizer leastSquaresOptimizer = new LevenbergMarquardtOptimizer();
NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(trilaterationFunction, leastSquaresOptimizer);
return solver.solve();
}
示例8: CircleOptimizer
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer; //导入依赖的package包/类
/**
* Instantiates a new Circle optimizer.
*/
public CircleOptimizer() {
this.optimizer = new LevenbergMarquardtOptimizer();
}
示例9: trilaterate
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer; //导入依赖的package包/类
private Position trilaterate(ArrayLocations locations) {
//Trilateration nonlinear weighted least squares
//https://github.com/lemmingapex/Trilateration - MIT Licence
//http://commons.apache.org/proper/commons-math/download_math.cgi
double[][] positions = new double[locations.size()][3];
double[] distances = new double[locations.size()];
int i = 0;
while (i < locations.size()) {
//Map projection is treated as Mercator for calcs
//Convert lat,lng to meters and then back again
//Altitude is in cm
positions[i] = new double[]{WebMercator.latitudeToY(locations.get(i).lat),
WebMercator.longitudeToX(locations.get(i).lng),locations.get(i).altitude};
distances[i] = locations.get(i).distance;
i++;
}
TrilaterationFunction trilaterationFunction = new TrilaterationFunction(positions, distances);
NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(trilaterationFunction, new LevenbergMarquardtOptimizer());
LeastSquaresOptimizer.Optimum optimum = solver.solve();
double[] centroid = optimum.getPoint().toArray();
double errorRadius = 0;
boolean errorCalc = false;
// Error and geometry information
try {
//Create new array without the altitude. Including altitude causes a
//SingularMatrixException as it cannot invert the matrix.
double[][] err_positions = new double[locations.size()][2];
i = 0;
while (i < locations.size()) {
err_positions[i] = new double[]{positions[i][0],
positions[i][1]};
i++;
}
trilaterationFunction = new TrilaterationFunction(err_positions, distances);
solver = new NonLinearLeastSquaresSolver(trilaterationFunction, new LevenbergMarquardtOptimizer());
optimum = solver.solve();
RealVector standardDeviation = optimum.getSigma(0);
//RealMatrix covarianceMatrix = optimum.getCovariances(0);
errorRadius = ((standardDeviation.getEntry(0) + standardDeviation.getEntry(1)) / 2) * 100;
errorCalc = true;
} catch (Exception ex) {
errorRadius = 0;
errorCalc = false;
}
return new Position(WebMercator.yToLatitude(optimum.getPoint().toArray()[0]),
WebMercator.xToLongitude(centroid[1]),centroid[2],
errorRadius, errorCalc);
}
示例10: fitPolygonalCell
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer; //导入依赖的package包/类
/**
* Find an ellipse that optimises the fit to the polygon detected edges.
*
* @param roi
* @param params
* @param weightMap
* @param angle
* @return
*/
private double[] fitPolygonalCell(PolygonRoi roi, double[] params, FloatProcessor weightMap, FloatProcessor angle)
{
// Get an estimate of the starting parameters using the current polygon
double[] startPoint = params;
startPoint = estimateStartPoint(roi, weightMap.getWidth(), weightMap.getHeight());
int maxEval = 2000;
final DifferentiableEllipticalFitFunction func = new DifferentiableEllipticalFitFunction(roi, weightMap);
double relativeThreshold = 100 * Precision.EPSILON;
double absoluteThreshold = 100 * Precision.SAFE_MIN;
ConvergenceChecker<PointVectorValuePair> checker = new SimplePointChecker<PointVectorValuePair>(
relativeThreshold, absoluteThreshold);
double initialStepBoundFactor = 10;
double costRelativeTolerance = 1e-10;
double parRelativeTolerance = 1e-10;
double orthoTolerance = 1e-10;
double threshold = Precision.SAFE_MIN;
LevenbergMarquardtOptimizer optimiser = new LevenbergMarquardtOptimizer(initialStepBoundFactor,
costRelativeTolerance, parRelativeTolerance, orthoTolerance, threshold);
try
{
//@formatter:off
LeastSquaresProblem problem = new LeastSquaresBuilder()
.maxEvaluations(Integer.MAX_VALUE)
.maxIterations(maxEval)
.start(startPoint)
.target(func.calculateTarget())
.weight(new DiagonalMatrix(func.calculateWeights()))
.model(func, new MultivariateMatrixFunction() {
public double[][] value(double[] point) throws IllegalArgumentException
{
return func.jacobian(point);
}} )
.checkerPair(checker)
.build();
//@formatter:on
Optimum solution = optimiser.optimize(problem);
if (debug)
IJ.log(String.format("Eval = %d (Iter = %d), RMS = %f", solution.getEvaluations(),
solution.getIterations(), solution.getRMS()));
return solution.getPoint().toArray();
}
catch (Exception e)
{
IJ.log("Failed to find an elliptical solution, defaulting to polygon");
e.printStackTrace();
}
return null;
}
示例11: getOptimizer
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer; //导入依赖的package包/类
/**
* Creates an optimizer set up to fit the appropriate curve.
* <p>
* The default implementation uses a {@link LevenbergMarquardtOptimizer
* Levenberg-Marquardt} optimizer.
* </p>
* @return the optimizer to use for fitting the curve to the
* given {@code points}.
*/
protected LeastSquaresOptimizer getOptimizer() {
return new LevenbergMarquardtOptimizer();
}