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 void serialize(HmmModel model, DataOutput output) throws IOException { MatrixWritable matrix = new MatrixWritable(model.getEmissionMatrix()); matrix.write(output); matrix.set(model.getTransitionMatrix()); matrix.write(output); VectorWritable vector = new VectorWritable(model.getInitialProbabilities()); vector.write(output); }
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); }
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()); }
static void serialize(HmmModel model, DataOutput output) throws IOException { MatrixWritable matrix = new MatrixWritable(model.getEmissionMatrix()); matrix.write(output); matrix.set(model.getTransitionMatrix()); matrix.write(output); VectorWritable vector = new VectorWritable(model.getInitialProbabilities()); vector.write(output); }
static void serialize(HmmModel model, DataOutput output) throws IOException { MatrixWritable matrix = new MatrixWritable(model.getEmissionMatrix()); matrix.write(output); matrix.set(model.getTransitionMatrix()); matrix.write(output); VectorWritable vector = new VectorWritable(model.getInitialProbabilities()); vector.write(output); }
MatrixWritable m = new MatrixWritable(); try (DataInputStream in = new DataInputStream(new FileInputStream(file))) { m.readFields(in); MatrixWritable m = new MatrixWritable(); try (DataInputStream in = new DataInputStream(new FileInputStream(file))) { m.readFields(in); MatrixWritable bTmp = new MatrixWritable(); for (int j = 0; j < ncols; j += columnsPerSlice) { if (bFile(tmpDir, j).exists()) {
private static Matrix lowRankMatrix(File tmpDir, String aBase, int rowsPerSlice, int rows, int columns) throws IOException { int rank = 10; Matrix u = new RandomTrinaryMatrix(1, rows, rank, false); Matrix d = new DenseMatrix(rank, rank); d.set(0, 0, 5); d.set(1, 1, 3); d.set(2, 2, 1); d.set(3, 3, 0.5); Matrix v = new RandomTrinaryMatrix(2, columns, rank, false); Matrix a = u.times(d).times(v.transpose()); if (tmpDir != null) { for (int i = 0; i < a.rowSize(); i += rowsPerSlice) { MatrixWritable m = new MatrixWritable(a.viewPart(i, Math.min(a.rowSize() - i, rowsPerSlice), 0, a.columnSize())); DataOutputStream out = new DataOutputStream(new FileOutputStream(new File(tmpDir, String.format("%s-%09d", aBase, i)))); try { m.write(out); } finally { out.close(); } } } return a; } }
Matrix r = null; MatrixWritable m = new MatrixWritable();