public List<MLArray> smallsignalMLArray(Double stepMin, Double varMin, Double f1, Double f2, Double d1, Double d2, Double d3, Double nm, Double fInstant, Double fDuration) { MLDouble mStepMin = new MLDouble("step_min", new double[]{stepMin}, 1); MLDouble mVarMin = new MLDouble("var_min", new double[]{varMin}, 1); MLDouble mF = new MLDouble("f", new double[]{f1, f2}, 1); MLDouble mD = new MLDouble("d", new double[]{d1, d2, d3}, 1); MLDouble mNm = new MLDouble("Nm", new double[]{nm}, 1); MLDouble mFInstant = new MLDouble("f_instant", new double[] {fInstant}, 1); MLDouble mFDuration = new MLDouble("f_duration", new double[] {fDuration}, 1); List<MLArray> mlarray = Arrays.asList(mStepMin, mVarMin, mF, mD, mNm, mFInstant, mFDuration); return mlarray; }
public List<MLArray> transientMLArray() { //currently, this index does not require any parameters .. //let's create a DUMMY one MLDouble mP = new MLDouble("DUMMY", new double[] {0.0}, 1); List<MLArray> mlarray = Arrays.asList(mP); return mlarray; }
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); String name = (String) s.readObject(); double[][] values = (double[][]) s.readObject(); matrix = new MLDouble(name, values); }
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 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; }
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 static void writeWP41ContinuousInputMatFile(Path outputfile, double[][] idata, int nsamples, double ir, double k) throws IOException { MLDouble dNsample = new MLDouble("N_Sample", new double[]{nsamples}, 1); MLDouble dIR = new MLDouble("IR", new double[]{ir}, 1); MLDouble dK = new MLDouble("K", new double[]{k}, 1); MLDouble data = Utils.matToMLDouble(idata, "X"); List<MLArray> mlarray = new ArrayList<>(); mlarray.add((MLArray) dNsample); mlarray.add((MLArray) dIR); mlarray.add((MLArray) dK); mlarray.add((MLArray) data); MatFileWriter writer = new MatFileWriter(); writer.write(outputfile.toFile(), mlarray); }
public MLDenseDoubleMatrix(long... size) { super(size); if (Coordinates.product(size) > 0) { this.matrix = new MLDouble("matrix" + System.nanoTime(), MathUtil.toIntArray(size)); init(); } }
/** * @param m * @return a {@link MLDouble} for matlab */ public static MLDouble asMatlab(Matrix m) { final double[][] retArr = new double[m.rowCount()][m.columnCount()]; for (int i = 0; i < retArr.length; i++) { for (int j = 0; j < retArr[i].length; j++) { retArr[i][j] = m.get(i, j); } } final MLDouble ret = new MLDouble("out", retArr); return ret; }
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; }
public MLDenseDoubleMatrix(Matrix m) { super(m.getSize()); if (m.getMetaData() != null) { setMetaData(m.getMetaData().clone()); this.matrix = new MLDouble(m.getLabel(), MathUtil.toIntArray(m.getSize())); } else { this.matrix = new MLDouble("matrix" + System.nanoTime(), MathUtil.toIntArray(m .getSize())); } init(); for (long[] c : m.availableCoordinates()) { setAsDouble(m.getAsDouble(c), c); } }
/** * 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 testMLStructureFieldNames() throws IOException { // test column-packed vector double[] src = new double[]{1.3, 2.0, 3.0, 4.0, 5.0, 6.0}; // create 3x2 double matrix // [ 1.0 4.0 ; // 2.0 5.0 ; // 3.0 6.0 ] MLDouble mlDouble = new MLDouble(null, src, 3); MLChar mlChar = new MLChar(null, "I am dummy"); MLStructure mlStruct = new MLStructure("str", new int[]{1, 1}); mlStruct.setField("f1", mlDouble); mlStruct.setField("f2", mlChar); Collection<String> fieldNames = mlStruct.getFieldNames(); assertEquals(2, fieldNames.size()); assertTrue(fieldNames.contains("f1")); assertTrue(fieldNames.contains("f2")); }