예제 #1
0
 public void run() {
   // method = new StatisticalBestLocal();
   // mt.test(method, trainDataSource, testDataSource);
   method = new Statistical();
   for (int i = 0; i < nom.length; i++) {
     for (int j = 0; j < num.length; j++) {
       for (int k = 0; k < list.length; k++) {
         method.setNominalNorm(nom[i]);
         if (num[j] instanceof prefwork.normalizer.THOrdinalNormalizer) {
           for (int k2 = 1; k2 < 5; k2++) {
             prefwork.normalizer.THOrdinalNormalizer th =
                 (prefwork.normalizer.THOrdinalNormalizer) num[j];
             th.setMode(new String[] {"", "" + k2});
             method.setNumericalNorm(num[j]);
             method.setListNorm(list[k]);
             mt.test(method, trainDataSource, testDataSource);
           }
         } else {
           method.setNumericalNorm(num[j]);
           method.setListNorm(list[k]);
           mt.test(method, trainDataSource, testDataSource);
         }
       }
     }
   }
   semRuns.release();
 }
예제 #2
0
  @SuppressWarnings("unchecked")
  public void test() {
    try {
      confMonoTests.setFileName("confMonoTests.xml");
      confDbs.setFileName("confDbs.xml");
      confDatasources.setFileName("confDatasources.xml");

      confMonoTests.load();
      confDbs.load();
      confDatasources.load();

      List<String> runs = confMonoTests.getList("run");
      log.info("Start of testing");
      // runs = new TestRun[confRuns.getInt("threads")];
      int numRuns = confMonoTests.getInt("threads");
      String resultsFile = "";
      semRuns = new Semaphore(numRuns);
      // Iterate through runs
      for (String run : runs) {
        int dbId = 0;
        run = "runs." + run;
        // Iterate through dbs
        while (confMonoTests.getProperty(run + ".dbs.db(" + dbId + ").name") != null) {
          String dbName = confMonoTests.getString(run + ".dbs.db(" + dbId + ").name");
          List<String> datasources =
              confMonoTests.getList(run + ".dbs.db(" + dbId + ").datasources");
          int datasourceId = 0;
          // Iterate through datasources
          for (String datasourceName : datasources) {
            int methodId = 0;
            // Load possible normalizers
            List<String> numericalNorms =
                confMonoTests.getList(run + ".normalizers.numericalNormalizer");
            List<String> nominalNormalizers =
                confMonoTests.getList(run + ".normalizers.nominalNormalizer");
            List<String> listNormalizer =
                confMonoTests.getList(run + ".normalizers.listNormalizer");
            // Iterate through tests
            if (confMonoTests.getProperty(run + ".test.path") != null) {
              synchronized (semRuns) {
                // Waiting for a free slot;
                semRuns.acquire();

                System.gc();
                BasicDataSource trainDataSource = getDataSource(datasourceName, dbName);
                trainDataSource.configDriver(confMonoTests, run + ".dbs.db(" + dbId + ")");
                trainDataSource.configDataSource(
                    confMonoTests, run + ".dbs.db(" + dbId + ").datasources(" + datasourceId + ")");
                BasicDataSource testDataSource = getDataSource(datasourceName, dbName);
                testDataSource.configDriver(confMonoTests, run + ".dbs.db(" + dbId + ")");
                testDataSource.configDataSource(
                    confMonoTests, run + ".dbs.db(" + dbId + ").datasources(" + datasourceId + ")");

                MonotonicityTest mt = new MonotonicityTest();
                mt.configTest(confMonoTests, run + ".test");
                log.info("Testing datasource " + trainDataSource.getName());
                // Making new thread for a new test.
                new TestRun(
                        this,
                        mt,
                        trainDataSource,
                        testDataSource,
                        getNorms(nominalNormalizers),
                        getNorms(numericalNorms),
                        getNorms(listNormalizer))
                    .start();
                // Wait 1 second for avoid of the colision
                // in writing of results.
                Thread.sleep(1000);
              }
            }
            datasourceId++;
          }
          dbId++;
        }
      }

      // Waiting for all other threads to finish.
      for (int i = 0; i < numRuns; i++) semRuns.acquire();

      log.info("End of testing");

      Process p = Runtime.getRuntime().exec("cmd ", null, null);
      p.getOutputStream().write(("loadResults.bat " + resultsFile + "\n").getBytes());
      p.getOutputStream().flush();
      p.getOutputStream().write("exit\n".getBytes());
      p.getOutputStream().flush();
      BufferedReader stdOut = new BufferedReader(new InputStreamReader(p.getInputStream()));
      BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
      while (true) {
        try {
          p.exitValue();
          break;
        } catch (Exception e) {
          while (stdOut.ready() || stdErr.ready()) {
            if (stdOut.ready()) stdOut.readLine();
            else stdErr.readLine();
          }
        }
      }
      p.waitFor();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }