コード例 #1
0
 public Map<String, Map<GM_Position, Double>> readMatResultsFile(final String pStrFilter) {
   MatFileReader lMatFileReader = null;
   final MatFileFilter lMatFilter = new MatFileFilter();
   Map<String, Map<GM_Position, Double>> lRes = null;
   try {
     if (pStrFilter != null) {
       lMatFilter.addArrayName(STR_XP_NAME);
       lMatFilter.addArrayName(STR_YP_NAME);
       lMatFilter.addArrayName(pStrFilter);
     }
     if (m_strResultsFile == null) {
       lMatFileReader = new MatFileReader(FileUtils.toFile(m_resultsFile.getURL()), lMatFilter);
     } else {
       lMatFileReader = new MatFileReader(m_strResultsFile, lMatFilter);
     }
   } catch (final Exception e) {
     // throw new MatlabIOException( "Cannot open or read SWAN result matlab file." );
   }
   if (lMatFileReader != null) {
     try {
       final GM_Position lShiftPosition =
           SWANDataConverterHelper.readCoordinateShiftValues(m_resultsFile);
       m_doubleShiftX = lShiftPosition.getX();
       m_doubleShiftY = lShiftPosition.getY();
       final Map<String, MLArray> lMapData = lMatFileReader.getContent();
       // printDebugParsedSWANRawData( lMatFileReader, null );
       lRes = getValuesFormatedNameDatePosition(lMapData);
       // printDebugResultData( lRes, null );
     } catch (final Exception e) {
       e.printStackTrace();
     }
   }
   return lRes;
 }
コード例 #2
0
  public void callCPLEXOptimizer(double startTime, int horizon, double rebWeight)
      throws FileNotFoundException, IOException {
    // Call MATLAB script to generate trips
    new_routes = new HashMap<Link, Set<Path>>();
    new_reb_routes = new HashMap<Link, Set<Path>>();
    // MATLAB OPTIMIZER RUNS HERE
    MatFileReader matfilereader = new MatFileReader("src/main/resources/optimizerpaths.mat");
    MLCell passpaths = (MLCell) matfilereader.getMLArray("passpaths");
    MLCell rebpaths = (MLCell) matfilereader.getMLArray("rebpaths");
    System.out.println("OPTMIZING");

    decomposePassPaths(new_routes, passpaths);
    decomposePassPaths(new_reb_routes, rebpaths);
  }
コード例 #3
0
ファイル: Ex3Test.java プロジェクト: artem-spector/ml-java
  @BeforeClass
  public static void loadData() throws Exception {
    MatFileReader reader = new MatFileReader("machine-learning-ex3/ex3/ex3data1.mat");
    Map<String, MLArray> content = reader.getContent();
    Assert.assertNotNull(content);

    X = factory.createMatrix(((MLDouble) content.get("X")).getArray());
    y = factory.createMatrix(((MLDouble) content.get("y")).getArray());
    System.out.println("X: " + X.numRows() + "*" + X.numColumns());
    System.out.println("y: " + y.numRows() + "*" + y.numColumns());
    assertEquals(X.numRows(), y.numRows());
    assertEquals(1, y.numColumns());

    double[][] images = new double[100][];
    int[] randIndexes = new ArrayUtil().randperm(X.numRows());
    for (int i = 0; i < images.length; i++) images[i] = X.getRow(randIndexes[i]).asArray();
    String[] labels = new String[images.length];
    for (int i = 0; i < labels.length; i++)
      labels[i] = String.valueOf((int) y.get(randIndexes[i], 0));

    JPanel panel = displayUtil.createImageGrid(images, 20, 20, 2, labels);
    displayUtil.saveImage(panel, "./target/Ex3TrainingSample.png");
  }
コード例 #4
0
 // debug only: raw text output of results
 private static void printDebugParsedSWANRawData(final MatFileReader mfr, final String outputPath)
     throws IOException, MatlabIOException {
   String outputPathTmp = "d:/temp/MatReaderOut-"; // $NON-NLS-1$
   if (outputPath != null && !"".equals(outputPath)) // $NON-NLS-1$
   {
     outputPathTmp = outputPath;
   }
   final Map<String, MLArray> lMapData = mfr.getContent();
   final FileWriter fstream = new FileWriter(outputPathTmp + (new Date()).getTime());
   final BufferedWriter out = new BufferedWriter(fstream);
   final Set<String> lSetKeys = lMapData.keySet();
   for (final String lStrKey : lSetKeys) {
     final MLArray lValues = lMapData.get(lStrKey);
     out.write(lValues.contentToString());
   }
   out.close();
 }