List of usage examples for org.apache.commons.math3.linear Array2DRowRealMatrix getRowDimension
@Override public int getRowDimension()
From source file:org.apache.hadoop.hive.ql.abm.simulation.MCSimNode.java
private Array2DRowRealMatrix concat(Array2DRowRealMatrix A, Array2DRowRealMatrix B, Array2DRowRealMatrix C, Array2DRowRealMatrix D) { int dim = A.getRowDimension() + D.getRowDimension(); Array2DRowRealMatrix ret = new Array2DRowRealMatrix(dim, dim); ret.setSubMatrix(A.getData(), 0, 0); ret.setSubMatrix(B.getData(), 0, A.getColumnDimension()); ret.setSubMatrix(C.getData(), A.getRowDimension(), 0); ret.setSubMatrix(D.getData(), A.getRowDimension(), A.getColumnDimension()); return ret;/*from w w w . j a va2s . c o m*/ }
From source file:org.apache.sysml.runtime.matrix.data.LibCommonsMath.java
/** * Function to compute matrix inverse via matrix decomposition. * /* w w w . ja va 2s. c om*/ * @param in commons-math3 Array2DRowRealMatrix * @return matrix block * @throws DMLRuntimeException if DMLRuntimeException occurs */ private static MatrixBlock computeMatrixInverse(Array2DRowRealMatrix in) throws DMLRuntimeException { if (!in.isSquare()) throw new DMLRuntimeException("Input to inv() must be square matrix -- given: a " + in.getRowDimension() + "x" + in.getColumnDimension() + " matrix."); QRDecomposition qrdecompose = new QRDecomposition(in); DecompositionSolver solver = qrdecompose.getSolver(); RealMatrix inverseMatrix = solver.getInverse(); return DataConverter.convertToMatrixBlock(inverseMatrix.getData()); }
From source file:org.apache.sysml.runtime.matrix.data.LibCommonsMath.java
/** * Function to compute Cholesky decomposition of the given input matrix. * The input must be a real symmetric positive-definite matrix. * /*from w w w . j a va 2 s .c o m*/ * @param in commons-math3 Array2DRowRealMatrix * @return matrix block * @throws DMLRuntimeException if DMLRuntimeException occurs */ private static MatrixBlock computeCholesky(Array2DRowRealMatrix in) throws DMLRuntimeException { if (!in.isSquare()) throw new DMLRuntimeException("Input to cholesky() must be square matrix -- given: a " + in.getRowDimension() + "x" + in.getColumnDimension() + " matrix."); CholeskyDecomposition cholesky = new CholeskyDecomposition(in); RealMatrix rmL = cholesky.getL(); return DataConverter.convertToMatrixBlock(rmL.getData()); }
From source file:outlineDescriptor.FieldAnalyzer.java
private CellReference[] identifyMaxima(CellReference[] store, Array2DRowRealMatrix kernel) { ArrayList<CellReference> out = new ArrayList<CellReference>(); int maxCount = 0; for (CellReference pt : store) { //this point has already been processed thus it is not a separate maximum if ((flags[getListOffset(pt.x, pt.y)] & (DISCARDED | PROCESSED)) != 0) { continue; }/* w w w . jav a 2 s . c o m*/ //boolean equalInRange = (flags[getListOffset(pt.x, pt.y)] & EQUAL) != 0; //checking the neighboring area for (int i = 0; i < kernel.getRowDimension(); i++) { double[] bounds = kernel.getRow(i); int upperLimit = (int) Math.max(bounds[1], bounds[2]); int bottom = (int) Math.min(bounds[1], bounds[2]); while (bottom <= upperLimit) { int yPos = pt.y + bottom; int xPos = (int) bounds[0] + pt.x; if (xPos >= 0 && xPos < coherenceKernel.length && yPos >= 0 && yPos < coherenceKernel[0].length) { if ((flags[getListOffset(xPos, yPos)] & CANDIDATE) == 0) { //this point isnt being considered for a maximum, continue flags[getListOffset(xPos, yPos)] |= PROCESSED; } //checking for equality within tolerance else if (pt.coh - FPERROR <= coherenceKernel[xPos][yPos]) { flags[getListOffset(xPos, yPos)] |= (EQUAL); } else { flags[getListOffset(xPos, yPos)] |= (PROCESSED | DISCARDED); } } flags[getListOffset(pt.x, pt.y)] |= MAX; bottom++; } } out.add(pt); maxCount++; if (maxCount >= count) { break; } } out.trimToSize(); return out.toArray(new CellReference[out.size()]); }
From source file:outlineDescriptor.FieldAnalyzer.java
private int[] getMax(Array2DRowRealMatrix field) { int[] pos = new int[2]; for (int x = 0; x < field.getColumnDimension(); x++) { for (int y = 0; y < field.getRowDimension(); y++) { if (field.getEntry(y, x) > field.getEntry(pos[1], pos[0])) { pos[0] = x;//from w w w.jav a 2s.co m pos[1] = y; } } } return pos; }
From source file:outlineDescriptor.ODUtils.java
public static void generateHeatMap(Array2DRowRealMatrix matrix, String name) { ResultsTable results = new ResultsTable(); for (int x = 0; x < matrix.getColumnDimension(); x++) { for (int y = 0; y < matrix.getRowDimension(); y++) { double intensity = matrix.getEntry(y, x); results.incrementCounter();/*from w ww. j a v a2s.c om*/ results.addValue("x", x); results.addValue("y", y); results.addValue("intensity", intensity); } } results.show(name); }
From source file:outlineDescriptor.ODUtils.java
public static void ellipseVote(int x0, int y0, double value, EllipticalKernelGenerator ek, int ellipseIndex, votable vf) {/*from ww w .j av a 2s. c om*/ Array2DRowRealMatrix ellipse = ek.getRotatedEllipseBounds(ellipseIndex); for (int i = 0; i < ellipse.getRowDimension(); i++) { int upperLimit = (int) Math.max(ellipse.getEntry(i, 1), ellipse.getEntry(i, 2)); int bottom = (int) Math.min(ellipse.getEntry(i, 1), ellipse.getEntry(i, 2)); while (bottom <= upperLimit) { int yPos = y0 + bottom; int xPos = (int) ellipse.getEntry(i, 0) + x0; vf.vote(xPos, yPos, ek.getDensityAt(ellipseIndex, ellipse.getEntry(i, 0), bottom), value); bottom++; } } }
From source file:outlineDescriptor.Transform.java
private Array2DRowRealMatrix createSVDmatrix(Array2DRowRealMatrix angleOffset, int aSteps, double step) { Array2DRowRealMatrix output = new Array2DRowRealMatrix(2 * aSteps, 2); for (int i = 0; i < aSteps; i++) { double angle = Math.PI - i * step; for (int row = 0; row < angleOffset.getRowDimension(); row++) { angleOffset.multiplyEntry(row, i, angleOffset.getEntry(row, i)); }/* ww w . ja v a 2 s .co m*/ double stdDev = getDeviance(angleOffset.getColumn(i)); // new StandardDeviation().evaluate(angleOffset.getColumn(i)); double outX = Math.cos(angle) * stdDev; double outY = Math.sin(angle) * stdDev; output.setEntry(i, 0, outX); output.setEntry(i, 1, outY); output.setEntry(i + aSteps, 0, -outX); output.setEntry(i + aSteps, 1, -outY); } return output; }
From source file:outlineDescriptor.Transform.java
private Array2DRowRealMatrix simpleHoughTransform(Array2DRowRealMatrix inputMatrix, int aSteps, double step) { double xMax = StatUtils.max(inputMatrix.getColumn(0)); double yMax = StatUtils.max(inputMatrix.getColumn(1)); int maxDst = (int) Math.sqrt(xMax * xMax + yMax * yMax); Array2DRowRealMatrix angleOffset = new Array2DRowRealMatrix(2 * maxDst + 1, aSteps); //calculating all possible line/distance pairs for each point for (int i = 0; i < aSteps; i++) { double angle = i * step; double xc = Math.cos(Math.PI / 2 - angle); double yc = Math.sin(Math.PI / 2 - angle); for (int row = 0; row < inputMatrix.getRowDimension(); row++) { if (inputMatrix.getEntry(row, 2) == 0) continue; int distance = (int) (xc * inputMatrix.getEntry(row, 0) + yc * inputMatrix.getEntry(row, 1)); distance += maxDst;//w w w . ja v a2s . c o m angleOffset.addToEntry(distance, i, inputMatrix.getEntry(row, 2)); } } return angleOffset; }
From source file:outlineDescriptor.Transform.java
private Array2DRowRealMatrix transform(Array2DRowRealMatrix rm, int aSteps) { double meanX = StatUtils.mean(rm.getColumn(0)); double meanY = StatUtils.mean(rm.getColumn(1)); double step = Math.PI / aSteps; Array2DRowRealMatrix output;// w w w. j av a 2s . c o m for (int i = 0; i < rm.getRowDimension(); i++) { rm.setEntry(i, 0, rm.getEntry(i, 0) - meanX); rm.setEntry(i, 1, rm.getEntry(i, 1) - meanY); } Array2DRowRealMatrix angleOffset = simpleHoughTransform(rm, aSteps, step); output = createSVDmatrix(angleOffset, aSteps, step); return output; }