当前位置: 首页>>代码示例>>Java>>正文


Java LevenbergMarquardtOptimizer类代码示例

本文整理汇总了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;
}
 
开发者ID:PrasannaNatarajan,项目名称:Interrobang,代码行数:11,代码来源:Trilateration.java

示例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());
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:22,代码来源:CameraCalibrationZhang.java

示例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;
}
 
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:30,代码来源:LevenbergMarquardtClearingAlgorithm.java

示例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());
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:36,代码来源:GaussianCurveFitter.java

示例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;
}
 
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:29,代码来源:PCPALMMolecules.java

示例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();
}
 
开发者ID:lemmingapex,项目名称:trilateration,代码行数:9,代码来源:TrilaterationTest.java

示例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();
}
 
开发者ID:neXenio,项目名称:BLE-Indoor-Positioning,代码行数:7,代码来源:Multilateration.java

示例8: CircleOptimizer

import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer; //导入依赖的package包/类
/**
 * Instantiates a new Circle optimizer.
 */
public CircleOptimizer() {
    this.optimizer = new LevenbergMarquardtOptimizer();
}
 
开发者ID:BPL-Gear,项目名称:bpl-gear,代码行数:7,代码来源:CircleOptimizer.java

示例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);

}
 
开发者ID:subpos,项目名称:subpos_android_api,代码行数:64,代码来源:NodeLocations.java

示例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;
}
 
开发者ID:aherbert,项目名称:GDSC,代码行数:65,代码来源:Cell_Outliner.java

示例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();
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:13,代码来源:AbstractCurveFitter.java


注:本文中的org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。