double total = 0; double scale = CCommonOps.elementMaxAbs(a);
extract(src, srcY0, srcY1, srcX0, srcX1, dst, 0, 0);
/** * <p> * Creates a reflector from the provided vector and gamma.<br> * <br> * Q = I - γ u u<sup>H</sup><br> * </p> * * @param u A vector. Not modified. * @param gamma To produce a reflector gamma needs to be equal to 2/||u||. * @return An orthogonal reflector. */ public static CDenseMatrix64F createReflector( CDenseMatrix64F u , double gamma) { if( !CMatrixFeatures.isVector(u)) throw new IllegalArgumentException("u must be a vector"); CDenseMatrix64F Q = CCommonOps.identity(u.getNumElements()); CCommonOps.multAddTransB(-gamma,0,u,u,Q); return Q; }
public static CDenseMatrix64F checkIdentity(CDenseMatrix64F A, int numRows, int numCols) { if( A == null ) { return CCommonOps.identity(numRows,numCols); } else if( numRows != A.numRows || numCols != A.numCols ) throw new IllegalArgumentException("Input is not "+numRows+" x "+numCols+" matrix"); else CCommonOps.setIdentity(A); return A; }
/** * Creates a random symmetric positive definite matrix. * * @param width The width of the square matrix it returns. * @param rand Random number generator used to make the matrix. * @return The random symmetric positive definite matrix. */ public static CDenseMatrix64F createHermPosDef(int width, Random rand) { // This is not formally proven to work. It just seems to work. CDenseMatrix64F a = CRandomMatrices.createRandom(width,1,rand); CDenseMatrix64F b = new CDenseMatrix64F(1,width); CDenseMatrix64F c = new CDenseMatrix64F(width,width); CCommonOps.transposeConjugate(a,b); CCommonOps.mult(a, b, c); for( int i = 0; i < width; i++ ) { c.data[2*(i*width+i)] += 1; } return c; }
/** * Uses EJML. @pabeles */ public ComplexMatrix inverse() { if (this.getRowDimension() != this.getColumnDimension()) { throw new RuntimeException("Can only call inverse on square, invertible matrices!"); } CDenseMatrix64F ejmlMatrix = ComplexTools.ihmcComplexToEjmlComplex(this); CCommonOps.invert(ejmlMatrix); return ComplexTools.ejmlToIhmComplex(ejmlMatrix); }
CCommonOps.fill(c,0,0); return;
CDenseMatrix64F u = x.copy(); double max = CCommonOps.elementMaxAbs(u); CCommonOps.elementDivide(u, max, 0, u); CCommonOps.elementDivide(u,u.getReal(0,0),u.getImag(0,0),u);
CDenseMatrix64F u[] = CCommonOps.columnsToVector(Q, null);
/** * Q = I - gamma*u*u<sup>H</sup> */ public static CDenseMatrix64F householder( CDenseMatrix64F u , double gamma ) { int N = u.getDataLength()/2; // u*u^H CDenseMatrix64F uut = new CDenseMatrix64F(N,N); CVectorVectorMult.outerProdH(u, u, uut); // foo = -gamma*u*u^H CCommonOps.elementMultiply(uut,-gamma,0,uut); // I + foo for (int i = 0; i < N; i++) { int index = (i*uut.numCols+i)*2; uut.data[index] = 1 + uut.data[index]; } return uut; }
CCommonOps.mult(Qt, Y, Z);
/** * Uses EJML. @pabeles */ public ComplexMatrix inverse() { if (this.getRowDimension() != this.getColumnDimension()) { throw new RuntimeException("Can only call inverse on square, invertible matrices!"); } CDenseMatrix64F ejmlMatrix = ComplexTools.ihmcComplexToEjmlComplex(this); CCommonOps.invert(ejmlMatrix); return ComplexTools.ejmlToIhmComplex(ejmlMatrix); }
CCommonOps.fill(c,0,0); return;
private static ComplexNumber[][] extractRightEigenvectorsByInvertingComplexV(ComplexNumber[][] leftEigenvectors) { // How to get W??? matrixV.inverse() isn't the correct thing. // How about using A.transpose()? But then we have scaling and potential reordering problems! // Here we'll use a complex matrix inverse. But I have a hunch you could represent it as a // real Matrix and do an inverse on that and then extract the numbers since everything is in // complex conjugate pairs... int order = leftEigenvectors.length; // Load leftEigenvectors into new matrix as transpose ComplexMatrix ihmcComplexV = new ComplexMatrix(order, order); for (int i = 0; i < order; i++) for (int j = 0; j < order; j++) ihmcComplexV.set(i, j, leftEigenvectors[j][i]); // notice transpose here CDenseMatrix64F ejmlComplexV = ComplexTools.ihmcComplexToEjmlComplex(ihmcComplexV); if( !CCommonOps.invert(ejmlComplexV) ) { throw new RuntimeException("Complex matrix inversion failed"); } return ComplexTools.copyEjmlComplexIntoIhmcComplexNumber2dArray(ejmlComplexV); }
/** * <p> * Creates a reflector from the provided vector.<br> * <br> * Q = I - γ u u<sup>T</sup><br> * γ = 2/||u||<sup>2</sup> * </p> * * @param u A vector. Not modified. * @return An orthogonal reflector. */ public static CDenseMatrix64F createReflector(CDenseMatrix64F u ) { if( !CMatrixFeatures.isVector(u)) throw new IllegalArgumentException("u must be a vector"); double norm = CNormOps.normF(u); double gamma = -2.0/(norm*norm); CDenseMatrix64F Q = CCommonOps.identity(u.getNumElements()); CCommonOps.multAddTransB(gamma,0,u,u,Q); return Q; }
if( ret.numCols != numPivots || ret.numRows != numPivots ) throw new IllegalArgumentException("Unexpected matrix dimension"); CCommonOps.fill(ret, 0,0);
private static ComplexNumber[][] extractRightEigenvectorsByInvertingComplexV(ComplexNumber[][] leftEigenvectors) { // How to get W??? matrixV.inverse() isn't the correct thing. // How about using A.transpose()? But then we have scaling and potential reordering problems! // Here we'll use a complex matrix inverse. But I have a hunch you could represent it as a // real Matrix and do an inverse on that and then extract the numbers since everything is in // complex conjugate pairs... int order = leftEigenvectors.length; // Load leftEigenvectors into new matrix as transpose ComplexMatrix ihmcComplexV = new ComplexMatrix(order, order); for (int i = 0; i < order; i++) for (int j = 0; j < order; j++) ihmcComplexV.set(i, j, leftEigenvectors[j][i]); // notice transpose here CDenseMatrix64F ejmlComplexV = ComplexTools.ihmcComplexToEjmlComplex(ihmcComplexV); if( !CCommonOps.invert(ejmlComplexV) ) { throw new RuntimeException("Complex matrix inversion failed"); } return ComplexTools.copyEjmlComplexIntoIhmcComplexNumber2dArray(ejmlComplexV); }
CCommonOps.fill(c,0,0); return;
CCommonOps.fill(c,0,0); return;
CCommonOps.fill(c,0,0); return;