Re: svn commit: r1179935 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/linear/ test/java/org/apache/commons/math/linear/
Le 07/10/2011 07:21, gr...@apache.org a écrit : Author: gregs Date: Fri Oct 7 05:21:17 2011 New Revision: 1179935 URL: http://svn.apache.org/viewvc?rev=1179935view=rev Log: JIRA Math-630 First push of PivotingQRDecomposition Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/PivotingQRDecomposition.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/PivotingQRDecompositionTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/PivotingQRSolverTest.java Hello Greg, It seems the files do not have the right subversion properties. Could you check your global subversion settings and make sure [auto-props] is set correctly ? Thanks Luc Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/PivotingQRDecomposition.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/PivotingQRDecomposition.java?rev=1179935view=auto == --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/PivotingQRDecomposition.java (added) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/PivotingQRDecomposition.java Fri Oct 7 05:21:17 2011 @@ -0,0 +1,421 @@ +/* + * Copyright 2011 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.math.linear; + +import java.util.Arrays; +import org.apache.commons.math.util.MathUtils; +import org.apache.commons.math.ConvergenceException; +import org.apache.commons.math.exception.DimensionMismatchException; +import org.apache.commons.math.exception.util.LocalizedFormats; +import org.apache.commons.math.util.FastMath; + +/** + * + * @author gregsterijevski + */ +public class PivotingQRDecomposition { + +private double[][] qr; +/** The diagonal elements of R. */ +private double[] rDiag; +/** Cached value of Q. */ +private RealMatrix cachedQ; +/** Cached value of QT. */ +private RealMatrix cachedQT; +/** Cached value of R. */ +private RealMatrix cachedR; +/** Cached value of H. */ +private RealMatrix cachedH; +/** permutation info */ +private int[] permutation; +/** the rank **/ +private int rank; +/** vector of column multipliers */ +private double[] beta; + +public boolean isSingular() { +return rank != qr[0].length; +} + +public int getRank() { +return rank; +} + +public int[] getOrder() { +return MathUtils.copyOf(permutation); +} + +public PivotingQRDecomposition(RealMatrix matrix) throws ConvergenceException { +this(matrix, 1.0e-16, true); +} + +public PivotingQRDecomposition(RealMatrix matrix, boolean allowPivot) throws ConvergenceException { +this(matrix, 1.0e-16, allowPivot); +} + +public PivotingQRDecomposition(RealMatrix matrix, double qrRankingThreshold, +boolean allowPivot) throws ConvergenceException { +final int rows = matrix.getRowDimension(); +final int cols = matrix.getColumnDimension(); +qr = matrix.getData(); +rDiag = new double[cols]; +//final double[] norms = new double[cols]; +this.beta = new double[cols]; +this.permutation = new int[cols]; +cachedQ = null; +cachedQT = null; +cachedR = null; +cachedH = null; + +/*- initialize the permutation vector and calculate the norms */ +for (int k = 0; k cols; ++k) { +permutation[k] = k; +} +// transform the matrix column after column +for (int k = 0; k cols; ++k) { +// select the column with the greatest norm on active components +int nextColumn = -1; +double ak2 = Double.NEGATIVE_INFINITY; +if (allowPivot) { +for (int i = k; i cols; ++i) { +double norm2 = 0; +for (int j = k; j rows; ++j) { +final double aki = qr[j][permutation[i]]; +norm2 += aki * aki; +} +if (Double.isInfinite(norm2) || Double.isNaN(norm2)) { +throw new ConvergenceException(LocalizedFormats.UNABLE_TO_PERFORM_QR_DECOMPOSITION_ON_JACOBIAN, +rows, cols); +
Re: svn commit: r1179935 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/linear/ test/java/org/apache/commons/math/linear/
Will do. My aplogies! -Greg On Fri, Oct 7, 2011 at 3:55 AM, Luc Maisonobe luc.maison...@free.fr wrote: Le 07/10/2011 07:21, gr...@apache.org a écrit : Author: gregs Date: Fri Oct 7 05:21:17 2011 New Revision: 1179935 URL: http://svn.apache.org/viewvc?**rev=1179935view=revhttp://svn.apache.org/viewvc?rev=1179935view=rev Log: JIRA Math-630 First push of PivotingQRDecomposition Added: commons/proper/math/trunk/src/**main/java/org/apache/commons/** math/linear/**PivotingQRDecomposition.java commons/proper/math/trunk/src/**test/java/org/apache/commons/** math/linear/**PivotingQRDecompositionTest.**java commons/proper/math/trunk/src/**test/java/org/apache/commons/** math/linear/**PivotingQRSolverTest.java Hello Greg, It seems the files do not have the right subversion properties. Could you check your global subversion settings and make sure [auto-props] is set correctly ? Thanks Luc Added: commons/proper/math/trunk/src/**main/java/org/apache/commons/** math/linear/**PivotingQRDecomposition.java URL: http://svn.apache.org/viewvc/**commons/proper/math/trunk/src/** main/java/org/apache/commons/**math/linear/** PivotingQRDecomposition.java?**rev=1179935view=autohttp://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/PivotingQRDecomposition.java?rev=1179935view=auto ==**==** == --- commons/proper/math/trunk/src/**main/java/org/apache/commons/** math/linear/**PivotingQRDecomposition.java (added) +++ commons/proper/math/trunk/src/**main/java/org/apache/commons/** math/linear/**PivotingQRDecomposition.java Fri Oct 7 05:21:17 2011 @@ -0,0 +1,421 @@ +/* + * Copyright 2011 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/**licenses/LICENSE-2.0http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.math.**linear; + +import java.util.Arrays; +import org.apache.commons.math.util.**MathUtils; +import org.apache.commons.math.**ConvergenceException; +import org.apache.commons.math.**exception.**DimensionMismatchException; +import org.apache.commons.math.**exception.util.**LocalizedFormats; +import org.apache.commons.math.util.**FastMath; + +/** + * + * @author gregsterijevski + */ +public class PivotingQRDecomposition { + +private double[][] qr; +/** The diagonal elements of R. */ +private double[] rDiag; +/** Cached value of Q. */ +private RealMatrix cachedQ; +/** Cached value of QT. */ +private RealMatrix cachedQT; +/** Cached value of R. */ +private RealMatrix cachedR; +/** Cached value of H. */ +private RealMatrix cachedH; +/** permutation info */ +private int[] permutation; +/** the rank **/ +private int rank; +/** vector of column multipliers */ +private double[] beta; + +public boolean isSingular() { +return rank != qr[0].length; +} + +public int getRank() { +return rank; +} + +public int[] getOrder() { +return MathUtils.copyOf(permutation); +} + +public PivotingQRDecomposition(**RealMatrix matrix) throws ConvergenceException { +this(matrix, 1.0e-16, true); +} + +public PivotingQRDecomposition(**RealMatrix matrix, boolean allowPivot) throws ConvergenceException { +this(matrix, 1.0e-16, allowPivot); +} + +public PivotingQRDecomposition(**RealMatrix matrix, double qrRankingThreshold, +boolean allowPivot) throws ConvergenceException { +final int rows = matrix.getRowDimension(); +final int cols = matrix.getColumnDimension(); +qr = matrix.getData(); +rDiag = new double[cols]; +//final double[] norms = new double[cols]; +this.beta = new double[cols]; +this.permutation = new int[cols]; +cachedQ = null; +cachedQT = null; +cachedR = null; +cachedH = null; + +/*- initialize the permutation vector and calculate the norms */ +for (int k = 0; k cols; ++k) { +permutation[k] = k; +} +// transform the matrix column after column +for (int k = 0; k cols; ++k) { +// select the column with the greatest norm on active components +int nextColumn = -1; +double ak2 = Double.NEGATIVE_INFINITY; +