public static MLDouble vectToMLDouble(double[] dvect, String mName) throws NumberFormatException { if (dvect == null) { throw new NumberFormatException(".. must not be null"); } MLDouble mlDouble = new MLDouble(mName, new int[] {dvect.length, 1}); for (int i = 0; i < dvect.length; i++) { mlDouble.set(new Double(dvect[i]), i, 0); } return mlDouble; }
private static MLArray toMLArray(FloatFV fvec) { final MLDouble data = new MLDouble("fisherface", new int[] { fvec.values.length, 1 }); for (int i = 0; i < fvec.values.length; i++) { data.set((double) fvec.values[i], i, 0); } return data; }
private static MLArray toMLArray(FloatFV fvec) { final MLDouble data = new MLDouble("fisherface", new int[] { fvec.values.length, 1 }); for (int i = 0; i < fvec.values.length; i++) { data.set((double) fvec.values[i], i, 0); } return data; }
private static MLArray toMLArray(FloatFV fvec) { final MLDouble data = new MLDouble("fisherface", new int[] { fvec.values.length, 1 }); for (int i = 0; i < fvec.values.length; i++) { data.set((double) fvec.values[i], i, 0); } return data; }
private static MLArray toMLArray(FloatFV fvec) { final MLDouble data = new MLDouble("fisherface", new int[] { fvec.values.length, 1 }); for (int i = 0; i < fvec.values.length; i++) { data.set((double) fvec.values[i], i, 0); } return data; }
public static MLDouble matToMLDouble(double[][] dmat, String mName) throws NumberFormatException { if (dmat == null) { throw new NumberFormatException(".. must not be null"); } MLDouble mlDouble = new MLDouble(mName, new int[]{dmat.length, dmat[0].length}); for (int i = 0; i < dmat.length; i++) { for (int j = 0; j < dmat[0].length; j++) { mlDouble.set(new Double(dmat[i][j]), i, j); } } return mlDouble; }
public static MLDouble vectToMLDoubleRow(double[] dvect, String mName) throws NumberFormatException { if (dvect == null) { throw new NumberFormatException(".. must not be null"); } MLDouble mlDouble = new MLDouble(mName, new int[]{1, dvect.length}); for (int i = 0; i < dvect.length; i++) { mlDouble.set(new Double(dvect[i]), 0, i); } return mlDouble; }
public synchronized void setDouble(double value, long... coordinates) { matrix.set(value, getIndex(coordinates)); }
private MLDouble histoDataAsMLDouble(String name, ArrayTable<Integer, String, Float> histoData) { int rowsSize = histoData.rowKeySet().size(); int colsSize = histoData.columnKeySet().size(); MLDouble mlDouble = new MLDouble(name, new int[] {rowsSize, colsSize}); int i = 0; for (Integer rowKey : histoData.rowKeyList()) { int j = 0; for (String colkey : histoData.columnKeyList()) { Float v = histoData.get(rowKey, colkey); mlDouble.set(new Double(v), i, j); j++; } i++; } return mlDouble; }
public static MLDouble readMDoubleFromCSVFile(Path inFilePath, String mName, int nrows, int ncols, char delimiter) throws NumberFormatException, IOException { MLDouble mlDouble = new MLDouble(mName, new int[] {nrows, ncols}); CsvReader cvsReader = new CsvReader(inFilePath.toString()); cvsReader.setDelimiter(delimiter); int i = 0; while (cvsReader.readRecord()) { String[] rows = cvsReader.getValues(); int j = 0; for (String col : rows) { mlDouble.set(new Double(col), i, j); j++; } i++; } return mlDouble; }
/** * Convert a matlab {@link MLArray} to a {@link Matrix} * * @param name * @param mat * * @return the matrix */ public static MLArray toMLArray(String name, Matrix mat) { final MLDouble mlArrayDbl = new MLDouble(name, new int[] { mat.getNumRows(), mat.getNumColumns() }); for (final MatrixEntry matrixEntry : mat) { mlArrayDbl.set(matrixEntry.getValue(), matrixEntry.getRowIndex(), matrixEntry.getColumnIndex()); } return mlArrayDbl; }
@Test public void testBenchmarkDouble() throws Exception { final String fileName = "bb.mat"; final String name = "bigdouble"; final int SIZE = 1000; MLDouble mlDouble = new MLDouble(name, new int[]{SIZE, SIZE}); for (int i = 0; i < SIZE * SIZE; i++) { mlDouble.set((double) i, i); } // write array to file ArrayList<MLArray> list = new ArrayList<MLArray>(); list.add(mlDouble); // write arrays to file new MatFileWriter(getTempFile(fileName), list); // read array form file MatFileReader mfr = new MatFileReader(getTempFile(fileName)); MLArray mlArrayRetrived = mfr.getMLArray(name); // test if MLArray objects are equal assertEquals("Test if value red from file equals value stored", mlDouble, mlArrayRetrived); }