List of usage examples for org.apache.commons.math3.linear Array2DRowRealMatrix Array2DRowRealMatrix
public Array2DRowRealMatrix(final double[][] d, final boolean copyArray) throws DimensionMismatchException, NoDataException, NullArgumentException
From source file:com.insightml.models.regression.OLS.java
public static Array2DRowRealMatrix addIntercept2(final double[][] x) { return new Array2DRowRealMatrix(addIntercept(x), false); }
From source file:com.cloudera.oryx.common.math.SolverLoadIT.java
private static RealMatrix randomSymmetricMatrix(int dimension) { RandomGenerator random = RandomManager.getRandom(); RealMatrix symmetric = new Array2DRowRealMatrix(dimension, dimension); for (int j = 0; j < dimension; j++) { // Diagonal symmetric.setEntry(j, j, random.nextDouble()); for (int k = j + 1; k < dimension; k++) { // Off-diagonal double d = random.nextDouble(); symmetric.setEntry(j, k, d); symmetric.setEntry(k, j, d); }/* w ww . j a va 2 s . c om*/ } return symmetric; }
From source file:edu.byu.nlp.classify.eval.ConfusionMatrix.java
public ConfusionMatrix(int numLabels, int K, Indexer<String> labels) { this.labels = labels; this.matrix = new Array2DRowRealMatrix(numLabels, K); }
From source file:com.cloudera.oryx.common.math.CommonsMathLinearSystemSolverTest.java
@Test public void testSolveFToD() { double[][] data = { new double[] { 1.0, 2.0 }, new double[] { 3.0, 5.0 } }; RealMatrix M = new Array2DRowRealMatrix(data, false); LinearSystemSolver cmLinearSystemSolver = new CommonsMathLinearSystemSolver(); Solver solver = cmLinearSystemSolver.getSolver(M); assertArrayEquals(new double[] { -12.0, 7.0 }, solver.solveFToD(new float[] { 2.0f, -1.0f })); }
From source file:com.cloudera.oryx.kmeans.computation.covariance.CovarianceDataBuilder.java
CovarianceDataBuilder(int n) { this.means = new ArrayRealVector(n); this.rawCoMoment = new Array2DRowRealMatrix(n, n); }
From source file:com.itemanalysis.psychometrics.statistics.MatrixToVector.java
public MatrixToVector(RealMatrix matrix) { this.matrix = matrix; numEelements = (int) ((matrix.getColumnDimension() * (matrix.getColumnDimension() + 1)) / 2.0); realVector = new Array2DRowRealMatrix(numEelements, 1); }
From source file:edu.dfci.cccb.mev.math.commons.mock.Array2DRealMatrixBuilder.java
@Override public RealMatrix build(int height, int width) throws MatrixBuilderException { return new Array2DRowRealMatrix(height, width); }
From source file:mr.go.sgfilter.SGFilter.java
/** * Computes Savitzky-Golay coefficients for given parameters * //from ww w . j a v a 2 s . c o m * @param nl * numer of past data points filter will use * @param nr * number of future data points filter will use * @param degree * order of smoothin polynomial * @return Savitzky-Golay coefficients * @throws IllegalArgumentException * if {@code nl < 0} or {@code nr < 0} or {@code nl + nr < * degree} */ public static double[] computeSGCoefficients(int nl, int nr, int degree) { if (nl < 0 || nr < 0 || nl + nr < degree) throw new IllegalArgumentException("Bad arguments"); Array2DRowRealMatrix matrix = new Array2DRowRealMatrix(degree + 1, degree + 1); double[][] a = matrix.getDataRef(); double sum; for (int i = 0; i <= degree; i++) { for (int j = 0; j <= degree; j++) { sum = (i == 0 && j == 0) ? 1 : 0; for (int k = 1; k <= nr; k++) sum += pow(k, i + j); for (int k = 1; k <= nl; k++) sum += pow(-k, i + j); a[i][j] = sum; } } double[] b = new double[degree + 1]; b[0] = 1; ArrayRealVector b1 = new ArrayRealVector(b); b1 = (ArrayRealVector) (new LUDecomposition(matrix)).getSolver().solve(b1); b = b1.toArray(); double[] coeffs = new double[nl + nr + 1]; for (int n = -nl; n <= nr; n++) { sum = b[0]; for (int m = 1; m <= degree; m++) sum += b[m] * pow(n, m); coeffs[n + nl] = sum; } return coeffs; }
From source file:com.itemanalysis.psychometrics.factoranalysis.QuartiminCriteria.java
public void computeValues(RealMatrix L) { int k = L.getColumnDimension(); int p = L.getRowDimension(); RealMatrix I = new IdentityMatrix(p); RealMatrix L2 = MatrixUtils.multiplyElements(L, L); RealMatrix N = new Array2DRowRealMatrix(k, k); N.walkInRowOrder(new DefaultRealMatrixChangingVisitor() { @Override/*from w ww . j a va2 s . c om*/ public double visit(int row, int column, double value) { if (row == column) return 0.0; return 1.0; } }); RealMatrix X = L2.multiply(N); double sum = MatrixUtils.sumMatrix(MatrixUtils.multiplyElements(L2, X)); functionValue = sum / 4.0; gradient = MatrixUtils.multiplyElements(L, X); }
From source file:com.cloudera.oryx.common.math.CommonsMathLinearSystemSolverTest.java
@Test public void testSolveDToF() { double[][] data = { new double[] { 1.0, 2.0 }, new double[] { 3.0, 5.0 } }; RealMatrix M = new Array2DRowRealMatrix(data, false); LinearSystemSolver cmLinearSystemSolver = new CommonsMathLinearSystemSolver(); Solver solver = cmLinearSystemSolver.getSolver(M); assertArrayEquals(new float[] { -12.0f, 7.0f }, solver.solveDToF(new double[] { 2.0, -1.0 })); }