List of usage examples for org.apache.commons.math.linear RealMatrix getData
double[][] getData();
From source file:com.opengamma.analytics.math.util.wrapper.CommonsMathWrapper.java
/** * @param x A Commons matrix, not null// w w w . j a v a2 s . c om * @return An OG 2-D matrix of doubles */ public static DoubleMatrix2D unwrap(final RealMatrix x) { Validate.notNull(x); return new DoubleMatrix2D(x.getData()); }
From source file:juicebox.tools.utils.juicer.apa.APAUtils.java
public static double peakEnhancement(RealMatrix matrix) { int rows = matrix.getRowDimension(); int center = rows / 2; double centerVal = matrix.getEntry(center, center); double remainingSum = APARegionStatistics.sum(matrix.getData()) - centerVal; double remainingAverage = remainingSum / (rows * rows - 1); return centerVal / remainingAverage; }
From source file:juicebox.tools.utils.common.MatrixTools.java
/** * print for matrix */ public static void print(RealMatrix matrix) { print(matrix.getData()); }
From source file:juicebox.tools.utils.common.MatrixTools.java
/** * @return minimal positive entry in the matrix greater than 0 *//*from ww w .j a v a 2 s .c o m*/ public static double minimumPositive(RealMatrix data) { return minimumPositive(data.getData()); }
From source file:juicebox.tools.utils.common.MatrixTools.java
/** * @return mean of matrix/*from ww w . j av a 2 s . com*/ */ public static double mean(RealMatrix matrix) { return APARegionStatistics.statistics(matrix.getData()).getMean(); }
From source file:juicebox.tools.utils.juicer.apa.APAPlotter.java
/** * Method for plotting apa data/*from w ww. j a v a 2 s . co m*/ * * @param data for heat map * @param axesRange initial values and increments to annotate axes [x0, dx, y0, dy] * @param outputFile where image will saved */ public static void plot(RealMatrix data, int[] axesRange, File outputFile, String title) { APARegionStatistics apaStats = new APARegionStatistics(data); DecimalFormat df = new DecimalFormat("0.000"); title += ", P2LL = " + df.format(apaStats.getPeak2LL()); // initialize heat map HeatChart map = new HeatChart(data.getData()); map.setLowValueColour(Color.WHITE); map.setHighValueColour(Color.RED); map.setXValues(axesRange[0], axesRange[1]); map.setYValues(axesRange[2], axesRange[3]); map.setTitle(title); try { // calculate dimensions for plot wrapper initializeSizes(map); // create blank white image BufferedImage apaImage = new BufferedImage(fullWidth, fullHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = apaImage.createGraphics(); g2.setBackground(Color.WHITE); g2.fillRect(0, 0, fullWidth, fullHeight); // plot in heat map, color bar, etc g2.drawImage(map.getChartImage(), 0, 0, heatmapWidth, fullHeight, null); drawHeatMapBorder(g2, map); plotColorScaleBar(g2); plotColorScaleValues(g2, map); // top left, top right, bottom left, bottom right values (from apa) drawCornerRegions(g2, map, new Dimension(APA.regionWidth, APA.regionWidth), apaStats.getRegionCornerValues()); // save data ImageIO.write(apaImage, "png", outputFile); } catch (IOException e) { e.printStackTrace(); } }
From source file:juicebox.tools.utils.common.MatrixTools.java
/** * Write data from matrix out to specified file with each row on a separate line * * @param filename/*from w ww . j a va2s.c om*/ * @param realMatrix */ public static void saveMatrixText(String filename, RealMatrix realMatrix) { Writer writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "utf-8")); double[][] matrix = realMatrix.getData(); for (double[] row : matrix) { writer.write(Arrays.toString(row) + "\n"); } } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (writer != null) writer.close(); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:edu.cudenver.bios.matrixsvc.application.NamedRealMatrix.java
public NamedRealMatrix(RealMatrix matrix) { super(); this.data = matrix.getData(); }
From source file:com.opengamma.analytics.math.util.wrapper.CommonsMathWrapperTest.java
@Test public void testVectorAsMatrix() { final RealMatrix commons = CommonsMathWrapper.wrapAsMatrix(OG_VECTOR); final double[][] data = commons.getData(); assertEquals(data.length, OG_VECTOR.getNumberOfElements()); assertEquals(data[0].length, 1);/*from w w w .j a v a 2s . c o m*/ }
From source file:com.cloudera.science.ml.client.cmd.KMeansOutlierCommand.java
@Override public int execute(Configuration conf) throws IOException { List<MLClusterCovariance> ccov = AvroIO.read(MLClusterCovariance.class, new File(covFile)); Map<ClusterKey, MahalanobisDistance> distances = Maps.newHashMap(); for (MLClusterCovariance cc : ccov) { int dim = cc.getMeans().size(); RealMatrix m = MatrixUtils.toRealMatrix(dim, dim, cc.getCov(), true); RealMatrix im = Inverter.SVD.apply(m); // pseudo-inverse works fine for this MahalanobisDistance md = new MahalanobisDistance(toArray(cc.getMeans()), im.getData(), cc.getCount()); distances.put(new ClusterKey(cc.getClusteringId(), cc.getCenterId()), md); }/*from www .j a v a 2 s . co m*/ Pipeline p = pipelineParams.create(KMeansOutlierCommand.class, conf); PCollection<NamedVector> vecs = inputParams.getVectors(p); KMeansParallel kmp = new KMeansParallel(); List<Centers> centers = centersParams.getCenters(); List<Integer> centerIds = centersParams.getCenterIds(); validate(centers, centerIds, distances); Records outliers = kmp.computeOutliers(vecs, centers, approx, centerIds, distances); outputParams.writeRecords(outliers.get(), outliers.getSpec(), outliersPath); p.done(); return 0; }