idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
149,300
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 (...
Adjust submatrices and helper data structures for the input matrix . Must be called before the decomposition can be computed .
149,301
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 .
149,302
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 .
149,303
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 ( ) ) { setToInverse...
Sets the matrix inv equal to the inverse of the matrix that was decomposed .
149,304
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 .
149,305
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 ) { declareInternalDat...
Provides the results of a QR decomposition . These will be modified by adding or removing rows from the original A matrix .
149,306
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 ...
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 ...
149,307
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 .
149,308
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 .
149,309
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 IllegalArgumentExc...
Computes either the vector p - norm or the induced matrix p - norm depending on A being a vector or a matrix respectively .
149,310
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 .
149,311
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 .
149,312
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 .
149,313
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 .
149,314
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 (...
Extracts the words from a string . Words are seperated by a space character .
149,315
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...
Returns the maximum magnitude of the complex numbers
149,316
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 ...
Extracts a house holder vector from the column of A and stores it in u
149,317
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 , ( co...
Extracts a house holder vector from the rows of A and stores it in u
149,318
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 ) { doubl...
Extracts the column of A and copies it into u while computing the magnitude of the largest element and returning it .
149,319
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 + ...
Finds the magnitude of the largest element in the row
149,320
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 .
149,321
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 . nextD...
Assigns the provided square matrix to be a random Hermitian matrix with elements from min to max value .
149,322
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 .
149,323
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
149,324
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 i...
Converts the real matrix into a complex matrix .
149,325
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 al...
Places the real component of the input matrix into the output matrix .
149,326
public static DMatrixRMaj convert ( DMatrixRBlock src , DMatrixRMaj dst ) { return ConvertDMatrixStruct . convert ( src , dst ) ; }
Converts a row major block matrix into a row major matrix .
149,327
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 ....
Converts the transpose of a row major matrix into a row major block matrix .
149,328
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 IllegalArgumen...
Transposes a block matrix .
149,329
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 , rowIn...
Transposes an individual block inside a block matrix .
149,330
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 ( blockLeng...
Sets either the upper or low triangle of a matrix to zero
149,331
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 . or...
Checks to see if the submatrix has its boundaries along inner blocks .
149,332
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 ;...
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
149,333
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 ++ ) { doubl...
Computes the best fit set of polynomial coefficients to the provided observations .
149,334
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...
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 .
149,335
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 .
149,336
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 , ...
Computes the householder vector used in QR decomposition .
149,337
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 ] ; } re...
Computes the decomposition of the provided matrix . If no errors are detected then true is returned false otherwise .
149,338
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 .
149,339
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 .
149,340
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 .
149,341
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...
Assigns an element a value based on its index in the internal array ..
149,342
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 .
149,343
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,...
Returns the value of the matrix at the specified index of the 1D row major array .
149,344
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 .
149,345
public T copy ( ) { T ret = createLike ( ) ; ret . getMatrix ( ) . set ( this . getMatrix ( ) ) ; return ret ; }
Creates and returns a matrix which is idential to this one .
149,346
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 .
149,347
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 .
149,348
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 ...
Switches from a dense to sparse matrix
149,349
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 . getNum...
Switches from a sparse to dense matrix
149,350
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 ; doubl...
Performs a matrix multiplication between inner block matrices .
149,351
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 ) ...
a specialized version of solve that avoid additional checks that are not needed .
149,352
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
149,353
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 = - ( ( Variab...
Returns the negative of the input variable
149,354
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 = ( ( VariableMat...
Returns an identity matrix
149,355
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" ) { pub...
Returns a matrix full of ones
149,356
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...
Sets the seed for random number generator
149,357
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" ) { pub...
Uniformly random numbers
149,358
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 . ...
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
149,359
public Token add ( Function function ) { Token t = new Token ( function ) ; push ( t ) ; return t ; }
Adds a function to the end of the token list
149,360
public Token add ( Variable variable ) { Token t = new Token ( variable ) ; push ( t ) ; return t ; }
Adds a variable to the end of the token list
149,361
public Token add ( Symbol symbol ) { Token t = new Token ( symbol ) ; push ( t ) ; return t ; }
Adds a symbol to the end of the token list
149,362
public Token add ( String word ) { Token t = new Token ( word ) ; push ( t ) ; return t ; }
Adds a word to the end of the token list
149,363
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
149,364
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 ;...
Inserts token after where . if where is null then it is inserted to the beginning of the list .
149,365
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 . previou...
Removes the token from the list
149,366
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 ) or...
Removes original and places target at the same location
149,367
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 ...
Removes elements from begin to end from the list inclusive . Returns a new list which is composed of the removed elements
149,368
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
149,369
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 .
149,370
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 . ...
Performs a matrix inversion operations that takes advantage of the special properties of a covariance matrix .
149,371
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 .
149,372
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 . le...
Sets up internal data structures and creates a copy of the input matrix .
149,373
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 [...
Returns the orthogonal U matrix .
149,374
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 ( transpo...
Returns the orthogonal V matrix .
149,375
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 Linear...
Wraps a linear solver of any type with a safe solver the ensures inputs are not modified
149,376
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 ++ ...
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 .
149,377
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 ) ; performImplicitSingle...
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 .
149,378
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 .
149,379
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 .
149,380
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 -...
Given the lambda value perform an implicit QR step on the matrix .
149,381
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 ....
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 .
149,382
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 ++...
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 .
149,383
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 .
149,384
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 ) { up...
Start pushing the element off to the right .
149,385
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 ) { ...
Used to finish up pushing the bulge off the matrix .
149,386
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 .
149,387
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 )...
Compute singular values and U and V at the same time
149,388
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 * ...
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
149,389
public static boolean checkDuplicateElements ( DMatrixSparseCSC A ) { A = A . copy ( ) ; A . sortIndices ( null ) ; return ! checkSortedFlag ( A ) ; }
Checks for duplicate elements . A is sorted
149,390
public static void changeSign ( DMatrixSparseCSC A , DMatrixSparseCSC B ) { if ( A != B ) { B . copyStructure ( A ) ; } for ( int i = 0 ; i < A . nz_length ; i ++ ) { B . nz_values [ i ] = - A . nz_values [ i ] ; } }
B = - A . Changes the sign of elements in A and stores it in B . A and B can be the same instance .
149,391
public static double elementMin ( DMatrixSparseCSC A ) { if ( A . nz_length == 0 ) return 0 ; double min = A . isFull ( ) ? A . nz_values [ 0 ] : 0 ; for ( int i = 0 ; i < A . nz_length ; i ++ ) { double val = A . nz_values [ i ] ; if ( val < min ) { min = val ; } } return min ; }
Returns the value of the element with the minimum value
149,392
public static double elementMax ( DMatrixSparseCSC A ) { if ( A . nz_length == 0 ) return 0 ; double max = A . isFull ( ) ? A . nz_values [ 0 ] : 0 ; for ( int i = 0 ; i < A . nz_length ; i ++ ) { double val = A . nz_values [ i ] ; if ( val > max ) { max = val ; } } return max ; }
Returns the value of the element with the largest value
149,393
public static double elementSum ( DMatrixSparseCSC A ) { if ( A . nz_length == 0 ) return 0 ; double sum = 0 ; for ( int i = 0 ; i < A . nz_length ; i ++ ) { sum += A . nz_values [ i ] ; } return sum ; }
Sum of all elements
149,394
public static void columnMaxAbs ( DMatrixSparseCSC A , double [ ] values ) { if ( values . length < A . numCols ) throw new IllegalArgumentException ( "Array is too small. " + values . length + " < " + A . numCols ) ; for ( int i = 0 ; i < A . numCols ; i ++ ) { int idx0 = A . col_idx [ i ] ; int idx1 = A . col_idx [ i...
Finds the maximum abs in each column of A and stores it into values
149,395
public static DMatrixSparseCSC diag ( double ... values ) { int N = values . length ; return diag ( new DMatrixSparseCSC ( N , N , N ) , values , 0 , N ) ; }
Returns a diagonal matrix with the specified diagonal elements .
149,396
public static void permutationVector ( DMatrixSparseCSC P , int [ ] vector ) { if ( P . numCols != P . numRows ) { throw new MatrixDimensionException ( "Expected a square matrix" ) ; } else if ( P . nz_length != P . numCols ) { throw new IllegalArgumentException ( "Expected N non-zero elements in permutation matrix" ) ...
Converts the permutation matrix into a vector
149,397
public static void permutationInverse ( int [ ] original , int [ ] inverse , int length ) { for ( int i = 0 ; i < length ; i ++ ) { inverse [ original [ i ] ] = i ; } }
Computes the inverse permutation vector
149,398
public static void zero ( DMatrixSparseCSC A , int row0 , int row1 , int col0 , int col1 ) { for ( int col = col1 - 1 ; col >= col0 ; col -- ) { int numRemoved = 0 ; int idx0 = A . col_idx [ col ] , idx1 = A . col_idx [ col + 1 ] ; for ( int i = idx0 ; i < idx1 ; i ++ ) { int row = A . nz_rows [ i ] ; if ( row >= row0 ...
Zeros an inner rectangle inside the matrix .
149,399
public static void removeZeros ( DMatrixSparseCSC input , DMatrixSparseCSC output , double tol ) { ImplCommonOps_DSCC . removeZeros ( input , output , tol ) ; }
Copies all elements from input into output which are &gt ; tol .