List of usage examples for org.apache.commons.math3.linear RealMatrix getRowDimension
int getRowDimension();
From source file:org.pmad.gmm.HessenbergTransformer.java
/** * Build the transformation to Hessenberg form of a general matrix. * * @param matrix matrix to transform// w w w . j a v a 2 s . co m * @throws NonSquareMatrixException if the matrix is not square */ public HessenbergTransformer(final RealMatrix matrix) { if (!matrix.isSquare()) { throw new NonSquareMatrixException(matrix.getRowDimension(), matrix.getColumnDimension()); } final int m = matrix.getRowDimension(); householderVectors = matrix.getData(); ort = new double[m]; cachedP = null; cachedPt = null; cachedH = null; // transform matrix transform(); }
From source file:org.pmad.gmm.MyEDC.java
/** * Calculates the eigen decomposition of the given real matrix. * <p>//ww w. j av a 2 s .c o m * Supports decomposition of a general matrix since 3.1. * * @param matrix Matrix to decompose. * @throws MaxCountExceededException if the algorithm fails to converge. * @throws MathArithmeticException if the decomposition of a general matrix * results in a matrix with zero norm * @since 3.1 */ public MyEDC(final RealMatrix matrix) throws MathArithmeticException { final double symTol = 10 * matrix.getRowDimension() * matrix.getColumnDimension() * Precision.EPSILON; isSymmetric = MatrixUtils.isSymmetric(matrix, symTol); if (isSymmetric) { transformToTridiagonal(matrix); findEigenVectors(transformer.getQ().getData()); } else { final SchurTransformer t = transformToSchur(matrix); findEigenVectorsFromSchur(t); } }
From source file:org.pmad.gmm.SchurTransformer.java
/** * Build the transformation to Schur form of a general real matrix. * * @param matrix matrix to transform/* ww w. j a va 2s .com*/ * @throws NonSquareMatrixException if the matrix is not square */ public SchurTransformer(final RealMatrix matrix) { if (!matrix.isSquare()) { throw new NonSquareMatrixException(matrix.getRowDimension(), matrix.getColumnDimension()); } HessenbergTransformer transformer = new HessenbergTransformer(matrix); matrixT = transformer.getH().getData(); matrixP = transformer.getP().getData(); cachedT = null; cachedP = null; cachedPt = null; // transform matrix transform(); }
From source file:org.pmad.gmm.TriDiagonalTransformer.java
/** * Build the transformation to tridiagonal shape of a symmetrical matrix. * <p>The specified matrix is assumed to be symmetrical without any check. * Only the upper triangular part of the matrix is used.</p> * * @param matrix Symmetrical matrix to transform. * @throws NonSquareMatrixException if the matrix is not square. *//*from w ww. j a va 2 s . c o m*/ public TriDiagonalTransformer(RealMatrix matrix) { if (!matrix.isSquare()) { throw new NonSquareMatrixException(matrix.getRowDimension(), matrix.getColumnDimension()); } final int m = matrix.getRowDimension(); householderVectors = matrix.getData(); main = new double[m]; secondary = new double[m - 1]; cachedQ = null; cachedQt = null; cachedT = null; // transform matrix transform(); }
From source file:org.rhwlab.BHC.NodeBase.java
public Element formElementXML() { List<MicroCluster> micros = new ArrayList<>(); this.getDataAsMicroCluster(micros); int voxels = 0; long intensity = 0; for (MicroCluster micro : micros) { voxels = voxels + micro.getPointCount(); intensity = intensity + micro.getTotalIntensity(); }/*from www. j a va 2s . co m*/ RealVector mu = MicroCluster.mean(micros); RealMatrix W = MicroCluster.precision(micros, mu); if (W != null) { Element clusterEle = new Element("GaussianMixtureModel"); //clusterEle.setAttribute("id", String.format("%d", id)); // clusterEle.setAttribute("parent", "-1"); clusterEle.setAttribute("count", String.format("%d", micros.size())); clusterEle.setAttribute("voxels", String.format("%d", voxels)); clusterEle.setAttribute("intensity", String.format("%d", intensity)); clusterEle.setAttribute("intensityRSD", Double.toString(getIntensityRSD())); clusterEle.setAttribute("sourceNode", String.format("%d", label)); clusterEle.setAttribute("posterior", Double.toString(lnR)); clusterEle.setAttribute("x", Double.toString(mu.getEntry(0))); clusterEle.setAttribute("y", Double.toString(mu.getEntry(1))); clusterEle.setAttribute("z", Double.toString(mu.getEntry(2))); StringBuilder builder = new StringBuilder(); for (int row = 0; row < W.getRowDimension(); ++row) { for (int col = 0; col < W.getColumnDimension(); ++col) { if (row > 0 || col > 0) { builder.append(" "); } builder.append(W.getEntry(row, col)); } } clusterEle.setAttribute("precision", builder.toString()); return clusterEle; } else { return null; } }
From source file:org.rhwlab.BHCnotused.Cluster.java
public void saveAsXML(Element root, int id) throws Exception { Element clusterEle = new Element("GaussianMixtureModel"); clusterEle.setAttribute("id", String.format("%d", id)); clusterEle.setAttribute("parent", "-1"); StringBuilder builder = new StringBuilder(); for (int j = 0; j < data.getMean().getDimension(); ++j) { if (j > 0) { builder.append(" "); }//ww w. ja v a 2 s . co m builder.append(data.getMean().getEntry(j)); } clusterEle.setAttribute("m", builder.toString()); RealMatrix W = data.getPrecision(); builder = new StringBuilder(); for (int row = 0; row < W.getRowDimension(); ++row) { for (int col = 0; col < W.getColumnDimension(); ++col) { if (row > 0 || col > 0) { builder.append(" "); } builder.append(W.getEntry(row, col)); } } clusterEle.setAttribute("W", builder.toString()); clusterEle.setAttribute("pi", pi.toString()); clusterEle.setAttribute("likelihood", data.likelihood().toString()); clusterEle.setAttribute("DPM", dpm.toString()); clusterEle.setAttribute("posterior", r.toString()); clusterEle.setAttribute("d", d.toString()); clusterEle.addContent(data.asString()); root.addContent(clusterEle); }
From source file:org.rhwlab.dispim.nucleus.BHCNucleusData.java
public void printMat(String label, RealMatrix m) { System.out.println(label);/* ww w .j a v a 2s.c om*/ for (int r = 0; r < m.getRowDimension(); ++r) { for (int c = 0; c < m.getColumnDimension(); ++c) { System.out.printf("%f\t", m.getEntry(r, c)); } System.out.println(); } }
From source file:org.rhwlab.dispim.nucleus.Nucleus.java
private void reportMatrix(PrintStream stream, String label, RealMatrix m) { stream.printf("%s: ", label); for (int r = 0; r < m.getRowDimension(); ++r) { for (int c = 0; c < m.getColumnDimension(); ++c) { stream.printf("%f ", m.getEntry(r, c)); }// w w w . j a v a 2 s. co m stream.print(" : "); } stream.println(); }
From source file:org.rhwlab.dispim.nucleus.NucleusData.java
static public String precisionAsString(RealMatrix m) { StringBuffer buf = new StringBuffer(); for (int r = 0; r < m.getRowDimension(); ++r) { for (int c = 0; c < m.getColumnDimension(); ++c) { if (r != 0 || c != 0) { buf.append(" "); }//from ww w . ja va2 s . co m buf.append(Double.toString(m.getEntry(r, c))); } } return buf.toString(); }
From source file:org.rhwlab.variationalbayesian.GaussianMixture.java
public void reportMatrix(PrintStream str, String name, RealMatrix mat) { str.printf("%s\n", name); for (int r = 0; r < mat.getRowDimension(); ++r) { for (int c = 0; c < mat.getColumnDimension(); ++c) { str.printf(" %e", mat.getEntry(r, c)); }/*from ww w . j ava2 s. co m*/ str.println(); } }