@Override public void init(int numParameters) { hessian.reshape(numParameters,numParameters); }
@Override public void init(int numParameters) { hessian.reshape(numParameters,numParameters); }
@Override public void reshape(int numRows, int numCols) { reshape(numRows, numCols,0); }
/** * Copies the non-zero structure of orig into "this" * @param orig Matrix who's structure is to be copied */ public void copyStructure( DMatrixSparseCSC orig ) { reshape(orig.numRows, orig.numCols, orig.nz_length); this.nz_length = orig.nz_length; System.arraycopy(orig.col_idx,0,col_idx,0,orig.numCols+1); System.arraycopy(orig.nz_rows,0,nz_rows,0,orig.nz_length); }
@Override public void set(Matrix original) { DMatrixSparseCSC o = (DMatrixSparseCSC)original; reshape(o.numRows, o.numCols, o.nz_length); this.nz_length = o.nz_length; System.arraycopy(o.nz_values, 0, nz_values, 0, nz_length); System.arraycopy(o.nz_rows, 0, nz_rows, 0, nz_length); System.arraycopy(o.col_idx, 0, col_idx, 0, numCols+1); this.indicesSorted = o.indicesSorted; }
dst = new DMatrixSparseCSC(src.numRows, src.numCols, nonzero); else dst.reshape(src.numRows, src.numCols, nonzero); dst.nz_length = 0;
/** * Compuets the Hessian in block form * @param jacLeft (Input) Left side of Jacobian * @param jacRight (Input) Right side of Jacobian */ @Override public void computeHessian(DMatrixSparseCSC jacLeft , DMatrixSparseCSC jacRight) { A.reshape(jacLeft.numCols,jacLeft.numCols,1); B.reshape(jacLeft.numCols,jacRight.numCols,1); D.reshape(jacRight.numCols,jacRight.numCols,1); // take advantage of the inner product's symmetry when possible to reduce // the number of calculations CommonOps_DSCC.innerProductLower(jacLeft,tmp0,gw,gx); CommonOps_DSCC.symmLowerToFull(tmp0,A,gw); CommonOps_DSCC.multTransA(jacLeft,jacRight,B,gw,gx); CommonOps_DSCC.innerProductLower(jacRight,tmp0,gw,gx); CommonOps_DSCC.symmLowerToFull(tmp0,D,gw); }
/** * Compuets the Hessian in block form * @param jacLeft (Input) Left side of Jacobian * @param jacRight (Input) Right side of Jacobian */ @Override public void computeHessian(DMatrixSparseCSC jacLeft , DMatrixSparseCSC jacRight) { A.reshape(jacLeft.numCols,jacLeft.numCols,1); B.reshape(jacLeft.numCols,jacRight.numCols,1); D.reshape(jacRight.numCols,jacRight.numCols,1); // take advantage of the inner product's symmetry when possible to reduce // the number of calculations CommonOps_DSCC.innerProductLower(jacLeft,tmp0,gw,gx); CommonOps_DSCC.symmLowerToFull(tmp0,A,gw); CommonOps_DSCC.multTransA(jacLeft,jacRight,B,gw,gx); CommonOps_DSCC.innerProductLower(jacRight,tmp0,gw,gx); CommonOps_DSCC.symmLowerToFull(tmp0,D,gw); }
dst = new DMatrixSparseCSC(src.numRows, src.numCols , src.nz_length); else dst.reshape(src.numRows, src.numCols, src.nz_length);
@Override public void process(double[] input, DMatrixSparseCSC jacobian) { jacobian.reshape(M,N,N); function.process(input,output0); // Use a triplet initially because it is less expensive to grow DMatrixSparseTriplet tmp = new DMatrixSparseTriplet(M,N,N); for( int i = 0; i < N; i++ ) { double x = input[i]; double h = x != 0 ? differenceScale*Math.abs(x) : differenceScale; // takes in account round off error double temp = x+h; h = temp-x; input[i] = temp; function.process(input,output1); for( int j = 0; j < M; j++ ) { double value = (output1[j] - output0[j])/h; if( Math.abs(value) > zeroTolerance ) tmp.set(j,i,value); } input[i] = x; } ConvertDMatrixStruct.convert(tmp,jacobian); }
@Override public void process(double[] input, DMatrixSparseCSC jacobian) { jacobian.reshape(M,N,N); function.process(input,output0); // Use a triplet initially because it is less expensive to grow DMatrixSparseTriplet tmp = new DMatrixSparseTriplet(M,N,N); for( int i = 0; i < N; i++ ) { double x = input[i]; double h = x != 0 ? differenceScale*Math.abs(x) : differenceScale; // takes in account round off error double temp = x+h; h = temp-x; input[i] = temp; function.process(input,output1); for( int j = 0; j < M; j++ ) { double value = (output1[j] - output0[j])/h; if( Math.abs(value) > zeroTolerance ) tmp.set(j,i,value); } input[i] = x; } ConvertDMatrixStruct.convert(tmp,jacobian); }
@Override protected void setHessian(HessianMath alg, DMatrixRMaj H) { int M = 3; int N = H.numCols-M; HessianSchurComplement_DSCC hm = (HessianSchurComplement_DSCC)alg; DMatrixSparseCSC SH = new DMatrixSparseCSC(1,1); ConvertDMatrixStruct.convert(H,SH); hm.A.reshape(M,M); hm.B.reshape(M,N); hm.D.reshape(N,N); CommonOps_DSCC.extract(SH,0,M,0,M,hm.A,0,0); CommonOps_DSCC.extract(SH,0,M,M,M+N,hm.B,0,0); CommonOps_DSCC.extract(SH,M,M+N,M,M+N,hm.D,0,0); }
D_m.reshape(A.numRows,B.numCols);
D_m.reshape(A.numRows,B.numCols);