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

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

Introduction

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

Prototype

public static MultivariateJacobianFunction model(final MultivariateVectorFunction value,
        final MultivariateMatrixFunction jacobian) 

Source Link

Document

Combine a MultivariateVectorFunction with a MultivariateMatrixFunction to produce a MultivariateJacobianFunction .

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 w w  .  j ava2  s.  c om*/

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