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

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#CONVERGENCE_FAILED . 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: ConvergenceException.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct the exception.
 */
public ConvergenceException() {
    this(LocalizedFormats.CONVERGENCE_FAILED);
}
 
Example 2
Source File: SchurTransformer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Transform original matrix to Schur form.
 * @throws MaxCountExceededException if the transformation does not converge
 */
private void transform() {
    final int n = matrixT.length;

    // compute matrix norm
    final double norm = getNorm();

    // shift information
    final ShiftInfo shift = new ShiftInfo();

    // Outer loop over eigenvalue index
    int iteration = 0;
    int iu = n - 1;
    while (iu >= 0) {

        // Look for single small sub-diagonal element
        final int il = findSmallSubDiagonalElement(iu, norm);

        // Check for convergence
        if (il == iu) {
            // One root found
            matrixT[iu][iu] += shift.exShift;
            iu--;
            iteration = 0;
        } else if (il == iu - 1) {
            // Two roots found
            double p = (matrixT[iu - 1][iu - 1] - matrixT[iu][iu]) / 2.0;
            double q = p * p + matrixT[iu][iu - 1] * matrixT[iu - 1][iu];
            matrixT[iu][iu] += shift.exShift;
            matrixT[iu - 1][iu - 1] += shift.exShift;

            if (q >= 0) {
                double z = FastMath.sqrt(FastMath.abs(q));
                if (p >= 0) {
                    z = p + z;
                } else {
                    z = p - z;
                }
                final double x = matrixT[iu][iu - 1];
                final double s = FastMath.abs(x) + FastMath.abs(z);
                p = x / s;
                q = z / s;
                final double r = FastMath.sqrt(p * p + q * q);
                p /= r;
                q /= r;

                // Row modification
                for (int j = iu - 1; j < n; j++) {
                    z = matrixT[iu - 1][j];
                    matrixT[iu - 1][j] = q * z + p * matrixT[iu][j];
                    matrixT[iu][j] = q * matrixT[iu][j] - p * z;
                }

                // Column modification
                for (int i = 0; i <= iu; i++) {
                    z = matrixT[i][iu - 1];
                    matrixT[i][iu - 1] = q * z + p * matrixT[i][iu];
                    matrixT[i][iu] = q * matrixT[i][iu] - p * z;
                }

                // Accumulate transformations
                for (int i = 0; i <= n - 1; i++) {
                    z = matrixP[i][iu - 1];
                    matrixP[i][iu - 1] = q * z + p * matrixP[i][iu];
                    matrixP[i][iu] = q * matrixP[i][iu] - p * z;
                }
            }
            iu -= 2;
            iteration = 0;
        } else {
            // No convergence yet
            computeShift(il, iu, iteration, shift);

            // stop transformation after too many iterations
            if (++iteration > MAX_ITERATIONS) {
                throw new MaxCountExceededException(LocalizedFormats.CONVERGENCE_FAILED,
                                                    MAX_ITERATIONS);
            }

            // the initial houseHolder vector for the QR step
            final double[] hVec = new double[3];

            final int im = initQRStep(il, iu, shift, hVec);
            performDoubleQRStep(il, im, iu, shift, hVec);
        }
    }
}
 
Example 3
Source File: ConvergenceException.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct the exception.
 */
public ConvergenceException() {
    this(LocalizedFormats.CONVERGENCE_FAILED);
}
 
Example 4
Source File: ConvergenceException.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct the exception.
 */
public ConvergenceException() {
    this(LocalizedFormats.CONVERGENCE_FAILED);
}
 
Example 5
Source File: ConvergenceException.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct the exception.
 */
public ConvergenceException() {
    this(LocalizedFormats.CONVERGENCE_FAILED);
}
 
Example 6
Source File: SchurTransformer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Transform original matrix to Schur form.
 * @throws MaxCountExceededException if the transformation does not converge
 */
private void transform() {
    final int n = matrixT.length;

    // compute matrix norm
    final double norm = getNorm();

    // shift information
    final ShiftInfo shift = new ShiftInfo();

    // Outer loop over eigenvalue index
    int iteration = 0;
    int iu = n - 1;
    while (iu >= 0) {

        // Look for single small sub-diagonal element
        final int il = findSmallSubDiagonalElement(iu, norm);

        // Check for convergence
        if (il == iu) {
            // One root found
            matrixT[iu][iu] = matrixT[iu][iu] + shift.exShift;
            iu--;
            iteration = 0;
        } else if (il == iu - 1) {
            // Two roots found
            double p = (matrixT[iu - 1][iu - 1] - matrixT[iu][iu]) / 2.0;
            double q = p * p + matrixT[iu][iu - 1] * matrixT[iu - 1][iu];
            matrixT[iu][iu] += shift.exShift;
            matrixT[iu - 1][iu - 1] += shift.exShift;

            if (q >= 0) {
                double z = FastMath.sqrt(FastMath.abs(q));
                if (p >= 0) {
                    z = p + z;
                } else {
                    z = p - z;
                }
                final double x = matrixT[iu][iu - 1];
                final double s = FastMath.abs(x) + FastMath.abs(z);
                p = x / s;
                q = z / s;
                final double r = FastMath.sqrt(p * p + q * q);
                p = p / r;
                q = q / r;

                // Row modification
                for (int j = iu - 1; j < n; j++) {
                    z = matrixT[iu - 1][j];
                    matrixT[iu - 1][j] = q * z + p * matrixT[iu][j];
                    matrixT[iu][j] = q * matrixT[iu][j] - p * z;
                }

                // Column modification
                for (int i = 0; i <= iu; i++) {
                    z = matrixT[i][iu - 1];
                    matrixT[i][iu - 1] = q * z + p * matrixT[i][iu];
                    matrixT[i][iu] = q * matrixT[i][iu] - p * z;
                }

                // Accumulate transformations
                for (int i = 0; i <= n - 1; i++) {
                    z = matrixP[i][iu - 1];
                    matrixP[i][iu - 1] = q * z + p * matrixP[i][iu];
                    matrixP[i][iu] = q * matrixP[i][iu] - p * z;
                }
            }
            iu -= 2;
            iteration = 0;
        } else {
            // No convergence yet
            computeShift(il, iu, iteration, shift);

            // stop transformation after too many iterations
            if (++iteration > MAX_ITERATIONS) {
                throw new MaxCountExceededException(LocalizedFormats.CONVERGENCE_FAILED,
                                                    MAX_ITERATIONS);
            }

            // the initial houseHolder vector for the QR step
            final double[] hVec = new double[3];

            final int im = initQRStep(il, iu, shift, hVec);
            performDoubleQRStep(il, im, iu, shift, hVec);
        }
    }
}
 
Example 7
Source File: ConvergenceException.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct the exception.
 */
public ConvergenceException() {
    this(LocalizedFormats.CONVERGENCE_FAILED);
}
 
Example 8
Source File: ConvergenceException.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct the exception.
 */
public ConvergenceException() {
    this(LocalizedFormats.CONVERGENCE_FAILED);
}
 
Example 9
Source File: SchurTransformer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Transform original matrix to Schur form.
 * @throws MaxCountExceededException if the transformation does not converge
 */
private void transform() {
    final int n = matrixT.length;

    // compute matrix norm
    final double norm = getNorm();

    // shift information
    final ShiftInfo shift = new ShiftInfo();

    // Outer loop over eigenvalue index
    int iteration = 0;
    int iu = n - 1;
    while (iu >= 0) {

        // Look for single small sub-diagonal element
        final int il = findSmallSubDiagonalElement(iu, norm);

        // Check for convergence
        if (il == iu) {
            // One root found
            matrixT[iu][iu] = matrixT[iu][iu] + shift.exShift;
            iu--;
            iteration = 0;
        } else if (il == iu - 1) {
            // Two roots found
            double p = (matrixT[iu - 1][iu - 1] - matrixT[iu][iu]) / 2.0;
            double q = p * p + matrixT[iu][iu - 1] * matrixT[iu - 1][iu];
            matrixT[iu][iu] += shift.exShift;
            matrixT[iu - 1][iu - 1] += shift.exShift;

            if (q >= 0) {
                double z = FastMath.sqrt(FastMath.abs(q));
                if (p >= 0) {
                    z = p + z;
                } else {
                    z = p - z;
                }
                final double x = matrixT[iu][iu - 1];
                final double s = FastMath.abs(x) + FastMath.abs(z);
                p = x / s;
                q = z / s;
                final double r = FastMath.sqrt(p * p + q * q);
                p = p / r;
                q = q / r;

                // Row modification
                for (int j = iu - 1; j < n; j++) {
                    z = matrixT[iu - 1][j];
                    matrixT[iu - 1][j] = q * z + p * matrixT[iu][j];
                    matrixT[iu][j] = q * matrixT[iu][j] - p * z;
                }

                // Column modification
                for (int i = 0; i <= iu; i++) {
                    z = matrixT[i][iu - 1];
                    matrixT[i][iu - 1] = q * z + p * matrixT[i][iu];
                    matrixT[i][iu] = q * matrixT[i][iu] - p * z;
                }

                // Accumulate transformations
                for (int i = 0; i <= n - 1; i++) {
                    z = matrixP[i][iu - 1];
                    matrixP[i][iu - 1] = q * z + p * matrixP[i][iu];
                    matrixP[i][iu] = q * matrixP[i][iu] - p * z;
                }
            }
            iu -= 2;
            iteration = 0;
        } else {
            // No convergence yet
            computeShift(il, iu, iteration, shift);

            // stop transformation after too many iterations
            if (++iteration > MAX_ITERATIONS) {
                throw new MaxCountExceededException(LocalizedFormats.CONVERGENCE_FAILED,
                                                    MAX_ITERATIONS);
            }

            // the initial houseHolder vector for the QR step
            final double[] hVec = new double[3];

            final int im = initQRStep(il, iu, shift, hVec);
            performDoubleQRStep(il, im, iu, shift, hVec);
        }
    }
}
 
Example 10
Source File: ConvergenceException.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct the exception.
 */
public ConvergenceException() {
    this(LocalizedFormats.CONVERGENCE_FAILED);
}
 
Example 11
Source File: SchurTransformer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Transform original matrix to Schur form.
 * @throws MaxCountExceededException if the transformation does not converge
 */
private void transform() {
    final int n = matrixT.length;

    // compute matrix norm
    final double norm = getNorm();

    // shift information
    final ShiftInfo shift = new ShiftInfo();

    // Outer loop over eigenvalue index
    int iteration = 0;
    int iu = n - 1;
    while (iu >= 0) {

        // Look for single small sub-diagonal element
        final int il = findSmallSubDiagonalElement(iu, norm);

        // Check for convergence
        if (il == iu) {
            // One root found
            matrixT[iu][iu] = matrixT[iu][iu] + shift.exShift;
            iu--;
            iteration = 0;
        } else if (il == iu - 1) {
            // Two roots found
            double p = (matrixT[iu - 1][iu - 1] - matrixT[iu][iu]) / 2.0;
            double q = p * p + matrixT[iu][iu - 1] * matrixT[iu - 1][iu];
            matrixT[iu][iu] += shift.exShift;
            matrixT[iu - 1][iu - 1] += shift.exShift;

            if (q >= 0) {
                double z = FastMath.sqrt(FastMath.abs(q));
                if (p >= 0) {
                    z = p + z;
                } else {
                    z = p - z;
                }
                final double x = matrixT[iu][iu - 1];
                final double s = FastMath.abs(x) + FastMath.abs(z);
                p = x / s;
                q = z / s;
                final double r = FastMath.sqrt(p * p + q * q);
                p = p / r;
                q = q / r;

                // Row modification
                for (int j = iu - 1; j < n; j++) {
                    z = matrixT[iu - 1][j];
                    matrixT[iu - 1][j] = q * z + p * matrixT[iu][j];
                    matrixT[iu][j] = q * matrixT[iu][j] - p * z;
                }

                // Column modification
                for (int i = 0; i <= iu; i++) {
                    z = matrixT[i][iu - 1];
                    matrixT[i][iu - 1] = q * z + p * matrixT[i][iu];
                    matrixT[i][iu] = q * matrixT[i][iu] - p * z;
                }

                // Accumulate transformations
                for (int i = 0; i <= n - 1; i++) {
                    z = matrixP[i][iu - 1];
                    matrixP[i][iu - 1] = q * z + p * matrixP[i][iu];
                    matrixP[i][iu] = q * matrixP[i][iu] - p * z;
                }
            }
            iu -= 2;
            iteration = 0;
        } else {
            // No convergence yet
            computeShift(il, iu, iteration, shift);

            // stop transformation after too many iterations
            if (++iteration > MAX_ITERATIONS) {
                throw new MaxCountExceededException(LocalizedFormats.CONVERGENCE_FAILED,
                                                    MAX_ITERATIONS);
            }

            // the initial houseHolder vector for the QR step
            final double[] hVec = new double[3];

            final int im = initQRStep(il, iu, shift, hVec);
            performDoubleQRStep(il, im, iu, shift, hVec);
        }
    }
}
 
Example 12
Source File: ConvergenceException.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct the exception.
 */
public ConvergenceException() {
    this(LocalizedFormats.CONVERGENCE_FAILED);
}
 
Example 13
Source File: SchurTransformer.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Transform original matrix to Schur form.
 * @throws MaxCountExceededException if the transformation does not converge
 */
private void transform() {
    final int n = matrixT.length;

    // compute matrix norm
    final double norm = getNorm();

    // shift information
    final ShiftInfo shift = new ShiftInfo();

    // Outer loop over eigenvalue index
    int iteration = 0;
    int iu = n - 1;
    while (iu >= 0) {

        // Look for single small sub-diagonal element
        final int il = findSmallSubDiagonalElement(iu, norm);

        // Check for convergence
        if (il == iu) {
            // One root found
            matrixT[iu][iu] += shift.exShift;
            iu--;
            iteration = 0;
        } else if (il == iu - 1) {
            // Two roots found
            double p = (matrixT[iu - 1][iu - 1] - matrixT[iu][iu]) / 2.0;
            double q = p * p + matrixT[iu][iu - 1] * matrixT[iu - 1][iu];
            matrixT[iu][iu] += shift.exShift;
            matrixT[iu - 1][iu - 1] += shift.exShift;

            if (q >= 0) {
                double z = FastMath.sqrt(FastMath.abs(q));
                if (p >= 0) {
                    z = p + z;
                } else {
                    z = p - z;
                }
                final double x = matrixT[iu][iu - 1];
                final double s = FastMath.abs(x) + FastMath.abs(z);
                p = x / s;
                q = z / s;
                final double r = FastMath.sqrt(p * p + q * q);
                p /= r;
                q /= r;

                // Row modification
                for (int j = iu - 1; j < n; j++) {
                    z = matrixT[iu - 1][j];
                    matrixT[iu - 1][j] = q * z + p * matrixT[iu][j];
                    matrixT[iu][j] = q * matrixT[iu][j] - p * z;
                }

                // Column modification
                for (int i = 0; i <= iu; i++) {
                    z = matrixT[i][iu - 1];
                    matrixT[i][iu - 1] = q * z + p * matrixT[i][iu];
                    matrixT[i][iu] = q * matrixT[i][iu] - p * z;
                }

                // Accumulate transformations
                for (int i = 0; i <= n - 1; i++) {
                    z = matrixP[i][iu - 1];
                    matrixP[i][iu - 1] = q * z + p * matrixP[i][iu];
                    matrixP[i][iu] = q * matrixP[i][iu] - p * z;
                }
            }
            iu -= 2;
            iteration = 0;
        } else {
            // No convergence yet
            computeShift(il, iu, iteration, shift);

            // stop transformation after too many iterations
            if (++iteration > MAX_ITERATIONS) {
                throw new MaxCountExceededException(LocalizedFormats.CONVERGENCE_FAILED,
                                                    MAX_ITERATIONS);
            }

            // the initial houseHolder vector for the QR step
            final double[] hVec = new double[3];

            final int im = initQRStep(il, iu, shift, hVec);
            performDoubleQRStep(il, im, iu, shift, hVec);
        }
    }
}