List of usage examples for org.apache.commons.math3.linear RealMatrix getColumnDimension
int getColumnDimension();
From source file:edu.oregonstate.eecs.mcplan.ml.SequentialProjectionHashLearner.java
private void T(final RealMatrix S_tilde, final RealMatrix S) { for (int i = 0; i < S_tilde.getRowDimension(); ++i) { for (int j = 0; j < S_tilde.getColumnDimension(); ++j) { final double st = S_tilde.getEntry(i, j); S_tilde.setEntry(i, j, st * S.getEntry(i, j) < 0 ? st : 0); }//w w w .j a v a 2s.com } }
From source file:com.mothsoft.alexis.engine.numeric.CorrelationCalculatorTest.java
@Test public void testCommonsMathCorrelationIdentityMatrix() { final PearsonsCorrelation correlation = new PearsonsCorrelation(); final double[][] xy = new double[4][2]; xy[0][0] = 0.0;/*from w ww.jav a 2 s . c o m*/ xy[1][0] = 1.0; xy[2][0] = 2.3; xy[3][0] = 3.4; xy[0][1] = 0.0; xy[1][1] = 1.0; xy[2][1] = 2.3; xy[3][1] = 3.4; final RealMatrix matrix = correlation.computeCorrelationMatrix(xy); assertEquals(2, matrix.getColumnDimension()); assertEquals(2, matrix.getRowDimension()); assertEquals(1.0, matrix.getEntry(0, 1), 0.000001); assertEquals(1.0, matrix.getEntry(1, 0), 0.000001); }
From source file:com.clust4j.algo.preprocess.MeanCenterer.java
@Override public MeanCenterer fit(RealMatrix data) { synchronized (fitLock) { final int m = data.getRowDimension(); final int n = data.getColumnDimension(); // need to mean center... this.means = new double[n]; final double[][] y = data.getData(); // First pass, compute mean... for (int j = 0; j < n; j++) { for (int i = 0; i < m; i++) { means[j] += y[i][j];// w w w . j a va2s . c om // if last: if (i == m - 1) { means[j] /= (double) m; } } } return this; } }
From source file:edu.cudenver.bios.matrix.FixedRandomMatrix.java
/** * Update the values in the random submatrix. The matrix of new values * must match the dimensions of the random submatrix. * * @param updatedMatrix new values for the random submatrix *///from w w w. j a v a 2 s . com public void updateRandomMatrix(RealMatrix updatedMatrix) { if (randomMatrix != null && updatedMatrix.getColumnDimension() == randomMatrix.getColumnDimension() && updatedMatrix.getRowDimension() == randomMatrix.getRowDimension()) { double[][] data = updatedMatrix.getData(); randomMatrix.setSubMatrix(data, 0, 0); int startRow = 0; int startCol = 0; if (fixedMatrix != null) { if (combineHorizontal) { startRow = 0; startCol = fixedMatrix.getColumnDimension(); } else { startRow = fixedMatrix.getRowDimension(); startCol = 0; } } combinedMatrix.setSubMatrix(data, startRow, startCol); } }
From source file:edu.cudenver.bios.power.glmm.GLMMTestHotellingLawley.java
/** * Compute a Hotelling-Lawley Trace statistic * * @param H hypothesis sum of squares matrix * @param E error sum of squares matrix/* w w w . j a va2 s . c o m*/ * @returns F statistic */ private double getHotellingLawleyTrace(RealMatrix H, RealMatrix E) throws IllegalArgumentException { if (!H.isSquare() || !E.isSquare() || H.getColumnDimension() != E.getRowDimension()) throw new IllegalArgumentException( "Failed to compute Hotelling-Lawley Trace: hypothesis and error matrices must be square and same dimensions"); RealMatrix inverseE = new LUDecomposition(E).getSolver().getInverse(); RealMatrix HinverseE = H.multiply(inverseE); return HinverseE.getTrace(); }
From source file:com.clust4j.algo.preprocess.MinMaxScaler.java
@Override public MinMaxScaler fit(RealMatrix X) { synchronized (fitLock) { final int m = X.getRowDimension(); final int n = X.getColumnDimension(); this.mins = new double[n]; this.maxes = new double[n]; double[][] data = X.getData(); for (int col = 0; col < n; col++) { double mn = Double.POSITIVE_INFINITY, mx = Double.NEGATIVE_INFINITY; for (int row = 0; row < m; row++) { mn = FastMath.min(mn, data[row][col]); mx = FastMath.max(mx, data[row][col]); }//from ww w. jav a 2 s .c om this.mins[col] = mn; this.maxes[col] = mx; } return this; } }
From source file:com.joptimizer.functions.SDPLogarithmicBarrier.java
/** * Build the genaralized logarithmic barrier function for the constraint * <br>G + Sum[x_i * F_i(x),i] < 0, F_i, G symmetric matrices * @param Fi symmetric matrices/*from w w w . j av a2s . c o m*/ * @param G symmetric matrix */ public SDPLogarithmicBarrier(List<double[][]> FiMatrixList, double[][] GMatrix) { int dim = FiMatrixList.size(); this.Fi = new RealMatrix[dim]; RealMatrix Gg = new Array2DRowRealMatrix(GMatrix); if (Gg.getRowDimension() != Gg.getColumnDimension()) { throw new IllegalArgumentException("All matrices must be symmetric"); } this.G = Gg; int pp = G.getRowDimension(); for (int i = 0; i < dim; i++) { double[][] FiMatrix = FiMatrixList.get(i); RealMatrix Fii = new Array2DRowRealMatrix(FiMatrix); if (Fii.getRowDimension() != Fii.getColumnDimension() || pp != Fii.getRowDimension()) { throw new IllegalArgumentException("All matrices must be symmetric and with the same dimensions"); } this.Fi[i] = Fii; } this.dim = dim; this.p = pp; }
From source file:edu.cudenver.bios.power.glmm.GLMMTestPillaiBartlett.java
/** * Compute a Pillai Bartlett Trace statistic * //from ww w .j a v a 2 s. c o m * @param H hypothesis sum of squares matrix * @param E error sum of squares matrix * @returns F statistic */ private double getPillaiBartlettTrace(RealMatrix H, RealMatrix E) { if (!H.isSquare() || !E.isSquare() || H.getColumnDimension() != E.getRowDimension()) throw new IllegalArgumentException( "Failed to compute Pillai-Bartlett Trace: hypothesis and error matrices must be square and same dimensions"); double a = C.getRowDimension(); double b = U.getColumnDimension(); double s = (a < b) ? a : b; double p = beta.getColumnDimension(); RealMatrix adjustedH = H; if ((s == 1 && p > 1) || fMethod == FApproximation.PILLAI_ONE_MOMENT_OMEGA_MULT || fMethod == FApproximation.MULLER_TWO_MOMENT_OMEGA_MULT) { adjustedH = H.scalarMultiply(((double) (totalN - rank) / (double) totalN)); } RealMatrix T = adjustedH.add(E); RealMatrix inverseT = new LUDecomposition(T).getSolver().getInverse(); RealMatrix HinverseT = adjustedH.multiply(inverseT); return HinverseT.getTrace(); }
From source file:edu.ucdenver.bios.powersvc.resource.PowerResourceHelper.java
/** * This method takes a Real Matrix and converts it into a Named Matrix and * returns that Named Matrix./*from w w w . ja v a2s . c o m*/ * * @param matrix * The matrix is a input matrix of type RealMatrix and is to be * converted to a NamedMatrix. * @param name * the name is a String, which is to be assigned to named matrix. * @return namedMatrix Returns a NamedMatrix which is obtained by converting * the input matrix to NamedMatrix */ public static NamedMatrix toNamedMatrix(final RealMatrix matrix, final String name) { if (matrix == null || name == null || name.isEmpty()) { logger.error("failed to create NamedMatrix object name=[" + (name != null ? name : "NULL") + "]"); return null; } NamedMatrix namedMatrix = new NamedMatrix(); namedMatrix.setDataFromArray(matrix.getData()); namedMatrix.setName(name); namedMatrix.setColumns(matrix.getColumnDimension()); namedMatrix.setRows(matrix.getRowDimension()); return namedMatrix; }
From source file:jurls.core.utils.MatrixImage.java
public void draw(RealMatrix M, double minValue, double maxValue) { draw(M::getEntry, M.getColumnDimension(), M.getRowDimension(), minValue, maxValue); }