List of usage examples for org.apache.commons.math3.linear RealMatrix getEntry
double getEntry(int row, int column) throws OutOfRangeException;
From source file:com.github.dougkelly88.FLIMPlateReaderGUI.InstrumentInterfaceClasses.XYZMotionInterface.java
public static AffineTransform deriveAffineTransform(Point2D.Double[] xplt, Point2D.Double[] stage) { // GENERAL CASE: // if S is stage space and P is XPLT plate space, // and T is the matrix to transform between the two: // S = TP//from w w w .ja va 2 s .c om // SP^-1 = TPP^-1 // T = SP^-1; // where S is a 2x3 matrix with 3 points, T is a 2x3 matrix and P is a // 3x3 matrix with 3 points and the bottom row occupied by ones... double[][] Parr = { { xplt[0].getX(), xplt[1].getX(), xplt[2].getX() }, { xplt[0].getY(), xplt[1].getY(), xplt[2].getY() }, { 1, 1, 1 } }; RealMatrix P = MatrixUtils.createRealMatrix(Parr); double[][] Sarr = { { stage[0].getX(), stage[1].getX(), stage[2].getX() }, { stage[0].getY(), stage[1].getY(), stage[2].getY() } }; RealMatrix S = MatrixUtils.createRealMatrix(Sarr); RealMatrix Pinv = (new LUDecomposition(P)).getSolver().getInverse(); RealMatrix transformationMatrix = S.multiply(Pinv); double m00 = transformationMatrix.getEntry(0, 0); double m01 = transformationMatrix.getEntry(0, 1); double m02 = transformationMatrix.getEntry(0, 2); double m10 = transformationMatrix.getEntry(1, 0); double m11 = transformationMatrix.getEntry(1, 1); double m12 = transformationMatrix.getEntry(1, 2); return new AffineTransform(m00, m10, m01, m11, m02, m12); }
From source file:edu.oregonstate.eecs.mcplan.ml.HilbertSpace.java
public static double inner_prod(final RealVector x, final RealMatrix M, final RealVector y) { // return x.dotProduct( M.operate( y ) ); double s = 0.0; for (int i = 0; i < M.getRowDimension(); ++i) { for (int j = 0; j < M.getColumnDimension(); ++j) { s += x.getEntry(i) * M.getEntry(i, j) * y.getEntry(j); }/*from w w w . j a v a 2s .c om*/ } return s; }
From source file:gedi.util.MathUtils.java
public static double colSum(RealMatrix m, int c) { double re = 0; for (int i = 0; i < m.getColumnDimension(); i++) re += m.getEntry(i, c); return re;// w w w.ja v a 2 s . c o m }
From source file:ffnn.FFNNTubesAI.java
public static void printMatrix(RealMatrix m, int row, int col) { for (int j = 0; j < row; j++) { for (int i = 0; i < col; i++) { System.out.print(m.getEntry(j, i) + " "); }/*from w w w. ja va2 s. c o m*/ System.out.println(); } System.out.println(); }
From source file:lsafunctions.LSA.java
public static RealMatrix calculateTfIdf(RealMatrix M) { int tf;//w w w . j av a 2s .co m double idf; int df; double ndf; for (int j = 0; j < M.getRowDimension(); j++) { df = calcDf(j, M); // System.out.println("J:"+j+" df:"+df); for (int k = 0; k < M.getColumnDimension(); k++) { tf = (int) M.getEntry(j, k); ndf = M.getColumnDimension() / df; idf = Math.log(ndf) / Math.log(2); M.setEntry(j, k, idf * tf); } } //M.print(NumberFormat.INTEGER_FIELD, M.getColumnDimension()); M = normalizeMatrix(M); return M; }
From source file:game.utils.Utils.java
public static String matrixToString(RealMatrix matrix) { StringBuilder ret = new StringBuilder(); for (int i = 0; i < matrix.getRowDimension(); i++) { for (int j = 0; j < matrix.getColumnDimension(); j++) { ret.append(String.format("%.5f", matrix.getEntry(i, j))); if (j == matrix.getColumnDimension() - 1) ret.append('\n'); else//from w w w . j a va 2 s .com ret.append(", "); } } return ret.toString(); }
From source file:edu.cudenver.bios.matrix.MatrixUtilities.java
/** * Force a square RealMatrix to be symmetric. * * @param rm The RealMatrix.// w ww . ja v a 2 s.com * * @return The same RealMatrix, modified if necessary * to be symmetric. * * @throws NonSquareMatrixException if the RealMatrix is * not square. */ public static RealMatrix forceSymmetric(RealMatrix rm) { int m = rm.getRowDimension(); int n = rm.getColumnDimension(); if (m != n) { throw new NonSquareMatrixException(m, n); } for (int i = 0; i < m; ++i) { for (int j = i + 1; j < n; ++j) { double value = (rm.getEntry(i, j) + rm.getEntry(j, i)) / 2; rm.setEntry(i, j, value); rm.setEntry(j, i, value); } } return rm; }
From source file:edu.byu.nlp.stats.GammaDistribution.java
/** * Samples a new Gamma distributed random variate for each parameter setting specified as elements * of the shapes matrix./*w w w. ja v a 2 s. co m*/ */ public static double[][] sample(RealMatrix shapes, RandomGenerator rnd) { double[][] gammas = new double[shapes.getRowDimension()][shapes.getColumnDimension()]; for (int i = 0; i < shapes.getRowDimension(); i++) { for (int j = 0; j < shapes.getColumnDimension(); j++) { gammas[i][j] = sample(shapes.getEntry(i, j), rnd); } } return gammas; }
From source file:ch.zhaw.iamp.rct.weights.Weights.java
private static void matrixToCsv(final RealMatrix matrix, final String targetFilePath) throws IOException { Writer out = new FileWriter(targetFilePath); for (int i = 0; i < matrix.getRowDimension(); ++i) { for (int j = 0; j < matrix.getColumnDimension(); ++j) { out.append("" + matrix.getEntry(i, j)); if (j < matrix.getColumnDimension() - 1) { out.append(","); }//from w w w.ja v a2 s . com } out.append("\n"); out.flush(); } }
From source file:dataGen.DataGen.java
/** * Do the yet created data stored in the matrix fulfill the Anti-Correlation condition? * Returns true if all correlation coefficients are below the Supremum correlation coefficient. * @param corrMatrix/*from www . j a va2 s .com*/ * The Data-Matrix * @param corrCoeff * the Supremum correlation coefficient * @param dimensions * how many dimensions does the test file have? * @return * true if all correlation coefficients are below the Supremum correlation coefficient. */ public static boolean isCorrMatrixCompleteValid(RealMatrix corrMatrix, double corrCoeff, int dimensions) { for (int i = 1; i < corrMatrix.getColumnDimension(); i++) { for (int j = 0; j < i; j++) { if (corrMatrix.getEntry(i, j) > corrCoeff) { return false; } } } return true; }