result.setSubMatrix(result00.getData(), 0, 0); result.setSubMatrix(result01.getData(), 0, splitIndex1); result.setSubMatrix(result10.getData(), splitIndex1, 0); result.setSubMatrix(result11.getData(), splitIndex1, splitIndex1);
@Nonnull public static RealMatrix combinedMatrices(@Nonnull final RealMatrix[][] grid, final int dimensions) { Preconditions.checkArgument(grid.length >= 1, "The number of rows must be greater than 1"); Preconditions.checkArgument(grid[0].length >= 1, "The number of cols must be greater than 1"); Preconditions.checkArgument(dimensions > 0, "Dimension should be more than 0: ", dimensions); final int rows = grid.length; final int cols = grid[0].length; final RealMatrix combined = new BlockRealMatrix(rows * dimensions, cols * dimensions); for (int row = 0; row < grid.length; row++) { for (int col = 0; col < grid[row].length; col++) { combined.setSubMatrix(grid[row][col].getData(), row * dimensions, col * dimensions); } } return combined; }
@Nonnull public static RealMatrix combinedMatrices(@Nonnull final RealMatrix[] grid) { Preconditions.checkArgument(grid.length >= 1, "The number of rows must be greater than 0: " + grid.length); final int rows = grid.length; final int rowDims = grid[0].getRowDimension(); final int colDims = grid[0].getColumnDimension(); final RealMatrix combined = new BlockRealMatrix(rows * rowDims, colDims); for (int row = 0; row < grid.length; row++) { RealMatrix cell = grid[row]; Preconditions.checkArgument(cell.getRowDimension() == rowDims, "Mismatch in row dimensions at row ", row); Preconditions.checkArgument(cell.getColumnDimension() == colDims, "Mismatch in col dimensions at row ", row); combined.setSubMatrix(cell.getData(), row * rowDims, 0); } return combined; }
R.setSubMatrix(T.getData(), 0, 0); Qt.setSubMatrix(eye(n), 0, 0); R.setSubMatrix( subR.subtract(x.outerProduct(subR.preMultiply(x)).scalarMultiply(2)).getData(), i, 0); Qt.setSubMatrix( subQt.subtract(x.outerProduct(subQt.preMultiply(x)).scalarMultiply(2)).getData(), i, 0);
APh1.setSubMatrix(A.getData(), 0, 0); RealVector bPh1 = b; RealVector cPh1 = new ArrayRealVector(c.getDimension()+1);
/** * Translate the algebraic form of the ellipsoid to the offset. * * @param center vector containing the offset of the ellipsoid. * @param a the algebraic form of the polynomial. * @return the offset translated form of the algebraic ellipsoid. */ private RealMatrix translateToCenter(RealVector center, RealMatrix a) { // Form the corresponding translation matrix. RealMatrix t = MatrixUtils.createRealIdentityMatrix(4); RealMatrix centerMatrix = new Array2DRowRealMatrix(1, 3); centerMatrix.setRowVector(0, center); t.setSubMatrix(centerMatrix.getData(), 3, 0); // Translate to the offset. RealMatrix r = t.multiply(a).multiply(t.transpose()); return r; }
eigvecs.setSubMatrix(eye(nEig), 0, 0); eigvecs.setSubMatrix(eigvecs.multiply(Q).getData(), 0, 0);
private RealMatrix buildJ(SOCPConstraintParameters param, RealVector X){ RealMatrix J = new Array2DRowRealMatrix(dim, param.getA().getRowDimension()+1); J.setSubMatrix(param.getA().transpose().getData(), 0, 0); J.setColumnVector(param.getA().getRowDimension(), param.getC()); return J; }
@Override public double[][] hessian(double[] X) { RealVector x = new ArrayRealVector(X); RealMatrix ret = new Array2DRowRealMatrix(dim, dim); for(int i=0; i<socpConstraintParametersList.size(); i++){ SOCPConstraintParameters param = socpConstraintParametersList.get(i); double t = this.buildT(param, x); RealVector u = this.buildU(param, x); double t2uu = t*t - u.dotProduct(u); RealVector t2u = u.mapMultiply(-2*t); RealMatrix Jacob = this.buildJ(param, x); int k = u.getDimension(); RealMatrix H = new Array2DRowRealMatrix(k+1, k+1); RealMatrix ID = MatrixUtils.createRealIdentityMatrix(k); H.setSubMatrix(ID.scalarMultiply(t2uu).add(u.outerProduct(u).scalarMultiply(2)).getData(), 0, 0); H.setSubMatrix(new double[][]{t2u.toArray()}, k, 0); for(int j=0; j<k; j++){ H.setEntry(j, k, t2u.getEntry(j)); } H.setEntry(k, k, t*t+u.dotProduct(u)); RealMatrix ret_i = Jacob.multiply(H).multiply(Jacob.transpose()).scalarMultiply(2./Math.pow(t2uu, 2)); ret = ret.add(ret_i); } return ret.getData(); }
T.setSubMatrix(new double[s][s], 0, 0);
result.setSubMatrix(result00.getData(), 0, 0); result.setSubMatrix(result01.getData(), 0, splitIndex1); result.setSubMatrix(result10.getData(), splitIndex1, 0); result.setSubMatrix(result11.getData(), splitIndex1, splitIndex1);
result.setSubMatrix(result00.getData(), 0, 0); result.setSubMatrix(result01.getData(), 0, splitIndex1); result.setSubMatrix(result10.getData(), splitIndex1, 0); result.setSubMatrix(result11.getData(), splitIndex1, splitIndex1);
for(int i=1; i<row; i++){ RealMatrix tmp = MatrixUtils.createRealMatrix(fullM.getRowDimension()+1, col); tmp.setSubMatrix(fullM.getData(), 0, 0); tmp.setRowVector(fullM.getRowDimension(), M.getRowVector(i)); SingularValueDecomposition dFact_i = new SingularValueDecomposition(tmp);
designMatrix.setColumn(1, ones(ts.length - 1 - k + 1)); designMatrix.setColumn(2, trend); designMatrix.setSubMatrix(yt1.getData(), 0, 3);
designMatrix.setColumn(1, ones(ts.length - 1 - k + 1)); designMatrix.setColumn(2, trend); designMatrix.setSubMatrix(yt1.getData(), 0, 3);