private static void doTestMatrixWritableEquals(Matrix m) throws IOException { Writable matrixWritable = new MatrixWritable(m); MatrixWritable matrixWritable2 = new MatrixWritable(); writeAndRead(matrixWritable, matrixWritable2); Matrix m2 = matrixWritable2.get(); compareMatrices(m, m2); doCheckBindings(m2.getRowLabelBindings()); doCheckBindings(m2.getColumnLabelBindings()); }
private static void addToSavedCopy(File file, Matrix matrix) throws IOException { MatrixWritable mw = new MatrixWritable(); if (file.exists()) { try (DataInputStream in = new DataInputStream(new FileInputStream(file))) { mw.readFields(in); } mw.get().assign(matrix, Functions.PLUS); } else { mw.set(matrix); } try (DataOutputStream out = new DataOutputStream(new FileOutputStream(file))) { mw.write(out); } }
private static void addToSavedCopy(File file, Matrix matrix) throws IOException { MatrixWritable mw = new MatrixWritable(); if (file.exists()) { DataInputStream in = new DataInputStream(new FileInputStream(file)); try { mw.readFields(in); } finally { in.close(); } mw.get().assign(matrix, Functions.PLUS); } else { mw.set(matrix); } DataOutputStream out = new DataOutputStream(new FileOutputStream(file)); try { mw.write(out); } finally { out.close(); } }
private static void addToSavedCopy(File file, Matrix matrix) throws IOException { MatrixWritable mw = new MatrixWritable(); if (file.exists()) { DataInputStream in = new DataInputStream(new FileInputStream(file)); try { mw.readFields(in); } finally { in.close(); } mw.get().assign(matrix, Functions.PLUS); } else { mw.set(matrix); } DataOutputStream out = new DataOutputStream(new FileOutputStream(file)); try { mw.write(out); } finally { out.close(); } }
public void computeV(File tmpDir, int ncols) throws IOException { // step 5, compute pieces of V for (int j = 0; j < ncols; j += columnsPerSlice) { File bPath = bFile(tmpDir, j); if (bPath.exists()) { MatrixWritable m = new MatrixWritable(); try (DataInputStream in = new DataInputStream(new FileInputStream(bPath))) { m.readFields(in); } m.set(l2.solveRight(m.get().transpose()).times(svd.getV())); try (DataOutputStream out = new DataOutputStream(new FileOutputStream( new File(tmpDir, String.format("V-%s", bPath.getName().replaceAll(".*-", "")))))) { m.write(out); } } } }
public void computeU(Iterable<File> partsOfA, File tmpDir) throws IOException { // step 4, compute pieces of U for (File file : partsOfA) { MatrixWritable m = new MatrixWritable(); m.readFields(new DataInputStream(new FileInputStream(file))); Matrix aI = m.get(); Matrix y = aI.times(new RandomTrinaryMatrix(seed, aI.numCols(), dim, false)); Matrix uI = r2.solveRight(y).times(svd.getU()); m.set(uI); try (DataOutputStream out = new DataOutputStream(new FileOutputStream( new File(tmpDir, String.format("U-%s", file.getName().replaceAll(".*-", "")))))) { m.write(out); } } }
public void computeU(Iterable<File> partsOfA, File tmpDir) throws IOException { // step 4, compute pieces of U for (File file : partsOfA) { MatrixWritable m = new MatrixWritable(); m.readFields(new DataInputStream(new FileInputStream(file))); Matrix aI = m.get(); Matrix y = aI.times(new RandomTrinaryMatrix(seed, aI.numCols(), dim, false)); Matrix uI = r2.solveRight(y).times(svd.getU()); m.set(uI); DataOutputStream out = new DataOutputStream(new FileOutputStream( new File(tmpDir, String.format("U-%s", file.getName().replaceAll(".*-", ""))))); try { m.write(out); } finally { out.close(); } } }
public void computeU(Iterable<File> partsOfA, File tmpDir) throws IOException { // step 4, compute pieces of U for (File file : partsOfA) { MatrixWritable m = new MatrixWritable(); m.readFields(new DataInputStream(new FileInputStream(file))); Matrix aI = m.get(); Matrix y = aI.times(new RandomTrinaryMatrix(seed, aI.numCols(), dim, false)); Matrix uI = r2.solveRight(y).times(svd.getU()); m.set(uI); DataOutputStream out = new DataOutputStream(new FileOutputStream( new File(tmpDir, String.format("U-%s", file.getName().replaceAll(".*-", ""))))); try { m.write(out); } finally { out.close(); } } }
public void computeV(File tmpDir, int ncols) throws IOException { // step 5, compute pieces of V for (int j = 0; j < ncols; j += columnsPerSlice) { File bPath = bFile(tmpDir, j); if (bPath.exists()) { MatrixWritable m = new MatrixWritable(); DataInputStream in = new DataInputStream(new FileInputStream(bPath)); try { m.readFields(in); } finally { in.close(); } m.set(l2.solveRight(m.get().transpose()).times(svd.getV())); DataOutputStream out = new DataOutputStream(new FileOutputStream( new File(tmpDir, String.format("V-%s", bPath.getName().replaceAll(".*-", ""))))); try { m.write(out); } finally { out.close(); } } } }
public void computeV(File tmpDir, int ncols) throws IOException { // step 5, compute pieces of V for (int j = 0; j < ncols; j += columnsPerSlice) { File bPath = bFile(tmpDir, j); if (bPath.exists()) { MatrixWritable m = new MatrixWritable(); DataInputStream in = new DataInputStream(new FileInputStream(bPath)); try { m.readFields(in); } finally { in.close(); } m.set(l2.solveRight(m.get().transpose()).times(svd.getV())); DataOutputStream out = new DataOutputStream(new FileOutputStream( new File(tmpDir, String.format("V-%s", bPath.getName().replaceAll(".*-", ""))))); try { m.write(out); } finally { out.close(); } } } }
static HmmModel deserialize(DataInput input) throws IOException { MatrixWritable matrix = new MatrixWritable(); matrix.readFields(input); Matrix emissionMatrix = matrix.get(); matrix.readFields(input); Matrix transitionMatrix = matrix.get(); VectorWritable vector = new VectorWritable(); vector.readFields(input); Vector initialProbabilities = vector.get(); return new HmmModel(transitionMatrix, emissionMatrix, initialProbabilities); }
static HmmModel deserialize(DataInput input) throws IOException { MatrixWritable matrix = new MatrixWritable(); matrix.readFields(input); Matrix emissionMatrix = matrix.get(); matrix.readFields(input); Matrix transitionMatrix = matrix.get(); VectorWritable vector = new VectorWritable(); vector.readFields(input); Vector initialProbabilities = vector.get(); return new HmmModel(transitionMatrix, emissionMatrix, initialProbabilities); }
static HmmModel deserialize(DataInput input) throws IOException { MatrixWritable matrix = new MatrixWritable(); matrix.readFields(input); Matrix emissionMatrix = matrix.get(); matrix.readFields(input); Matrix transitionMatrix = matrix.get(); VectorWritable vector = new VectorWritable(); vector.readFields(input); Vector initialProbabilities = vector.get(); return new HmmModel(transitionMatrix, emissionMatrix, initialProbabilities); }
inverseCovarianceMatrix.readFields(in); this.inverseCovarianceMatrix = inverseCovarianceMatrix.get(); Preconditions.checkArgument(this.inverseCovarianceMatrix != null, "inverseCovarianceMatrix not initialized");
Closeables.close(in, true); this.inverseCovarianceMatrix = inverseCovarianceMatrix.get(); Preconditions.checkArgument(this.inverseCovarianceMatrix != null, "inverseCovarianceMatrix not initialized");
Closeables.close(in, true); this.inverseCovarianceMatrix = inverseCovarianceMatrix.get(); Preconditions.checkArgument(this.inverseCovarianceMatrix != null, "inverseCovarianceMatrix not initialized");
private static void doTestMatrixWritableEquals(Matrix m) throws IOException { Writable matrixWritable = new MatrixWritable(m); MatrixWritable matrixWritable2 = new MatrixWritable(); writeAndRead(matrixWritable, matrixWritable2); Matrix m2 = matrixWritable2.get(); compareMatrices(m, m2); doCheckBindings(m2.getRowLabelBindings()); doCheckBindings(m2.getColumnLabelBindings()); }