org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem Java Examples

The following examples show how to use org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GaussianCurveFitter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected LeastSquaresProblem getProblem(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 least squares problem set up to fit a Gaussian curve to the
    // observed points.
    return new LeastSquaresBuilder().
            maxEvaluations(Integer.MAX_VALUE).
            maxIterations(maxIter).
            start(startPoint).
            target(target).
            weight(new DiagonalMatrix(weights)).
            model(model.getModelFunction(), model.getModelFunctionJacobian()).
            build();

}
 
Example #2
Source File: SimpleCurveFitter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected LeastSquaresProblem getProblem(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 count = 0;
    for (WeightedObservedPoint obs : observations) {
        target[count]  = obs.getY();
        weights[count] = obs.getWeight();
        ++count;
    }

    final AbstractCurveFitter.TheoreticalValuesFunction model
        = new AbstractCurveFitter.TheoreticalValuesFunction(function,
                                                            observations);

    // Create an optimizer for fitting the curve to the observed points.
    return new LeastSquaresBuilder().
            maxEvaluations(Integer.MAX_VALUE).
            maxIterations(maxIter).
            start(initialGuess).
            target(target).
            weight(new DiagonalMatrix(weights)).
            model(model.getModelFunction(), model.getModelFunctionJacobian()).
            build();
}
 
Example #3
Source File: HarmonicCurveFitter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected LeastSquaresProblem getProblem(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 new LeastSquaresBuilder().
            maxEvaluations(Integer.MAX_VALUE).
            maxIterations(maxIter).
            start(startPoint).
            target(target).
            weight(new DiagonalMatrix(weights)).
            model(model.getModelFunction(), model.getModelFunctionJacobian()).
            build();

}
 
Example #4
Source File: PolynomialCurveFitter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected LeastSquaresProblem getProblem(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);

    if (initialGuess == null) {
        throw new MathInternalError();
    }

    // Return a new least squares problem set up to fit a polynomial curve to the
    // observed points.
    return new LeastSquaresBuilder().
            maxEvaluations(Integer.MAX_VALUE).
            maxIterations(maxIter).
            start(initialGuess).
            target(target).
            weight(new DiagonalMatrix(weights)).
            model(model.getModelFunction(), model.getModelFunctionJacobian()).
            build();

}
 
Example #5
Source File: GaussianCurveFitter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected LeastSquaresProblem getProblem(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 least squares problem set up to fit a Gaussian curve to the
    // observed points.
    return new LeastSquaresBuilder().
            maxEvaluations(Integer.MAX_VALUE).
            maxIterations(maxIter).
            start(startPoint).
            target(target).
            weight(new DiagonalMatrix(weights)).
            model(model.getModelFunction(), model.getModelFunctionJacobian()).
            build();

}
 
Example #6
Source File: SimpleCurveFitter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected LeastSquaresProblem getProblem(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 count = 0;
    for (WeightedObservedPoint obs : observations) {
        target[count]  = obs.getY();
        weights[count] = obs.getWeight();
        ++count;
    }

    final AbstractCurveFitter.TheoreticalValuesFunction model
        = new AbstractCurveFitter.TheoreticalValuesFunction(function,
                                                            observations);

    // Create an optimizer for fitting the curve to the observed points.
    return new LeastSquaresBuilder().
            maxEvaluations(Integer.MAX_VALUE).
            maxIterations(maxIter).
            start(initialGuess).
            target(target).
            weight(new DiagonalMatrix(weights)).
            model(model.getModelFunction(), model.getModelFunctionJacobian()).
            build();
}
 
Example #7
Source File: HarmonicCurveFitter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected LeastSquaresProblem getProblem(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 new LeastSquaresBuilder().
            maxEvaluations(Integer.MAX_VALUE).
            maxIterations(maxIter).
            start(startPoint).
            target(target).
            weight(new DiagonalMatrix(weights)).
            model(model.getModelFunction(), model.getModelFunctionJacobian()).
            build();

}
 
Example #8
Source File: NonLinearLeastSquaresSolver.java    From trilateration with MIT License 5 votes vote down vote up
public Optimum solve(double[] target, double[] weights, double[] initialPoint, boolean debugInfo) {
	if (debugInfo) {
		System.out.println("Max Number of Iterations : " + MAXNUMBEROFITERATIONS);
	}

	LeastSquaresProblem leastSquaresProblem = LeastSquaresFactory.create(
			// function to be optimized
			function,
			// target values at optimal point in least square equation
			// (x0+xi)^2 + (y0+yi)^2 + ri^2 = target[i]
			new ArrayRealVector(target, false), new ArrayRealVector(initialPoint, false), new DiagonalMatrix(weights), null, MAXNUMBEROFITERATIONS, MAXNUMBEROFITERATIONS);

	return leastSquaresOptimizer.optimize(leastSquaresProblem);
}
 
Example #9
Source File: PolynomialCurveFitter.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
protected LeastSquaresProblem getProblem(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);

    if (initialGuess == null) {
        throw new MathInternalError();
    }

    // Return a new least squares problem set up to fit a polynomial curve to the
    // observed points.
    return new LeastSquaresBuilder().
            maxEvaluations(Integer.MAX_VALUE).
            maxIterations(maxIter).
            start(initialGuess).
            target(target).
            weight(new DiagonalMatrix(weights)).
            model(model.getModelFunction(), model.getModelFunctionJacobian()).
            build();

}
 
Example #10
Source File: AbstractCurveFitter.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Creates a least squares problem corresponding to the appropriate curve.
 *
 * @param points Sample points.
 * @return the least squares problem to use for fitting the curve to the
 * given {@code points}.
 */
protected abstract LeastSquaresProblem getProblem(Collection<WeightedObservedPoint> points);
 
Example #11
Source File: AbstractCurveFitter.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Creates a least squares problem corresponding to the appropriate curve.
 *
 * @param points Sample points.
 * @return the least squares problem to use for fitting the curve to the
 * given {@code points}.
 */
protected abstract LeastSquaresProblem getProblem(Collection<WeightedObservedPoint> points);