Example usage for org.apache.commons.math3.fitting.leastsquares LeastSquaresFactory create

List of usage examples for org.apache.commons.math3.fitting.leastsquares LeastSquaresFactory create

Introduction

In this page you can find the example usage for org.apache.commons.math3.fitting.leastsquares LeastSquaresFactory create.

Prototype

public static LeastSquaresProblem create(final MultivariateJacobianFunction model, final RealVector observed,
        final RealVector start, final ConvergenceChecker<Evaluation> checker, final int maxEvaluations,
        final int maxIterations) 

Source Link

Document

Create a org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem from the given elements.

Usage

From source file:eu.crisis_economics.abm.markets.clearing.heterogeneous.LevenbergMarquardtClearingAlgorithm.java

@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);//w ww  .  j  a  va 2s .  c  o  m

    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;
}