idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
25,600 | public static long wrapped ( DMatrixRMaj a , DMatrixRMaj b , DMatrixRMaj c ) { long timeBefore = System . currentTimeMillis ( ) ; double valA ; int indexCbase = 0 ; int endOfKLoop = b . numRows * b . numCols ; for ( int i = 0 ; i < a . numRows ; i ++ ) { int indexA = i * a . numCols ; int indexB = 0 ; int indexC = indexCbase ; int end = indexB + b . numCols ; valA = a . get ( indexA ++ ) ; while ( indexB < end ) { c . set ( indexC ++ , valA * b . get ( indexB ++ ) ) ; } while ( indexB != endOfKLoop ) { indexC = indexCbase ; end = indexB + b . numCols ; valA = a . get ( indexA ++ ) ; while ( indexB < end ) { c . plus ( indexC ++ , valA * b . get ( indexB ++ ) ) ; } } indexCbase += c . numCols ; } return System . currentTimeMillis ( ) - timeBefore ; } | Wrapper functions with no bounds checking are used to access matrix internals |
25,601 | public static long access2d ( DMatrixRMaj a , DMatrixRMaj b , DMatrixRMaj c ) { long timeBefore = System . currentTimeMillis ( ) ; for ( int i = 0 ; i < a . numRows ; i ++ ) { for ( int j = 0 ; j < b . numCols ; j ++ ) { c . set ( i , j , a . get ( i , 0 ) * b . get ( 0 , j ) ) ; } for ( int k = 1 ; k < b . numRows ; k ++ ) { for ( int j = 0 ; j < b . numCols ; j ++ ) { c . data [ i * b . numCols + j ] += a . get ( i , k ) * b . get ( k , j ) ; } } } return System . currentTimeMillis ( ) - timeBefore ; } | Only sets and gets that are by row and column are used . |
25,602 | public String p ( double value ) { return UtilEjml . fancyString ( value , format , false , length , significant ) ; } | Fancy print without a space added to positive numbers |
25,603 | public boolean process ( int sideLength , double diag [ ] , double off [ ] , double eigenvalues [ ] ) { if ( diag != null ) helper . init ( diag , off , sideLength ) ; if ( Q == null ) Q = CommonOps_DDRM . identity ( helper . N ) ; helper . setQ ( Q ) ; this . followingScript = true ; this . eigenvalues = eigenvalues ; this . fastEigenvalues = false ; return _process ( ) ; } | Computes the eigenvalue of the provided tridiagonal matrix . Note that only the upper portion needs to be tridiagonal . The bottom diagonal is assumed to be the same as the top . |
25,604 | public void performStep ( ) { for ( int i = helper . x2 - 1 ; i >= helper . x1 ; i -- ) { if ( helper . isZero ( i ) ) { helper . splits [ helper . numSplits ++ ] = i ; helper . x1 = i + 1 ; return ; } } double lambda ; if ( followingScript ) { if ( helper . steps > 10 ) { followingScript = false ; return ; } else { lambda = eigenvalues [ helper . x2 ] ; } } else { lambda = helper . computeShift ( ) ; } helper . performImplicitSingleStep ( lambda , false ) ; } | First looks for zeros and then performs the implicit single step in the QR Algorithm . |
25,605 | public static void block ( DMatrix1Row A , DMatrix1Row A_tran , final int blockLength ) { for ( int i = 0 ; i < A . numRows ; i += blockLength ) { int blockHeight = Math . min ( blockLength , A . numRows - i ) ; int indexSrc = i * A . numCols ; int indexDst = i ; for ( int j = 0 ; j < A . numCols ; j += blockLength ) { int blockWidth = Math . min ( blockLength , A . numCols - j ) ; int indexSrcEnd = indexSrc + blockWidth ; for ( ; indexSrc < indexSrcEnd ; indexSrc ++ ) { int rowSrc = indexSrc ; int rowDst = indexDst ; int end = rowDst + blockHeight ; for ( ; rowDst < end ; rowSrc += A . numCols ) { A_tran . data [ rowDst ++ ] = A . data [ rowSrc ] ; } indexDst += A_tran . numCols ; } } } } | Performs a transpose across block sub - matrices . Reduces the number of cache misses on larger matrices . |
25,606 | public static boolean isIdentity ( DMatrix a , double tol ) { for ( int i = 0 ; i < a . getNumRows ( ) ; i ++ ) { for ( int j = 0 ; j < a . getNumCols ( ) ; j ++ ) { if ( i == j ) { if ( Math . abs ( a . get ( i , j ) - 1.0 ) > tol ) return false ; } else { if ( Math . abs ( a . get ( i , j ) ) > tol ) return false ; } } } return true ; } | Returns true if the provided matrix is has a value of 1 along the diagonal elements and zero along all the other elements . |
25,607 | public static double computeHouseholder ( double [ ] x , int xStart , int xEnd , double max , DScalar gamma ) { double tau = 0 ; for ( int i = xStart ; i < xEnd ; i ++ ) { double val = x [ i ] /= max ; tau += val * val ; } tau = Math . sqrt ( tau ) ; if ( x [ xStart ] < 0 ) { tau = - tau ; } double u_0 = x [ xStart ] + tau ; gamma . value = u_0 / tau ; x [ xStart ] = 1 ; for ( int i = xStart + 1 ; i < xEnd ; i ++ ) { x [ i ] /= u_0 ; } return - tau * max ; } | Creates a householder reflection . |
25,608 | public static long get1D ( DMatrixRMaj A , int n ) { long before = System . currentTimeMillis ( ) ; double total = 0 ; for ( int iter = 0 ; iter < n ; iter ++ ) { int index = 0 ; for ( int i = 0 ; i < A . numRows ; i ++ ) { int end = index + A . numCols ; while ( index != end ) { total += A . get ( index ++ ) ; } } } long after = System . currentTimeMillis ( ) ; System . out . println ( total ) ; return after - before ; } | Get by index is used here . |
25,609 | public static DMatrixRBlock initializeQ ( DMatrixRBlock Q , int numRows , int numCols , int blockLength , boolean compact ) { int minLength = Math . min ( numRows , numCols ) ; if ( compact ) { if ( Q == null ) { Q = new DMatrixRBlock ( numRows , minLength , blockLength ) ; MatrixOps_DDRB . setIdentity ( Q ) ; } else { if ( Q . numRows != numRows || Q . numCols != minLength ) { throw new IllegalArgumentException ( "Unexpected matrix dimension. Found " + Q . numRows + " " + Q . numCols ) ; } else { MatrixOps_DDRB . setIdentity ( Q ) ; } } } else { if ( Q == null ) { Q = new DMatrixRBlock ( numRows , numRows , blockLength ) ; MatrixOps_DDRB . setIdentity ( Q ) ; } else { if ( Q . numRows != numRows || Q . numCols != numRows ) { throw new IllegalArgumentException ( "Unexpected matrix dimension. Found " + Q . numRows + " " + Q . numCols ) ; } else { MatrixOps_DDRB . setIdentity ( Q ) ; } } } return Q ; } | Sanity checks the input or declares a new matrix . Return matrix is an identity matrix . |
25,610 | private void setup ( DMatrixRBlock orig ) { blockLength = orig . blockLength ; dataW . blockLength = blockLength ; dataWTA . blockLength = blockLength ; this . dataA = orig ; A . original = dataA ; int l = Math . min ( blockLength , orig . numCols ) ; dataW . reshape ( orig . numRows , l , false ) ; dataWTA . reshape ( l , orig . numRows , false ) ; Y . original = orig ; Y . row1 = W . row1 = orig . numRows ; if ( temp . length < blockLength ) temp = new double [ blockLength ] ; if ( gammas . length < orig . numCols ) gammas = new double [ orig . numCols ] ; if ( saveW ) { dataW . reshape ( orig . numRows , orig . numCols , false ) ; } } | Adjust submatrices and helper data structures for the input matrix . Must be called before the decomposition can be computed . |
25,611 | private void setW ( ) { if ( saveW ) { W . col0 = Y . col0 ; W . col1 = Y . col1 ; W . row0 = Y . row0 ; W . row1 = Y . row1 ; } else { W . col1 = Y . col1 - Y . col0 ; W . row0 = Y . row0 ; } } | Sets the submatrix of W up give Y is already configured and if it is being cached or not . |
25,612 | private void solveInternalL ( ) { TriangularSolver_ZDRM . solveL_diagReal ( t , vv , n ) ; TriangularSolver_ZDRM . solveConjTranL_diagReal ( t , vv , n ) ; } | Used internally to find the solution to a single column vector . |
25,613 | public void invert ( ZMatrixRMaj inv ) { if ( inv . numRows != n || inv . numCols != n ) { throw new RuntimeException ( "Unexpected matrix dimension" ) ; } if ( inv . data == t ) { throw new IllegalArgumentException ( "Passing in the same matrix that was decomposed." ) ; } if ( decomposer . isLower ( ) ) { setToInverseL ( inv . data ) ; } else { throw new RuntimeException ( "Implement" ) ; } } | Sets the matrix inv equal to the inverse of the matrix that was decomposed . |
25,614 | public void declareInternalData ( int maxRows , int maxCols ) { this . maxRows = maxRows ; this . maxCols = maxCols ; U_tran = new DMatrixRMaj ( maxRows , maxRows ) ; Qm = new DMatrixRMaj ( maxRows , maxRows ) ; r_row = new double [ maxCols ] ; } | Declares the internal data structures so that it can process matrices up to the specified size . |
25,615 | private void setQR ( DMatrixRMaj Q , DMatrixRMaj R , int growRows ) { if ( Q . numRows != Q . numCols ) { throw new IllegalArgumentException ( "Q should be square." ) ; } this . Q = Q ; this . R = R ; m = Q . numRows ; n = R . numCols ; if ( m + growRows > maxRows || n > maxCols ) { if ( autoGrow ) { declareInternalData ( m + growRows , n ) ; } else { throw new IllegalArgumentException ( "Autogrow has been set to false and the maximum number of rows" + " or columns has been exceeded." ) ; } } } | Provides the results of a QR decomposition . These will be modified by adding or removing rows from the original A matrix . |
25,616 | private void updateRemoveQ ( int rowIndex ) { Qm . set ( Q ) ; Q . reshape ( m_m , m_m , false ) ; for ( int i = 0 ; i < rowIndex ; i ++ ) { for ( int j = 1 ; j < m ; j ++ ) { double sum = 0 ; for ( int k = 0 ; k < m ; k ++ ) { sum += Qm . data [ i * m + k ] * U_tran . data [ j * m + k ] ; } Q . data [ i * m_m + j - 1 ] = sum ; } } for ( int i = rowIndex + 1 ; i < m ; i ++ ) { for ( int j = 1 ; j < m ; j ++ ) { double sum = 0 ; for ( int k = 0 ; k < m ; k ++ ) { sum += Qm . data [ i * m + k ] * U_tran . data [ j * m + k ] ; } Q . data [ ( i - 1 ) * m_m + j - 1 ] = sum ; } } } | Updates the Q matrix to take inaccount the row that was removed by only multiplying e lements that need to be . There is still some room for improvement here ... |
25,617 | private void updateRemoveR ( ) { for ( int i = 1 ; i < n + 1 ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { double sum = 0 ; for ( int k = i - 1 ; k <= j ; k ++ ) { sum += U_tran . data [ i * m + k ] * R . data [ k * n + j ] ; } R . data [ ( i - 1 ) * n + j ] = sum ; } } } | Updates the R matrix to take in account the removed row . |
25,618 | public static void normalizeF ( DMatrixRMaj A ) { double val = normF ( A ) ; if ( val == 0 ) return ; int size = A . getNumElements ( ) ; for ( int i = 0 ; i < size ; i ++ ) { A . div ( i , val ) ; } } | Normalizes the matrix such that the Frobenius norm is equal to one . |
25,619 | public static double normP ( DMatrixRMaj A , double p ) { if ( p == 1 ) { return normP1 ( A ) ; } else if ( p == 2 ) { return normP2 ( A ) ; } else if ( Double . isInfinite ( p ) ) { return normPInf ( A ) ; } if ( MatrixFeatures_DDRM . isVector ( A ) ) { return elementP ( A , p ) ; } else { throw new IllegalArgumentException ( "Doesn't support induced norms yet." ) ; } } | Computes either the vector p - norm or the induced matrix p - norm depending on A being a vector or a matrix respectively . |
25,620 | public static double normP1 ( DMatrixRMaj A ) { if ( MatrixFeatures_DDRM . isVector ( A ) ) { return CommonOps_DDRM . elementSumAbs ( A ) ; } else { return inducedP1 ( A ) ; } } | Computes the p = 1 norm . If A is a matrix then the induced norm is computed . |
25,621 | public static double normP2 ( DMatrixRMaj A ) { if ( MatrixFeatures_DDRM . isVector ( A ) ) { return normF ( A ) ; } else { return inducedP2 ( A ) ; } } | Computes the p = 2 norm . If A is a matrix then the induced norm is computed . |
25,622 | public static double fastNormP2 ( DMatrixRMaj A ) { if ( MatrixFeatures_DDRM . isVector ( A ) ) { return fastNormF ( A ) ; } else { return inducedP2 ( A ) ; } } | Computes the p = 2 norm . If A is a matrix then the induced norm is computed . This implementation is faster but more prone to buffer overflow or underflow problems . |
25,623 | protected List < String > extractWords ( ) throws IOException { while ( true ) { lineNumber ++ ; String line = in . readLine ( ) ; if ( line == null ) { return null ; } if ( hasComment ) { if ( line . charAt ( 0 ) == comment ) continue ; } return parseWords ( line ) ; } } | Finds the next valid line of words in the stream and extracts them . |
25,624 | protected List < String > parseWords ( String line ) { List < String > words = new ArrayList < String > ( ) ; boolean insideWord = ! isSpace ( line . charAt ( 0 ) ) ; int last = 0 ; for ( int i = 0 ; i < line . length ( ) ; i ++ ) { char c = line . charAt ( i ) ; if ( insideWord ) { if ( isSpace ( c ) ) { words . add ( line . substring ( last , i ) ) ; insideWord = false ; } } else { if ( ! isSpace ( c ) ) { last = i ; insideWord = true ; } } } if ( insideWord ) { words . add ( line . substring ( last ) ) ; } return words ; } | Extracts the words from a string . Words are seperated by a space character . |
25,625 | public static double findMax ( double [ ] u , int startU , int length ) { double max = - 1 ; int index = startU * 2 ; int stopIndex = ( startU + length ) * 2 ; for ( ; index < stopIndex ; ) { double real = u [ index ++ ] ; double img = u [ index ++ ] ; double val = real * real + img * img ; if ( val > max ) { max = val ; } } return Math . sqrt ( max ) ; } | Returns the maximum magnitude of the complex numbers |
25,626 | public static void extractHouseholderColumn ( ZMatrixRMaj A , int row0 , int row1 , int col , double u [ ] , int offsetU ) { int indexU = ( row0 + offsetU ) * 2 ; u [ indexU ++ ] = 1 ; u [ indexU ++ ] = 0 ; for ( int row = row0 + 1 ; row < row1 ; row ++ ) { int indexA = A . getIndex ( row , col ) ; u [ indexU ++ ] = A . data [ indexA ] ; u [ indexU ++ ] = A . data [ indexA + 1 ] ; } } | Extracts a house holder vector from the column of A and stores it in u |
25,627 | public static void extractHouseholderRow ( ZMatrixRMaj A , int row , int col0 , int col1 , double u [ ] , int offsetU ) { int indexU = ( offsetU + col0 ) * 2 ; u [ indexU ] = 1 ; u [ indexU + 1 ] = 0 ; int indexA = ( row * A . numCols + ( col0 + 1 ) ) * 2 ; System . arraycopy ( A . data , indexA , u , indexU + 2 , ( col1 - col0 - 1 ) * 2 ) ; } | Extracts a house holder vector from the rows of A and stores it in u |
25,628 | public static double extractColumnAndMax ( ZMatrixRMaj A , int row0 , int row1 , int col , double u [ ] , int offsetU ) { int indexU = ( offsetU + row0 ) * 2 ; double max = 0 ; int indexA = A . getIndex ( row0 , col ) ; double h [ ] = A . data ; for ( int i = row0 ; i < row1 ; i ++ , indexA += A . numCols * 2 ) { double realVal = u [ indexU ++ ] = h [ indexA ] ; double imagVal = u [ indexU ++ ] = h [ indexA + 1 ] ; double magVal = realVal * realVal + imagVal * imagVal ; if ( max < magVal ) { max = magVal ; } } return Math . sqrt ( max ) ; } | Extracts the column of A and copies it into u while computing the magnitude of the largest element and returning it . |
25,629 | public static double computeRowMax ( ZMatrixRMaj A , int row , int col0 , int col1 ) { double max = 0 ; int indexA = A . getIndex ( row , col0 ) ; double h [ ] = A . data ; for ( int i = col0 ; i < col1 ; i ++ ) { double realVal = h [ indexA ++ ] ; double imagVal = h [ indexA ++ ] ; double magVal = realVal * realVal + imagVal * imagVal ; if ( max < magVal ) { max = magVal ; } } return Math . sqrt ( max ) ; } | Finds the magnitude of the largest element in the row |
25,630 | public static ZMatrixRMaj hermitian ( int length , double min , double max , Random rand ) { ZMatrixRMaj A = new ZMatrixRMaj ( length , length ) ; fillHermitian ( A , min , max , rand ) ; return A ; } | Creates a random Hermitian matrix with elements from min to max value . |
25,631 | public static void fillHermitian ( ZMatrixRMaj A , double min , double max , Random rand ) { if ( A . numRows != A . numCols ) throw new IllegalArgumentException ( "A must be a square matrix" ) ; double range = max - min ; int length = A . numRows ; for ( int i = 0 ; i < length ; i ++ ) { A . set ( i , i , rand . nextDouble ( ) * range + min , 0 ) ; for ( int j = i + 1 ; j < length ; j ++ ) { double real = rand . nextDouble ( ) * range + min ; double imaginary = rand . nextDouble ( ) * range + min ; A . set ( i , j , real , imaginary ) ; A . set ( j , i , real , - imaginary ) ; } } } | Assigns the provided square matrix to be a random Hermitian matrix with elements from min to max value . |
25,632 | public static SimpleMatrix wrap ( Matrix internalMat ) { SimpleMatrix ret = new SimpleMatrix ( ) ; ret . setMatrix ( internalMat ) ; return ret ; } | Creates a new SimpleMatrix with the specified DMatrixRMaj used as its internal matrix . This means that the reference is saved and calls made to the returned SimpleMatrix will modify the passed in DMatrixRMaj . |
25,633 | public static SimpleMatrix diag ( Class type , double ... vals ) { SimpleMatrix M = new SimpleMatrix ( vals . length , vals . length , type ) ; for ( int i = 0 ; i < vals . length ; i ++ ) { M . set ( i , i , vals [ i ] ) ; } return M ; } | Creates a real valued diagonal matrix of the specified type |
25,634 | public static void convert ( DMatrixD1 input , ZMatrixD1 output ) { if ( input . numCols != output . numCols || input . numRows != output . numRows ) { throw new IllegalArgumentException ( "The matrices are not all the same dimension." ) ; } Arrays . fill ( output . data , 0 , output . getDataLength ( ) , 0 ) ; final int length = output . getDataLength ( ) ; for ( int i = 0 ; i < length ; i += 2 ) { output . data [ i ] = input . data [ i / 2 ] ; } } | Converts the real matrix into a complex matrix . |
25,635 | public static DMatrixRMaj stripReal ( ZMatrixD1 input , DMatrixRMaj output ) { if ( output == null ) { output = new DMatrixRMaj ( input . numRows , input . numCols ) ; } else if ( input . numCols != output . numCols || input . numRows != output . numRows ) { throw new IllegalArgumentException ( "The matrices are not all the same dimension." ) ; } final int length = input . getDataLength ( ) ; for ( int i = 0 ; i < length ; i += 2 ) { output . data [ i / 2 ] = input . data [ i ] ; } return output ; } | Places the real component of the input matrix into the output matrix . |
25,636 | public static DMatrixRMaj convert ( DMatrixRBlock src , DMatrixRMaj dst ) { return ConvertDMatrixStruct . convert ( src , dst ) ; } | Converts a row major block matrix into a row major matrix . |
25,637 | public static void convertTranSrc ( DMatrixRMaj src , DMatrixRBlock dst ) { if ( src . numRows != dst . numCols || src . numCols != dst . numRows ) throw new IllegalArgumentException ( "Incompatible matrix shapes." ) ; for ( int i = 0 ; i < dst . numRows ; i += dst . blockLength ) { int blockHeight = Math . min ( dst . blockLength , dst . numRows - i ) ; for ( int j = 0 ; j < dst . numCols ; j += dst . blockLength ) { int blockWidth = Math . min ( dst . blockLength , dst . numCols - j ) ; int indexDst = i * dst . numCols + blockHeight * j ; int indexSrc = j * src . numCols + i ; for ( int l = 0 ; l < blockWidth ; l ++ ) { int rowSrc = indexSrc + l * src . numCols ; int rowDst = indexDst + l ; for ( int k = 0 ; k < blockHeight ; k ++ , rowDst += blockWidth ) { dst . data [ rowDst ] = src . data [ rowSrc ++ ] ; } } } } } | Converts the transpose of a row major matrix into a row major block matrix . |
25,638 | public static DMatrixRBlock transpose ( DMatrixRBlock A , DMatrixRBlock A_tran ) { if ( A_tran != null ) { if ( A . numRows != A_tran . numCols || A . numCols != A_tran . numRows ) throw new IllegalArgumentException ( "Incompatible dimensions." ) ; if ( A . blockLength != A_tran . blockLength ) throw new IllegalArgumentException ( "Incompatible block size." ) ; } else { A_tran = new DMatrixRBlock ( A . numCols , A . numRows , A . blockLength ) ; } for ( int i = 0 ; i < A . numRows ; i += A . blockLength ) { int blockHeight = Math . min ( A . blockLength , A . numRows - i ) ; for ( int j = 0 ; j < A . numCols ; j += A . blockLength ) { int blockWidth = Math . min ( A . blockLength , A . numCols - j ) ; int indexA = i * A . numCols + blockHeight * j ; int indexC = j * A_tran . numCols + blockWidth * i ; transposeBlock ( A , A_tran , indexA , indexC , blockWidth , blockHeight ) ; } } return A_tran ; } | Transposes a block matrix . |
25,639 | private static void transposeBlock ( DMatrixRBlock A , DMatrixRBlock A_tran , int indexA , int indexC , int width , int height ) { for ( int i = 0 ; i < height ; i ++ ) { int rowIndexC = indexC + i ; int rowIndexA = indexA + width * i ; int end = rowIndexA + width ; for ( ; rowIndexA < end ; rowIndexC += height , rowIndexA ++ ) { A_tran . data [ rowIndexC ] = A . data [ rowIndexA ] ; } } } | Transposes an individual block inside a block matrix . |
25,640 | public static void zeroTriangle ( boolean upper , DMatrixRBlock A ) { int blockLength = A . blockLength ; if ( upper ) { for ( int i = 0 ; i < A . numRows ; i += blockLength ) { int h = Math . min ( blockLength , A . numRows - i ) ; for ( int j = i ; j < A . numCols ; j += blockLength ) { int w = Math . min ( blockLength , A . numCols - j ) ; int index = i * A . numCols + h * j ; if ( j == i ) { for ( int k = 0 ; k < h ; k ++ ) { for ( int l = k + 1 ; l < w ; l ++ ) { A . data [ index + w * k + l ] = 0 ; } } } else { for ( int k = 0 ; k < h ; k ++ ) { for ( int l = 0 ; l < w ; l ++ ) { A . data [ index + w * k + l ] = 0 ; } } } } } } else { for ( int i = 0 ; i < A . numRows ; i += blockLength ) { int h = Math . min ( blockLength , A . numRows - i ) ; for ( int j = 0 ; j <= i ; j += blockLength ) { int w = Math . min ( blockLength , A . numCols - j ) ; int index = i * A . numCols + h * j ; if ( j == i ) { for ( int k = 0 ; k < h ; k ++ ) { int z = Math . min ( k , w ) ; for ( int l = 0 ; l < z ; l ++ ) { A . data [ index + w * k + l ] = 0 ; } } } else { for ( int k = 0 ; k < h ; k ++ ) { for ( int l = 0 ; l < w ; l ++ ) { A . data [ index + w * k + l ] = 0 ; } } } } } } } | Sets either the upper or low triangle of a matrix to zero |
25,641 | public static boolean blockAligned ( int blockLength , DSubmatrixD1 A ) { if ( A . col0 % blockLength != 0 ) return false ; if ( A . row0 % blockLength != 0 ) return false ; if ( A . col1 % blockLength != 0 && A . col1 != A . original . numCols ) { return false ; } if ( A . row1 % blockLength != 0 && A . row1 != A . original . numRows ) { return false ; } return true ; } | Checks to see if the submatrix has its boundaries along inner blocks . |
25,642 | private void makeSingularPositive ( ) { numSingular = qralg . getNumberOfSingularValues ( ) ; singularValues = qralg . getSingularValues ( ) ; for ( int i = 0 ; i < numSingular ; i ++ ) { double val = singularValues [ i ] ; if ( val < 0 ) { singularValues [ i ] = - val ; if ( computeU ) { int start = i * Ut . numCols ; int stop = start + Ut . numCols ; for ( int j = start ; j < stop ; j ++ ) { Ut . data [ j ] = - Ut . data [ j ] ; } } } } } | With the QR algorithm it is possible for the found singular values to be native . This makes them all positive by multiplying it by a diagonal matrix that has |
25,643 | public void fit ( double samplePoints [ ] , double [ ] observations ) { y . reshape ( observations . length , 1 , false ) ; System . arraycopy ( observations , 0 , y . data , 0 , observations . length ) ; A . reshape ( y . numRows , coef . numRows , false ) ; for ( int i = 0 ; i < observations . length ; i ++ ) { double obs = 1 ; for ( int j = 0 ; j < coef . numRows ; j ++ ) { A . set ( i , j , obs ) ; obs *= samplePoints [ i ] ; } } if ( ! solver . setA ( A ) ) throw new RuntimeException ( "Solver failed" ) ; solver . solve ( y , coef ) ; } | Computes the best fit set of polynomial coefficients to the provided observations . |
25,644 | public void removeWorstFit ( ) { int worstIndex = - 1 ; double worstError = - 1 ; for ( int i = 0 ; i < y . numRows ; i ++ ) { double predictedObs = 0 ; for ( int j = 0 ; j < coef . numRows ; j ++ ) { predictedObs += A . get ( i , j ) * coef . get ( j , 0 ) ; } double error = Math . abs ( predictedObs - y . get ( i , 0 ) ) ; if ( error > worstError ) { worstError = error ; worstIndex = i ; } } if ( worstIndex == - 1 ) return ; removeObservation ( worstIndex ) ; solver . removeRowFromA ( worstIndex ) ; solver . solve ( y , coef ) ; } | Removes the observation that fits the model the worst and recomputes the coefficients . This is done efficiently by using an adjustable solver . Often times the elements with the largest errors are outliers and not part of the system being modeled . By removing them a more accurate set of coefficients can be computed . |
25,645 | private void removeObservation ( int index ) { final int N = y . numRows - 1 ; final double d [ ] = y . data ; for ( int i = index ; i < N ; i ++ ) { d [ i ] = d [ i + 1 ] ; } y . numRows -- ; } | Removes an element from the observation matrix . |
25,646 | public static ZMatrixRMaj householderVector ( ZMatrixRMaj x ) { ZMatrixRMaj u = x . copy ( ) ; double max = CommonOps_ZDRM . elementMaxAbs ( u ) ; CommonOps_ZDRM . elementDivide ( u , max , 0 , u ) ; double nx = NormOps_ZDRM . normF ( u ) ; Complex_F64 c = new Complex_F64 ( ) ; u . get ( 0 , 0 , c ) ; double realTau , imagTau ; if ( c . getMagnitude ( ) == 0 ) { realTau = nx ; imagTau = 0 ; } else { realTau = c . real / c . getMagnitude ( ) * nx ; imagTau = c . imaginary / c . getMagnitude ( ) * nx ; } u . set ( 0 , 0 , c . real + realTau , c . imaginary + imagTau ) ; CommonOps_ZDRM . elementDivide ( u , u . getReal ( 0 , 0 ) , u . getImag ( 0 , 0 ) , u ) ; return u ; } | Computes the householder vector used in QR decomposition . |
25,647 | public boolean decompose ( ZMatrixRMaj A ) { if ( A . numRows != A . numCols ) throw new IllegalArgumentException ( "A must be square." ) ; if ( A . numRows <= 0 ) return false ; QH = A ; N = A . numCols ; if ( b . length < N * 2 ) { b = new double [ N * 2 ] ; gammas = new double [ N ] ; u = new double [ N * 2 ] ; } return _decompose ( ) ; } | Computes the decomposition of the provided matrix . If no errors are detected then true is returned false otherwise . |
25,648 | public DMatrixRMaj getA ( ) { if ( A . data . length < numRows * numCols ) { A = new DMatrixRMaj ( numRows , numCols ) ; } A . reshape ( numRows , numCols , false ) ; CommonOps_DDRM . mult ( Q , R , A ) ; return A ; } | Compute the A matrix from the Q and R matrices . |
25,649 | public void set ( T a ) { if ( a . getType ( ) == getType ( ) ) mat . set ( a . getMatrix ( ) ) ; else { setMatrix ( a . mat . copy ( ) ) ; } } | Sets the elements in this matrix to be equal to the elements in the passed in matrix . Both matrix must have the same dimension . |
25,650 | public void set ( int row , int col , double value ) { ops . set ( mat , row , col , value ) ; } | Assigns the element in the Matrix to the specified value . Performs a bounds check to make sure the requested element is part of the matrix . |
25,651 | public void set ( int index , double value ) { if ( mat . getType ( ) == MatrixType . DDRM ) { ( ( DMatrixRMaj ) mat ) . set ( index , value ) ; } else if ( mat . getType ( ) == MatrixType . FDRM ) { ( ( FMatrixRMaj ) mat ) . set ( index , ( float ) value ) ; } else { throw new RuntimeException ( "Not supported yet for this matrix type" ) ; } } | Assigns an element a value based on its index in the internal array .. |
25,652 | public void set ( int row , int col , double real , double imaginary ) { if ( imaginary == 0 ) { set ( row , col , real ) ; } else { ops . set ( mat , row , col , real , imaginary ) ; } } | Used to set the complex value of a matrix element . |
25,653 | public double get ( int index ) { MatrixType type = mat . getType ( ) ; if ( type . isReal ( ) ) { if ( type . getBits ( ) == 64 ) { return ( ( DMatrixRMaj ) mat ) . data [ index ] ; } else { return ( ( FMatrixRMaj ) mat ) . data [ index ] ; } } else { throw new IllegalArgumentException ( "Complex matrix. Call get(int,Complex64F) instead" ) ; } } | Returns the value of the matrix at the specified index of the 1D row major array . |
25,654 | public void get ( int row , int col , Complex_F64 output ) { ops . get ( mat , row , col , output ) ; } | Used to get the complex value of a matrix element . |
25,655 | public T copy ( ) { T ret = createLike ( ) ; ret . getMatrix ( ) . set ( this . getMatrix ( ) ) ; return ret ; } | Creates and returns a matrix which is idential to this one . |
25,656 | public boolean isIdentical ( T a , double tol ) { if ( a . getType ( ) != getType ( ) ) return false ; return ops . isIdentical ( mat , a . mat , tol ) ; } | Checks to see if matrix a is the same as this matrix within the specified tolerance . |
25,657 | public boolean isInBounds ( int row , int col ) { return row >= 0 && col >= 0 && row < mat . getNumRows ( ) && col < mat . getNumCols ( ) ; } | Returns true of the specified matrix element is valid element inside this matrix . |
25,658 | public void convertToSparse ( ) { switch ( mat . getType ( ) ) { case DDRM : { DMatrixSparseCSC m = new DMatrixSparseCSC ( mat . getNumRows ( ) , mat . getNumCols ( ) ) ; ConvertDMatrixStruct . convert ( ( DMatrixRMaj ) mat , m , 0 ) ; setMatrix ( m ) ; } break ; case FDRM : { FMatrixSparseCSC m = new FMatrixSparseCSC ( mat . getNumRows ( ) , mat . getNumCols ( ) ) ; ConvertFMatrixStruct . convert ( ( FMatrixRMaj ) mat , m , 0 ) ; setMatrix ( m ) ; } break ; case DSCC : case FSCC : break ; default : throw new RuntimeException ( "Conversion not supported!" ) ; } } | Switches from a dense to sparse matrix |
25,659 | public void convertToDense ( ) { switch ( mat . getType ( ) ) { case DSCC : { DMatrix m = new DMatrixRMaj ( mat . getNumRows ( ) , mat . getNumCols ( ) ) ; ConvertDMatrixStruct . convert ( ( DMatrix ) mat , m ) ; setMatrix ( m ) ; } break ; case FSCC : { FMatrix m = new FMatrixRMaj ( mat . getNumRows ( ) , mat . getNumCols ( ) ) ; ConvertFMatrixStruct . convert ( ( FMatrix ) mat , m ) ; setMatrix ( m ) ; } break ; case DDRM : case FDRM : case ZDRM : case CDRM : break ; default : throw new RuntimeException ( "Not a sparse matrix!" ) ; } } | Switches from a sparse to dense matrix |
25,660 | private static void multBlockAdd ( double [ ] blockA , double [ ] blockB , double [ ] blockC , final int m , final int n , final int o , final int blockLength ) { for ( int k = 0 ; k < n ; k ++ ) { int rowB = k * blockLength ; int endB = rowB + o ; for ( int i = 0 ; i < m ; i ++ ) { int indexC = i * blockLength ; double valA = blockA [ indexC + k ] ; int indexB = rowB ; while ( indexB != endB ) { blockC [ indexC ++ ] += valA * blockB [ indexB ++ ] ; } } } } | Performs a matrix multiplication between inner block matrices . |
25,661 | public void _solveVectorInternal ( double [ ] vv ) { int ii = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int ip = indx [ i ] ; double sum = vv [ ip ] ; vv [ ip ] = vv [ i ] ; if ( ii != 0 ) { int index = i * n + ii - 1 ; for ( int j = ii - 1 ; j < i ; j ++ ) sum -= dataLU [ index ++ ] * vv [ j ] ; } else if ( sum != 0.0 ) { ii = i + 1 ; } vv [ i ] = sum ; } TriangularSolver_DDRM . solveU ( dataLU , vv , n ) ; } | a specialized version of solve that avoid additional checks that are not needed . |
25,662 | protected void resize ( VariableMatrix mat , int numRows , int numCols ) { if ( mat . isTemp ( ) ) { mat . matrix . reshape ( numRows , numCols ) ; } } | If the variable is a local temporary variable it will be resized so that the operation can complete . If not temporary then it will not be reshaped |
25,663 | public static Info neg ( final Variable A , ManagerTempVariables manager ) { Info ret = new Info ( ) ; if ( A instanceof VariableInteger ) { final VariableInteger output = manager . createInteger ( ) ; ret . output = output ; ret . op = new Operation ( "neg-i" ) { public void process ( ) { output . value = - ( ( VariableInteger ) A ) . value ; } } ; } else if ( A instanceof VariableScalar ) { final VariableDouble output = manager . createDouble ( ) ; ret . output = output ; ret . op = new Operation ( "neg-s" ) { public void process ( ) { output . value = - ( ( VariableScalar ) A ) . getDouble ( ) ; } } ; } else if ( A instanceof VariableMatrix ) { final VariableMatrix output = manager . createMatrix ( ) ; ret . output = output ; ret . op = new Operation ( "neg-m" ) { public void process ( ) { DMatrixRMaj a = ( ( VariableMatrix ) A ) . matrix ; output . matrix . reshape ( a . numRows , a . numCols ) ; CommonOps_DDRM . changeSign ( a , output . matrix ) ; } } ; } else { throw new RuntimeException ( "Unsupported variable " + A ) ; } return ret ; } | Returns the negative of the input variable |
25,664 | public static Info eye ( final Variable A , ManagerTempVariables manager ) { Info ret = new Info ( ) ; final VariableMatrix output = manager . createMatrix ( ) ; ret . output = output ; if ( A instanceof VariableMatrix ) { ret . op = new Operation ( "eye-m" ) { public void process ( ) { DMatrixRMaj mA = ( ( VariableMatrix ) A ) . matrix ; output . matrix . reshape ( mA . numRows , mA . numCols ) ; CommonOps_DDRM . setIdentity ( output . matrix ) ; } } ; } else if ( A instanceof VariableInteger ) { ret . op = new Operation ( "eye-i" ) { public void process ( ) { int N = ( ( VariableInteger ) A ) . value ; output . matrix . reshape ( N , N ) ; CommonOps_DDRM . setIdentity ( output . matrix ) ; } } ; } else { throw new RuntimeException ( "Unsupported variable type " + A ) ; } return ret ; } | Returns an identity matrix |
25,665 | public static Info ones ( final Variable A , final Variable B , ManagerTempVariables manager ) { Info ret = new Info ( ) ; final VariableMatrix output = manager . createMatrix ( ) ; ret . output = output ; if ( A instanceof VariableInteger && B instanceof VariableInteger ) { ret . op = new Operation ( "ones-ii" ) { public void process ( ) { int numRows = ( ( VariableInteger ) A ) . value ; int numCols = ( ( VariableInteger ) B ) . value ; output . matrix . reshape ( numRows , numCols ) ; CommonOps_DDRM . fill ( output . matrix , 1 ) ; } } ; } else { throw new RuntimeException ( "Expected two integers got " + A + " " + B ) ; } return ret ; } | Returns a matrix full of ones |
25,666 | public static Info rng ( final Variable A , ManagerTempVariables manager ) { Info ret = new Info ( ) ; if ( A instanceof VariableInteger ) { ret . op = new Operation ( "rng" ) { public void process ( ) { int seed = ( ( VariableInteger ) A ) . value ; manager . getRandom ( ) . setSeed ( seed ) ; } } ; } else { throw new RuntimeException ( "Expected one integer" ) ; } return ret ; } | Sets the seed for random number generator |
25,667 | public static Info rand ( final Variable A , final Variable B , ManagerTempVariables manager ) { Info ret = new Info ( ) ; final VariableMatrix output = manager . createMatrix ( ) ; ret . output = output ; if ( A instanceof VariableInteger && B instanceof VariableInteger ) { ret . op = new Operation ( "rand-ii" ) { public void process ( ) { int numRows = ( ( VariableInteger ) A ) . value ; int numCols = ( ( VariableInteger ) B ) . value ; output . matrix . reshape ( numRows , numCols ) ; RandomMatrices_DDRM . fillUniform ( output . matrix , 0 , 1 , manager . getRandom ( ) ) ; } } ; } else { throw new RuntimeException ( "Expected two integers got " + A + " " + B ) ; } return ret ; } | Uniformly random numbers |
25,668 | private static boolean extractSimpleExtents ( Variable var , Extents e , boolean row , int length ) { int lower ; int upper ; if ( var . getType ( ) == VariableType . INTEGER_SEQUENCE ) { IntegerSequence sequence = ( ( VariableIntegerSequence ) var ) . sequence ; if ( sequence . getType ( ) == IntegerSequence . Type . FOR ) { IntegerSequence . For seqFor = ( IntegerSequence . For ) sequence ; seqFor . initialize ( length ) ; if ( seqFor . getStep ( ) == 1 ) { lower = seqFor . getStart ( ) ; upper = seqFor . getEnd ( ) ; } else { return false ; } } else { return false ; } } else if ( var . getType ( ) == VariableType . SCALAR ) { lower = upper = ( ( VariableInteger ) var ) . value ; } else { throw new RuntimeException ( "How did a bad variable get put here?!?!" ) ; } if ( row ) { e . row0 = lower ; e . row1 = upper ; } else { e . col0 = lower ; e . col1 = upper ; } return true ; } | See if a simple sequence can be used to extract the array . A simple extent is a continuous block from a min to max index |
25,669 | public Token add ( Function function ) { Token t = new Token ( function ) ; push ( t ) ; return t ; } | Adds a function to the end of the token list |
25,670 | public Token add ( Variable variable ) { Token t = new Token ( variable ) ; push ( t ) ; return t ; } | Adds a variable to the end of the token list |
25,671 | public Token add ( Symbol symbol ) { Token t = new Token ( symbol ) ; push ( t ) ; return t ; } | Adds a symbol to the end of the token list |
25,672 | public Token add ( String word ) { Token t = new Token ( word ) ; push ( t ) ; return t ; } | Adds a word to the end of the token list |
25,673 | public void push ( Token token ) { size ++ ; if ( first == null ) { first = token ; last = token ; token . previous = null ; token . next = null ; } else { last . next = token ; token . previous = last ; token . next = null ; last = token ; } } | Adds a new Token to the end of the linked list |
25,674 | public void insert ( Token where , Token token ) { if ( where == null ) { if ( size == 0 ) push ( token ) ; else { first . previous = token ; token . previous = null ; token . next = first ; first = token ; size ++ ; } } else if ( where == last || null == last ) { push ( token ) ; } else { token . next = where . next ; token . previous = where ; where . next . previous = token ; where . next = token ; size ++ ; } } | Inserts token after where . if where is null then it is inserted to the beginning of the list . |
25,675 | public void remove ( Token token ) { if ( token == first ) { first = first . next ; } if ( token == last ) { last = last . previous ; } if ( token . next != null ) { token . next . previous = token . previous ; } if ( token . previous != null ) { token . previous . next = token . next ; } token . next = token . previous = null ; size -- ; } | Removes the token from the list |
25,676 | public void replace ( Token original , Token target ) { if ( first == original ) first = target ; if ( last == original ) last = target ; target . next = original . next ; target . previous = original . previous ; if ( original . next != null ) original . next . previous = target ; if ( original . previous != null ) original . previous . next = target ; original . next = original . previous = null ; } | Removes original and places target at the same location |
25,677 | public TokenList extractSubList ( Token begin , Token end ) { if ( begin == end ) { remove ( begin ) ; return new TokenList ( begin , begin ) ; } else { if ( first == begin ) { first = end . next ; } if ( last == end ) { last = begin . previous ; } if ( begin . previous != null ) { begin . previous . next = end . next ; } if ( end . next != null ) { end . next . previous = begin . previous ; } begin . previous = null ; end . next = null ; TokenList ret = new TokenList ( begin , end ) ; size -= ret . size ( ) ; return ret ; } } | Removes elements from begin to end from the list inclusive . Returns a new list which is composed of the removed elements |
25,678 | public void insertAfter ( Token before , TokenList list ) { Token after = before . next ; before . next = list . first ; list . first . previous = before ; if ( after == null ) { last = list . last ; } else { after . previous = list . last ; list . last . next = after ; } size += list . size ; } | Inserts the LokenList immediately following the before token |
25,679 | public static int isValid ( DMatrixRMaj cov ) { if ( ! MatrixFeatures_DDRM . isDiagonalPositive ( cov ) ) return 1 ; if ( ! MatrixFeatures_DDRM . isSymmetric ( cov , TOL ) ) return 2 ; if ( ! MatrixFeatures_DDRM . isPositiveSemidefinite ( cov ) ) return 3 ; return 0 ; } | Performs a variety of tests to see if the provided matrix is a valid covariance matrix . |
25,680 | public static boolean invert ( final DMatrixRMaj cov , final DMatrixRMaj cov_inv ) { if ( cov . numCols <= 4 ) { if ( cov . numCols != cov . numRows ) { throw new IllegalArgumentException ( "Must be a square matrix." ) ; } if ( cov . numCols >= 2 ) UnrolledInverseFromMinor_DDRM . inv ( cov , cov_inv ) ; else cov_inv . data [ 0 ] = 1.0 / cov . data [ 0 ] ; } else { LinearSolverDense < DMatrixRMaj > solver = LinearSolverFactory_DDRM . symmPosDef ( cov . numRows ) ; solver = new LinearSolverSafe < DMatrixRMaj > ( solver ) ; if ( ! solver . setA ( cov ) ) return false ; solver . invert ( cov_inv ) ; } return true ; } | Performs a matrix inversion operations that takes advantage of the special properties of a covariance matrix . |
25,681 | public int sum ( ) { int total = 0 ; int N = getNumElements ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( data [ i ] ) total += 1 ; } return total ; } | Returns the total number of elements which are true . |
25,682 | protected void init ( DMatrixRMaj A ) { UBV = A ; m = UBV . numRows ; n = UBV . numCols ; min = Math . min ( m , n ) ; int max = Math . max ( m , n ) ; if ( b . length < max + 1 ) { b = new double [ max + 1 ] ; u = new double [ max + 1 ] ; } if ( gammasU . length < m ) { gammasU = new double [ m ] ; } if ( gammasV . length < n ) { gammasV = new double [ n ] ; } } | Sets up internal data structures and creates a copy of the input matrix . |
25,683 | public DMatrixRMaj getU ( DMatrixRMaj U , boolean transpose , boolean compact ) { U = handleU ( U , transpose , compact , m , n , min ) ; CommonOps_DDRM . setIdentity ( U ) ; for ( int i = 0 ; i < m ; i ++ ) u [ i ] = 0 ; for ( int j = min - 1 ; j >= 0 ; j -- ) { u [ j ] = 1 ; for ( int i = j + 1 ; i < m ; i ++ ) { u [ i ] = UBV . get ( i , j ) ; } if ( transpose ) QrHelperFunctions_DDRM . rank1UpdateMultL ( U , u , gammasU [ j ] , j , j , m ) ; else QrHelperFunctions_DDRM . rank1UpdateMultR ( U , u , gammasU [ j ] , j , j , m , this . b ) ; } return U ; } | Returns the orthogonal U matrix . |
25,684 | public DMatrixRMaj getV ( DMatrixRMaj V , boolean transpose , boolean compact ) { V = handleV ( V , transpose , compact , m , n , min ) ; CommonOps_DDRM . setIdentity ( V ) ; for ( int j = min - 1 ; j >= 0 ; j -- ) { u [ j + 1 ] = 1 ; for ( int i = j + 2 ; i < n ; i ++ ) { u [ i ] = UBV . get ( j , i ) ; } if ( transpose ) QrHelperFunctions_DDRM . rank1UpdateMultL ( V , u , gammasV [ j ] , j + 1 , j + 1 , n ) ; else QrHelperFunctions_DDRM . rank1UpdateMultR ( V , u , gammasV [ j ] , j + 1 , j + 1 , n , this . b ) ; } return V ; } | Returns the orthogonal V matrix . |
25,685 | public static < S extends Matrix , D extends Matrix > LinearSolver < S , D > safe ( LinearSolver < S , D > solver ) { if ( solver . modifiesA ( ) || solver . modifiesB ( ) ) { if ( solver instanceof LinearSolverDense ) { return new LinearSolverSafe ( ( LinearSolverDense ) solver ) ; } else if ( solver instanceof LinearSolverSparse ) { return new LinearSolverSparseSafe ( ( LinearSolverSparse ) solver ) ; } else { throw new IllegalArgumentException ( "Unknown solver type" ) ; } } else { return solver ; } } | Wraps a linear solver of any type with a safe solver the ensures inputs are not modified |
25,686 | public static String fancyStringF ( double value , DecimalFormat format , int length , int significant ) { String formatted = fancyString ( value , format , length , significant ) ; int n = length - formatted . length ( ) ; if ( n > 0 ) { StringBuilder builder = new StringBuilder ( n ) ; for ( int i = 0 ; i < n ; i ++ ) { builder . append ( ' ' ) ; } return formatted + builder . toString ( ) ; } else { return formatted ; } } | Fixed length fancy formatting for doubles . If possible decimal notation is used . If all the significant digits can t be shown then it will switch to exponential notation . If not all the space is needed then it will be filled in to ensure it has the specified length . |
25,687 | private void performDynamicStep ( ) { if ( findingZeros ) { if ( steps > 6 ) { findingZeros = false ; } else { double scale = computeBulgeScale ( ) ; performImplicitSingleStep ( scale , 0 , false ) ; } } else { double scale = computeBulgeScale ( ) ; double lambda = selectWilkinsonShift ( scale ) ; performImplicitSingleStep ( scale , lambda , false ) ; } } | Here the lambda in the implicit step is determined dynamically . At first it selects zeros to quickly reveal singular values that are zero or close to zero . Then it computes it using a Wilkinson shift . |
25,688 | private void performScriptedStep ( ) { double scale = computeBulgeScale ( ) ; if ( steps > giveUpOnKnown ) { followScript = false ; } else { double s = values [ x2 ] / scale ; performImplicitSingleStep ( scale , s * s , false ) ; } } | Shifts are performed based upon singular values computed previously . If it does not converge using one of those singular values it uses a Wilkinson shift instead . |
25,689 | public boolean nextSplit ( ) { if ( numSplits == 0 ) return false ; x2 = splits [ -- numSplits ] ; if ( numSplits > 0 ) x1 = splits [ numSplits - 1 ] + 1 ; else x1 = 0 ; return true ; } | Tells it to process the submatrix at the next split . Should be called after the current submatrix has been processed . |
25,690 | public void performImplicitSingleStep ( double scale , double lambda , boolean byAngle ) { createBulge ( x1 , lambda , scale , byAngle ) ; for ( int i = x1 ; i < x2 - 1 && bulge != 0.0 ; i ++ ) { removeBulgeLeft ( i , true ) ; if ( bulge == 0 ) break ; removeBulgeRight ( i ) ; } if ( bulge != 0 ) removeBulgeLeft ( x2 - 1 , false ) ; incrementSteps ( ) ; } | Given the lambda value perform an implicit QR step on the matrix . |
25,691 | protected void updateRotator ( DMatrixRMaj Q , int m , int n , double c , double s ) { int rowA = m * Q . numCols ; int rowB = n * Q . numCols ; int endA = rowA + Q . numCols ; for ( ; rowA != endA ; rowA ++ , rowB ++ ) { double a = Q . get ( rowA ) ; double b = Q . get ( rowB ) ; Q . set ( rowA , c * a + s * b ) ; Q . set ( rowB , - s * a + c * b ) ; } } | Multiplied a transpose orthogonal matrix Q by the specified rotator . This is used to update the U and V matrices . Updating the transpose of the matrix is faster since it only modifies the rows . |
25,692 | protected boolean checkForAndHandleZeros ( ) { for ( int i = x2 - 1 ; i >= x1 ; i -- ) { if ( isOffZero ( i ) ) { resetSteps ( ) ; splits [ numSplits ++ ] = i ; x1 = i + 1 ; return true ; } } for ( int i = x2 - 1 ; i >= x1 ; i -- ) { if ( isDiagonalZero ( i ) ) { pushRight ( i ) ; resetSteps ( ) ; splits [ numSplits ++ ] = i ; x1 = i + 1 ; return true ; } } return false ; } | Checks to see if either the diagonal element or off diagonal element is zero . If one is then it performs a split or pushes it off the matrix . |
25,693 | private void pushRight ( int row ) { if ( isOffZero ( row ) ) return ; rotatorPushRight ( row ) ; int end = N - 2 - row ; for ( int i = 0 ; i < end && bulge != 0 ; i ++ ) { rotatorPushRight2 ( row , i + 2 ) ; } } | If there is a zero on the diagonal element the off diagonal element needs pushed off so that all the algorithms assumptions are two and so that it can split the matrix . |
25,694 | private void rotatorPushRight ( int m ) { double b11 = off [ m ] ; double b21 = diag [ m + 1 ] ; computeRotator ( b21 , - b11 ) ; off [ m ] = 0 ; diag [ m + 1 ] = b21 * c - b11 * s ; if ( m + 2 < N ) { double b22 = off [ m + 1 ] ; off [ m + 1 ] = b22 * c ; bulge = b22 * s ; } else { bulge = 0 ; } if ( Ut != null ) { updateRotator ( Ut , m , m + 1 , c , s ) ; } } | Start pushing the element off to the right . |
25,695 | private void rotatorPushRight2 ( int m , int offset ) { double b11 = bulge ; double b12 = diag [ m + offset ] ; computeRotator ( b12 , - b11 ) ; diag [ m + offset ] = b12 * c - b11 * s ; if ( m + offset < N - 1 ) { double b22 = off [ m + offset ] ; off [ m + offset ] = b22 * c ; bulge = b22 * s ; } if ( Ut != null ) { updateRotator ( Ut , m , m + offset , c , s ) ; } } | Used to finish up pushing the bulge off the matrix . |
25,696 | public void exceptionShift ( ) { numExceptional ++ ; double mag = 0.05 * numExceptional ; if ( mag > 1.0 ) mag = 1.0 ; double angle = 2.0 * UtilEjml . PI * ( rand . nextDouble ( ) - 0.5 ) * mag ; performImplicitSingleStep ( 0 , angle , true ) ; nextExceptional = steps + exceptionalThresh ; } | It is possible for the QR algorithm to get stuck in a loop because of symmetries . This happens more often with larger matrices . By taking a random step it can break the symmetry and finish . |
25,697 | private boolean computeUWV ( ) { bidiag . getDiagonal ( diag , off ) ; qralg . setMatrix ( numRowsT , numColsT , diag , off ) ; if ( computeU ) Ut = bidiag . getU ( Ut , true , compact ) ; if ( computeV ) Vt = bidiag . getV ( Vt , true , compact ) ; qralg . setFastValues ( false ) ; if ( computeU ) qralg . setUt ( Ut ) ; else qralg . setUt ( null ) ; if ( computeV ) qralg . setVt ( Vt ) ; else qralg . setVt ( null ) ; boolean ret = ! qralg . process ( ) ; return ret ; } | Compute singular values and U and V at the same time |
25,698 | private void makeSingularPositive ( ) { numSingular = qralg . getNumberOfSingularValues ( ) ; singularValues = qralg . getSingularValues ( ) ; for ( int i = 0 ; i < numSingular ; i ++ ) { double val = qralg . getSingularValue ( i ) ; if ( val < 0 ) { singularValues [ i ] = 0.0 - val ; if ( computeU ) { int start = i * Ut . numCols ; int stop = start + Ut . numCols ; for ( int j = start ; j < stop ; j ++ ) { Ut . set ( j , 0.0 - Ut . get ( j ) ) ; } } } else { singularValues [ i ] = val ; } } } | With the QR algorithm it is possible for the found singular values to be negative . This makes them all positive by multiplying it by a diagonal matrix that has |
25,699 | public static boolean checkDuplicateElements ( DMatrixSparseCSC A ) { A = A . copy ( ) ; A . sortIndices ( null ) ; return ! checkSortedFlag ( A ) ; } | Checks for duplicate elements . A is sorted |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.