List of usage examples for org.apache.commons.math3.linear RealMatrix getColumnDimension
int getColumnDimension();
From source file:put.ci.cevo.framework.algorithms.ApacheCMAES.java
/** * @param m Input matrix 1./* www . j ava 2s . c om*/ * @param n Input matrix 2. * @return Matrix where the elements of m and n are element-wise divided. */ private static RealMatrix divide(final RealMatrix m, final RealMatrix n) { final double[][] d = new double[m.getRowDimension()][m.getColumnDimension()]; for (int r = 0; r < m.getRowDimension(); r++) { for (int c = 0; c < m.getColumnDimension(); c++) { d[r][c] = m.getEntry(r, c) / n.getEntry(r, c); } } return new Array2DRowRealMatrix(d, false); }
From source file:put.ci.cevo.framework.algorithms.ApacheCMAES.java
/** * @param m Input matrix.//from w w w . j a va2s .c o m * @param k Diagonal position. * @return Upper triangular part of matrix. */ private static RealMatrix triu(final RealMatrix m, int k) { final double[][] d = new double[m.getRowDimension()][m.getColumnDimension()]; for (int r = 0; r < m.getRowDimension(); r++) { for (int c = 0; c < m.getColumnDimension(); c++) { d[r][c] = r <= c - k ? m.getEntry(r, c) : 0; } } return new Array2DRowRealMatrix(d, false); }
From source file:put.ci.cevo.framework.algorithms.ApacheCMAES.java
/** * @param m Input matrix./*from w w w. j a v a 2 s .c o m*/ * @return Row matrix representing the sums of the rows. */ private static RealMatrix sumRows(final RealMatrix m) { final double[][] d = new double[1][m.getColumnDimension()]; for (int c = 0; c < m.getColumnDimension(); c++) { double sum = 0; for (int r = 0; r < m.getRowDimension(); r++) { sum += m.getEntry(r, c); } d[0][c] = sum; } return new Array2DRowRealMatrix(d, false); }
From source file:put.ci.cevo.framework.algorithms.ApacheCMAES.java
/** * @param m Input matrix.//from w w w .j av a 2 s .co m * @return the diagonal n-by-n matrix if m is a column matrix or the column matrix representing the diagonal if m is * a n-by-n matrix. */ private static RealMatrix diag(final RealMatrix m) { if (m.getColumnDimension() == 1) { final double[][] d = new double[m.getRowDimension()][m.getRowDimension()]; for (int i = 0; i < m.getRowDimension(); i++) { d[i][i] = m.getEntry(i, 0); } return new Array2DRowRealMatrix(d, false); } else { final double[][] d = new double[m.getRowDimension()][1]; for (int i = 0; i < m.getColumnDimension(); i++) { d[i][0] = m.getEntry(i, i); } return new Array2DRowRealMatrix(d, false); } }
From source file:put.ci.cevo.framework.algorithms.ApacheCMAES.java
/** * @param mat Input matrix./*from w w w . j a v a2 s . co m*/ * @param n Number of row replicates. * @param m Number of column replicates. * @return a matrix which replicates the input matrix in both directions. */ private static RealMatrix repmat(final RealMatrix mat, int n, int m) { final int rd = mat.getRowDimension(); final int cd = mat.getColumnDimension(); final double[][] d = new double[n * rd][m * cd]; for (int r = 0; r < n * rd; r++) { for (int c = 0; c < m * cd; c++) { d[r][c] = mat.getEntry(r % rd, c % cd); } } return new Array2DRowRealMatrix(d, false); }
From source file:put.ci.cevo.framework.algorithms.ApacheCMAES.java
/** * @param m Input matrix.//from w ww .ja v a 2s .c om * @return the maximum of the matrix element values. */ private static double max(final RealMatrix m) { double max = -Double.MAX_VALUE; for (int r = 0; r < m.getRowDimension(); r++) { for (int c = 0; c < m.getColumnDimension(); c++) { double e = m.getEntry(r, c); if (max < e) { max = e; } } } return max; }
From source file:put.ci.cevo.framework.algorithms.ApacheCMAES.java
/** * @param m Input matrix./*from w w w.j a va 2 s. c o m*/ * @return the minimum of the matrix element values. */ private static double min(final RealMatrix m) { double min = Double.MAX_VALUE; for (int r = 0; r < m.getRowDimension(); r++) { for (int c = 0; c < m.getColumnDimension(); c++) { double e = m.getEntry(r, c); if (min > e) { min = e; } } } return min; }
From source file:restclient.service.DailyRecordFacadeREST.java
@GET @Path("findCorrelationByStartAndEndDateAndWeatherVariable/{startDate}/{endDate}/{attribute}") @Produces({ "application/json" }) public String findCorrelationByStartAndEndDateAndWeatherVariable(@PathParam("startDate") Date startDate, @PathParam("endDate") Date endDate, @PathParam("attribute") String attribute) { String attributeInLowerCase = attribute.toLowerCase(); switch (attributeInLowerCase) { case "windspeed": case "wind speed": attributeInLowerCase = "windSpeed"; break;//from ww w . j ava 2 s.c om case "atmosphericpressure": case "atmospheric pressure": attributeInLowerCase = "atmosphericPressure"; break; default: break; } String sth = "NEW restclient.Result2(d.painLevel, d." + attributeInLowerCase + ")"; String jpql = "SELECT " + sth + " FROM restclient.DailyRecord d WHERE d.recordDate >= :startDate AND d.recordDate <= :endDate"; TypedQuery<Result2> q = em.createQuery(jpql, Result2.class); q.setParameter("startDate", startDate); q.setParameter("endDate", endDate); List<Result2> result = q.getResultList(); double data[][] = new double[result.size()][]; for (int i = 0; i < result.size(); i++) { data[i] = new double[] { result.get(i).painLevel, result.get(i).weather }; } RealMatrix m = MatrixUtils.createRealMatrix(data); String first = ""; for (int i = 0; i < m.getColumnDimension(); i++) for (int j = 0; j < m.getColumnDimension(); j++) { PearsonsCorrelation pc = new PearsonsCorrelation(); double cor = pc.correlation(m.getColumn(i), m.getColumn(j)); first += (i + "," + j + "=[" + String.format(".%2f", cor) + "," + "]" + "; "); } PearsonsCorrelation pc = new PearsonsCorrelation(m); RealMatrix corM = pc.getCorrelationMatrix(); String second = ("!correlation:" + corM.getEntry(0, 1) + " "); RealMatrix pM = pc.getCorrelationPValues(); String third = ("!p value:" + pM.getEntry(0, 1)); return first + second + third; }
From source file:Rotationforest.Covariance.java
/** * Compute a covariance matrix from a matrix whose columns represent * covariates.// w w w . j av a 2s . c om * @param matrix input matrix (must have at least one column and two rows) * @param biasCorrected determines whether or not covariance estimates are bias-corrected * @return covariance matrix * @throws MathIllegalArgumentException if the matrix does not contain sufficient data */ protected RealMatrix computeCovarianceMatrix(RealMatrix matrix, boolean biasCorrected) throws MathIllegalArgumentException { int dimension = matrix.getColumnDimension(); Variance variance = new Variance(biasCorrected); RealMatrix outMatrix = new BlockRealMatrix(dimension, dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j < i; j++) { double cov = covariance(matrix.getColumn(i), matrix.getColumn(j), biasCorrected); outMatrix.setEntry(i, j, cov); outMatrix.setEntry(j, i, cov); } outMatrix.setEntry(i, i, variance.evaluate(matrix.getColumn(i))); outMatrix.setEntry(i, i, variance.evaluate(matrix.getColumn(i))); } //return outMatrix; return outMatrix; }
From source file:Rotationforest.Covariance.java
/** * Throws MathIllegalArgumentException if the matrix does not have at least * one column and two rows./* w w w.jav a2 s.c om*/ * @param matrix matrix to check * @throws MathIllegalArgumentException if the matrix does not contain sufficient data * to compute covariance */ private void checkSufficientData(final RealMatrix matrix) throws MathIllegalArgumentException { int nRows = matrix.getRowDimension(); int nCols = matrix.getColumnDimension(); if (nRows < 2 || nCols < 1) { throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_ROWS_AND_COLUMNS, nRows, nCols); } }