public MatrixWritable(Matrix m) { set(m); }
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 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); }
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); }