Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#UNABLE_TO_SOLVE_SINGULAR_PROBLEM

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#UNABLE_TO_SOLVE_SINGULAR_PROBLEM . 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: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected RealVector solve(final RealMatrix jacobian,
                           final RealVector residuals) {
    try {
        final Pair<RealMatrix, RealVector> normalEquation =
                computeNormalMatrix(jacobian, residuals);
        final RealMatrix normal = normalEquation.getFirst();
        final RealVector jTr = normalEquation.getSecond();
        return new CholeskyDecomposition(
                normal, SINGULARITY_THRESHOLD, SINGULARITY_THRESHOLD)
                .getSolver()
                .solve(jTr);
    } catch (NonPositiveDefiniteMatrixException e) {
        throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, e);
    }
}
 
Example 2
Source File: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected RealVector solve(final RealMatrix jacobian,
                           final RealVector residuals) {
    try {
        final Pair<RealMatrix, RealVector> normalEquation =
                computeNormalMatrix(jacobian, residuals);
        final RealMatrix normal = normalEquation.getFirst();
        final RealVector jTr = normalEquation.getSecond();
        return new CholeskyDecomposition(
                normal, SINGULARITY_THRESHOLD, SINGULARITY_THRESHOLD)
                .getSolver()
                .solve(jTr);
    } catch (NonPositiveDefiniteMatrixException e) {
        throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, e);
    }
}
 
Example 3
Source File: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public PointVectorValuePair doOptimize() {
    final ConvergenceChecker<PointVectorValuePair> checker
        = getConvergenceChecker();

    // Computation will be useless without a checker (see "for-loop").
    if (checker == null) {
        throw new NullArgumentException();
    }

    final double[] targetValues = getTarget();
    final int nR = targetValues.length; // Number of observed data.

    final RealMatrix weightMatrix = getWeight();
    // Diagonal of the weight matrix.
    final double[] residualsWeights = new double[nR];
    for (int i = 0; i < nR; i++) {
        residualsWeights[i] = weightMatrix.getEntry(i, i);
    }

    final double[] currentPoint = getStartPoint();
    final int nC = currentPoint.length;

    // iterate until convergence is reached
    PointVectorValuePair current = null;
    int iter = 0;
    for (boolean converged = false; !converged;) {
        ++iter;

        // evaluate the objective function and its jacobian
        PointVectorValuePair previous = current;
        // Value of the objective function at "currentPoint".
        final double[] currentObjective = computeObjectiveValue(currentPoint);
        final double[] currentResiduals = computeResiduals(currentObjective);
        final RealMatrix weightedJacobian = computeWeightedJacobian(currentPoint);
        current = new PointVectorValuePair(currentPoint, currentObjective);

        // build the linear problem
        final double[]   b = new double[nC];
        final double[][] a = new double[nC][nC];
        for (int i = 0; i < nR; ++i) {

            final double[] grad   = weightedJacobian.getRow(i);
            final double weight   = residualsWeights[i];
            final double residual = currentResiduals[i];

            // compute the normal equation
            final double wr = weight * residual;
            for (int j = 0; j < nC; ++j) {
                b[j] += wr * grad[j];
            }

            // build the contribution matrix for measurement i
            for (int k = 0; k < nC; ++k) {
                double[] ak = a[k];
                double wgk = weight * grad[k];
                for (int l = 0; l < nC; ++l) {
                    ak[l] += wgk * grad[l];
                }
            }
        }

        try {
            // solve the linearized least squares problem
            RealMatrix mA = new BlockRealMatrix(a);
            DecompositionSolver solver = useLU ?
                    new LUDecomposition(mA).getSolver() :
                    new QRDecomposition(mA).getSolver();
            final double[] dX = solver.solve(new ArrayRealVector(b, false)).toArray();
            // update the estimated parameters
            for (int i = 0; i < nC; ++i) {
                currentPoint[i] += dX[i];
            }
        } catch (SingularMatrixException e) {
            throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM);
        }

        // Check convergence.
        if (previous != null) {
            converged = checker.converged(iter, previous, current);
            if (converged) {
                cost = computeCost(currentResiduals);
                // Update (deprecated) "point" field.
                point = current.getPoint();
                return current;
            }
        }
    }
    // Must never happen.
    throw new MathInternalError();
}
 
Example 4
Source File: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public PointVectorValuePair doOptimize() {

    final ConvergenceChecker<PointVectorValuePair> checker
        = getConvergenceChecker();

    // iterate until convergence is reached
    PointVectorValuePair current = null;
    int iter = 0;
    for (boolean converged = false; !converged;) {
        ++iter;

        // evaluate the objective function and its jacobian
        PointVectorValuePair previous = current;
        updateResidualsAndCost();
        updateJacobian();
        current = new PointVectorValuePair(point, objective);

        final double[] targetValues = getTargetRef();
        final double[] residualsWeights = getWeightRef();

        // build the linear problem
        final double[]   b = new double[cols];
        final double[][] a = new double[cols][cols];
        for (int i = 0; i < rows; ++i) {

            final double[] grad   = weightedResidualJacobian[i];
            final double weight   = residualsWeights[i];
            final double residual = objective[i] - targetValues[i];

            // compute the normal equation
            final double wr = weight * residual;
            for (int j = 0; j < cols; ++j) {
                b[j] += wr * grad[j];
            }

            // build the contribution matrix for measurement i
            for (int k = 0; k < cols; ++k) {
                double[] ak = a[k];
                double wgk = weight * grad[k];
                for (int l = 0; l < cols; ++l) {
                    ak[l] += wgk * grad[l];
                }
            }
        }

        try {
            // solve the linearized least squares problem
            RealMatrix mA = new BlockRealMatrix(a);
            DecompositionSolver solver = useLU ?
                    new LUDecomposition(mA).getSolver() :
                    new QRDecomposition(mA).getSolver();
            final double[] dX = solver.solve(new ArrayRealVector(b, false)).toArray();
            // update the estimated parameters
            for (int i = 0; i < cols; ++i) {
                point[i] += dX[i];
            }
        } catch (SingularMatrixException e) {
            throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM);
        }

        // check convergence
        if (checker != null) {
            if (previous != null) {
                converged = checker.converged(iter, previous, current);
            }
        }
    }
    // we have converged
    return current;
}
 
Example 5
Source File: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public PointVectorValuePair doOptimize() {

    final ConvergenceChecker<PointVectorValuePair> checker
        = getConvergenceChecker();

    // iterate until convergence is reached
    PointVectorValuePair current = null;
    int iter = 0;
    for (boolean converged = false; !converged;) {
        ++iter;

        // evaluate the objective function and its jacobian
        PointVectorValuePair previous = current;
        updateResidualsAndCost();
        updateJacobian();
        current = new PointVectorValuePair(point, objective);

        final double[] targetValues = getTargetRef();
        final double[] residualsWeights = getWeightRef();

        // build the linear problem
        final double[]   b = new double[cols];
        final double[][] a = new double[cols][cols];
        for (int i = 0; i < rows; ++i) {

            final double[] grad   = weightedResidualJacobian[i];
            final double weight   = residualsWeights[i];
            final double residual = objective[i] - targetValues[i];

            // compute the normal equation
            final double wr = weight * residual;
            for (int j = 0; j < cols; ++j) {
                b[j] += wr * grad[j];
            }

            // build the contribution matrix for measurement i
            for (int k = 0; k < cols; ++k) {
                double[] ak = a[k];
                double wgk = weight * grad[k];
                for (int l = 0; l < cols; ++l) {
                    ak[l] += wgk * grad[l];
                }
            }
        }

        try {
            // solve the linearized least squares problem
            RealMatrix mA = new BlockRealMatrix(a);
            DecompositionSolver solver = useLU ?
                    new LUDecomposition(mA).getSolver() :
                    new QRDecomposition(mA).getSolver();
            final double[] dX = solver.solve(new ArrayRealVector(b, false)).toArray();
            // update the estimated parameters
            for (int i = 0; i < cols; ++i) {
                point[i] += dX[i];
            }
        } catch (SingularMatrixException e) {
            throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM);
        }

        // check convergence
        if (checker != null) {
            if (previous != null) {
                converged = checker.converged(iter, previous, current);
            }
        }
    }
    // we have converged
    return current;
}
 
Example 6
Source File: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public PointVectorValuePair doOptimize() {
    final ConvergenceChecker<PointVectorValuePair> checker
        = getConvergenceChecker();

    // Computation will be useless without a checker (see "for-loop").
    if (checker == null) {
        throw new NullArgumentException();
    }

    final double[] targetValues = getTarget();
    final int nR = targetValues.length; // Number of observed data.

    final RealMatrix weightMatrix = getWeight();
    // Diagonal of the weight matrix.
    final double[] residualsWeights = new double[nR];
    for (int i = 0; i < nR; i++) {
        residualsWeights[i] = weightMatrix.getEntry(i, i);
    }

    final double[] currentPoint = getStartPoint();
    final int nC = currentPoint.length;

    // iterate until convergence is reached
    PointVectorValuePair current = null;
    int iter = 0;
    for (boolean converged = false; !converged;) {
        ++iter;

        // evaluate the objective function and its jacobian
        PointVectorValuePair previous = current;
        // Value of the objective function at "currentPoint".
        final double[] currentObjective = computeObjectiveValue(currentPoint);
        final double[] currentResiduals = computeResiduals(currentObjective);
        final RealMatrix weightedJacobian = computeWeightedJacobian(currentPoint);
        current = new PointVectorValuePair(currentPoint, currentObjective);

        // build the linear problem
        final double[]   b = new double[nC];
        final double[][] a = new double[nC][nC];
        for (int i = 0; i < nR; ++i) {

            final double[] grad   = weightedJacobian.getRow(i);
            final double weight   = residualsWeights[i];
            final double residual = currentResiduals[i];

            // compute the normal equation
            final double wr = weight * residual;
            for (int j = 0; j < nC; ++j) {
                b[j] += wr * grad[j];
            }

            // build the contribution matrix for measurement i
            for (int k = 0; k < nC; ++k) {
                double[] ak = a[k];
                double wgk = weight * grad[k];
                for (int l = 0; l < nC; ++l) {
                    ak[l] += wgk * grad[l];
                }
            }
        }

        try {
            // solve the linearized least squares problem
            RealMatrix mA = new BlockRealMatrix(a);
            DecompositionSolver solver = useLU ?
                    new LUDecomposition(mA).getSolver() :
                    new QRDecomposition(mA).getSolver();
            final double[] dX = solver.solve(new ArrayRealVector(b, false)).toArray();
            // update the estimated parameters
            for (int i = 0; i < nC; ++i) {
                currentPoint[i] += dX[i];
            }
        } catch (SingularMatrixException e) {
            throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM);
        }

        // Check convergence.
        if (previous != null) {
            converged = checker.converged(iter, previous, current);
            if (converged) {
                cost = computeCost(currentResiduals);
                // Update (deprecated) "point" field.
                point = current.getPoint();
                return current;
            }
        }
    }
    // Must never happen.
    throw new MathInternalError();
}
 
Example 7
Source File: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public PointVectorValuePair doOptimize() {

    final ConvergenceChecker<PointVectorValuePair> checker
        = getConvergenceChecker();

    // iterate until convergence is reached
    PointVectorValuePair current = null;
    int iter = 0;
    for (boolean converged = false; !converged;) {
        ++iter;

        // evaluate the objective function and its jacobian
        PointVectorValuePair previous = current;
        updateResidualsAndCost();
        updateJacobian();
        current = new PointVectorValuePair(point, objective);

        final double[] targetValues = getTargetRef();
        final double[] residualsWeights = getWeightRef();

        // build the linear problem
        final double[]   b = new double[cols];
        final double[][] a = new double[cols][cols];
        for (int i = 0; i < rows; ++i) {

            final double[] grad   = weightedResidualJacobian[i];
            final double weight   = residualsWeights[i];
            final double residual = objective[i] - targetValues[i];

            // compute the normal equation
            final double wr = weight * residual;
            for (int j = 0; j < cols; ++j) {
                b[j] += wr * grad[j];
            }

            // build the contribution matrix for measurement i
            for (int k = 0; k < cols; ++k) {
                double[] ak = a[k];
                double wgk = weight * grad[k];
                for (int l = 0; l < cols; ++l) {
                    ak[l] += wgk * grad[l];
                }
            }
        }

        try {
            // solve the linearized least squares problem
            RealMatrix mA = new BlockRealMatrix(a);
            DecompositionSolver solver = useLU ?
                    new LUDecomposition(mA).getSolver() :
                    new QRDecomposition(mA).getSolver();
            final double[] dX = solver.solve(new ArrayRealVector(b, false)).toArray();
            // update the estimated parameters
            for (int i = 0; i < cols; ++i) {
                point[i] += dX[i];
            }
        } catch (SingularMatrixException e) {
            throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM);
        }

        // check convergence
        if (checker != null) {
            if (previous != null) {
                converged = checker.converged(iter, previous, current);
            }
        }
    }
    // we have converged
    return current;
}
 
Example 8
Source File: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public PointVectorValuePair doOptimize() {
    final ConvergenceChecker<PointVectorValuePair> checker
        = getConvergenceChecker();

    // Computation will be useless without a checker (see "for-loop").
    if (checker == null) {
        throw new NullArgumentException();
    }

    final double[] targetValues = getTarget();
    final int nR = targetValues.length; // Number of observed data.

    final RealMatrix weightMatrix = getWeight();
    // Diagonal of the weight matrix.
    final double[] residualsWeights = new double[nR];
    for (int i = 0; i < nR; i++) {
        residualsWeights[i] = weightMatrix.getEntry(i, i);
    }

    final double[] currentPoint = getStartPoint();
    final int nC = currentPoint.length;

    // iterate until convergence is reached
    PointVectorValuePair current = null;
    int iter = 0;
    for (boolean converged = false; !converged;) {
        ++iter;

        // evaluate the objective function and its jacobian
        PointVectorValuePair previous = current;
        // Value of the objective function at "currentPoint".
        final double[] currentObjective = computeObjectiveValue(currentPoint);
        final double[] currentResiduals = computeResiduals(currentObjective);
        final RealMatrix weightedJacobian = computeWeightedJacobian(currentPoint);
        current = new PointVectorValuePair(currentPoint, currentObjective);

        // build the linear problem
        final double[]   b = new double[nC];
        final double[][] a = new double[nC][nC];
        for (int i = 0; i < nR; ++i) {

            final double[] grad   = weightedJacobian.getRow(i);
            final double weight   = residualsWeights[i];
            final double residual = currentResiduals[i];

            // compute the normal equation
            final double wr = weight * residual;
            for (int j = 0; j < nC; ++j) {
                b[j] += wr * grad[j];
            }

            // build the contribution matrix for measurement i
            for (int k = 0; k < nC; ++k) {
                double[] ak = a[k];
                double wgk = weight * grad[k];
                for (int l = 0; l < nC; ++l) {
                    ak[l] += wgk * grad[l];
                }
            }
        }

        try {
            // solve the linearized least squares problem
            RealMatrix mA = new BlockRealMatrix(a);
            DecompositionSolver solver = useLU ?
                    new LUDecomposition(mA).getSolver() :
                    new QRDecomposition(mA).getSolver();
            final double[] dX = solver.solve(new ArrayRealVector(b, false)).toArray();
            // update the estimated parameters
            for (int i = 0; i < nC; ++i) {
                currentPoint[i] += dX[i];
            }
        } catch (SingularMatrixException e) {
            throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM);
        }

        // Check convergence.
        if (previous != null) {
            converged = checker.converged(iter, previous, current);
            if (converged) {
                cost = computeCost(currentResiduals);
                // Update (deprecated) "point" field.
                point = current.getPoint();
                return current;
            }
        }
    }
    // Must never happen.
    throw new MathInternalError();
}
 
Example 9
Source File: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public PointVectorValuePair doOptimize() {
    final ConvergenceChecker<PointVectorValuePair> checker
        = getConvergenceChecker();

    // Computation will be useless without a checker (see "for-loop").
    if (checker == null) {
        throw new NullArgumentException();
    }

    final double[] targetValues = getTarget();
    final int nR = targetValues.length; // Number of observed data.

    final RealMatrix weightMatrix = getWeight();
    // Diagonal of the weight matrix.
    final double[] residualsWeights = new double[nR];
    for (int i = 0; i < nR; i++) {
        residualsWeights[i] = weightMatrix.getEntry(i, i);
    }

    final double[] currentPoint = getStartPoint();
    final int nC = currentPoint.length;

    // iterate until convergence is reached
    PointVectorValuePair current = null;
    int iter = 0;
    for (boolean converged = false; !converged;) {
        ++iter;

        // evaluate the objective function and its jacobian
        PointVectorValuePair previous = current;
        // Value of the objective function at "currentPoint".
        final double[] currentObjective = computeObjectiveValue(currentPoint);
        final double[] currentResiduals = computeResiduals(currentObjective);
        final RealMatrix weightedJacobian = computeWeightedJacobian(currentPoint);
        current = new PointVectorValuePair(currentPoint, currentObjective);

        // build the linear problem
        final double[]   b = new double[nC];
        final double[][] a = new double[nC][nC];
        for (int i = 0; i < nR; ++i) {

            final double[] grad   = weightedJacobian.getRow(i);
            final double weight   = residualsWeights[i];
            final double residual = currentResiduals[i];

            // compute the normal equation
            final double wr = weight * residual;
            for (int j = 0; j < nC; ++j) {
                b[j] += wr * grad[j];
            }

            // build the contribution matrix for measurement i
            for (int k = 0; k < nC; ++k) {
                double[] ak = a[k];
                double wgk = weight * grad[k];
                for (int l = 0; l < nC; ++l) {
                    ak[l] += wgk * grad[l];
                }
            }
        }

        try {
            // solve the linearized least squares problem
            RealMatrix mA = new BlockRealMatrix(a);
            DecompositionSolver solver = useLU ?
                    new LUDecomposition(mA).getSolver() :
                    new QRDecomposition(mA).getSolver();
            final double[] dX = solver.solve(new ArrayRealVector(b, false)).toArray();
            // update the estimated parameters
            for (int i = 0; i < nC; ++i) {
                currentPoint[i] += dX[i];
            }
        } catch (SingularMatrixException e) {
            throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM);
        }

        // Check convergence.
        if (previous != null) {
            converged = checker.converged(iter, previous, current);
            if (converged) {
                cost = computeCost(currentResiduals);
                // Update (deprecated) "point" field.
                point = current.getPoint();
                return current;
            }
        }
    }
    // Must never happen.
    throw new MathInternalError();
}
 
Example 10
Source File: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public PointVectorValuePair doOptimize() {
    final ConvergenceChecker<PointVectorValuePair> checker
        = getConvergenceChecker();

    // Computation will be useless without a checker (see "for-loop").
    if (checker == null) {
        throw new NullArgumentException();
    }

    final double[] targetValues = getTarget();
    final int nR = targetValues.length; // Number of observed data.

    final RealMatrix weightMatrix = getWeight();
    // Diagonal of the weight matrix.
    final double[] residualsWeights = new double[nR];
    for (int i = 0; i < nR; i++) {
        residualsWeights[i] = weightMatrix.getEntry(i, i);
    }

    final double[] currentPoint = getStartPoint();
    final int nC = currentPoint.length;

    // iterate until convergence is reached
    PointVectorValuePair current = null;
    int iter = 0;
    for (boolean converged = false; !converged;) {
        ++iter;

        // evaluate the objective function and its jacobian
        PointVectorValuePair previous = current;
        // Value of the objective function at "currentPoint".
        final double[] currentObjective = computeObjectiveValue(currentPoint);
        final double[] currentResiduals = computeResiduals(currentObjective);
        final RealMatrix weightedJacobian = computeWeightedJacobian(currentPoint);
        current = new PointVectorValuePair(currentPoint, currentObjective);

        // build the linear problem
        final double[]   b = new double[nC];
        final double[][] a = new double[nC][nC];
        for (int i = 0; i < nR; ++i) {

            final double[] grad   = weightedJacobian.getRow(i);
            final double weight   = residualsWeights[i];
            final double residual = currentResiduals[i];

            // compute the normal equation
            final double wr = weight * residual;
            for (int j = 0; j < nC; ++j) {
                b[j] += wr * grad[j];
            }

            // build the contribution matrix for measurement i
            for (int k = 0; k < nC; ++k) {
                double[] ak = a[k];
                double wgk = weight * grad[k];
                for (int l = 0; l < nC; ++l) {
                    ak[l] += wgk * grad[l];
                }
            }
        }

        try {
            // solve the linearized least squares problem
            RealMatrix mA = new BlockRealMatrix(a);
            DecompositionSolver solver = useLU ?
                    new LUDecomposition(mA).getSolver() :
                    new QRDecomposition(mA).getSolver();
            final double[] dX = solver.solve(new ArrayRealVector(b, false)).toArray();
            // update the estimated parameters
            for (int i = 0; i < nC; ++i) {
                currentPoint[i] += dX[i];
            }
        } catch (SingularMatrixException e) {
            throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM);
        }

        // Check convergence.
        if (previous != null) {
            converged = checker.converged(iter, previous, current);
            if (converged) {
                cost = computeCost(currentResiduals);
                // Update (deprecated) "point" field.
                point = current.getPoint();
                return current;
            }
        }
    }
    // Must never happen.
    throw new MathInternalError();
}
 
Example 11
Source File: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
@Override
protected RealVector solve(final RealMatrix jacobian,
                           final RealVector residuals) {
    try {
        final Pair<RealMatrix, RealVector> normalEquation =
                computeNormalMatrix(jacobian, residuals);
        final RealMatrix normal = normalEquation.getFirst();
        final RealVector jTr = normalEquation.getSecond();
        return new LUDecomposition(normal, SINGULARITY_THRESHOLD)
                .getSolver()
                .solve(jTr);
    } catch (SingularMatrixException e) {
        throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, e);
    }
}
 
Example 12
Source File: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
@Override
protected RealVector solve(final RealMatrix jacobian,
                           final RealVector residuals) {
    try {
        final Pair<RealMatrix, RealVector> normalEquation =
                computeNormalMatrix(jacobian, residuals);
        final RealMatrix normal = normalEquation.getFirst();
        final RealVector jTr = normalEquation.getSecond();
        return new LUDecomposition(normal, SINGULARITY_THRESHOLD)
                .getSolver()
                .solve(jTr);
    } catch (SingularMatrixException e) {
        throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, e);
    }
}
 
Example 13
Source File: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
@Override
protected RealVector solve(final RealMatrix jacobian,
                           final RealVector residuals) {
    try {
        return new QRDecomposition(jacobian, SINGULARITY_THRESHOLD)
                .getSolver()
                .solve(residuals);
    } catch (SingularMatrixException e) {
        throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, e);
    }
}
 
Example 14
Source File: GaussNewtonOptimizer.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
@Override
protected RealVector solve(final RealMatrix jacobian,
                           final RealVector residuals) {
    try {
        return new QRDecomposition(jacobian, SINGULARITY_THRESHOLD)
                .getSolver()
                .solve(residuals);
    } catch (SingularMatrixException e) {
        throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, e);
    }
}