Ejemplo n.º 1
0
  public void generateSplit(int testPercent, String filename) {
    // Run the precycle to load the case base
    LogFactory.getLog(this.getClass()).info("Running precycle()");
    CBRCaseBase caseBase = null;
    try {
      caseBase = app.preCycle();
    } catch (ExecutionException e) {
      org.apache.commons.logging.LogFactory.getLog(this.getClass()).error(e);
    }

    if (!(caseBase instanceof jcolibri.casebase.CachedLinealCaseBase))
      LogFactory.getLog(this.getClass())
          .warn("Evaluation should be executed using a cached case base");

    ArrayList originalCases = new ArrayList(caseBase.getCases());

    ArrayList querySet = new ArrayList();
    ArrayList caseBaseSet = new ArrayList();

    // Split the case base
    splitCaseBase(originalCases, querySet, caseBaseSet, testPercent);

    save(querySet, filename);
  }
Ejemplo n.º 2
0
  public void HoldOutfromFile(String file) {
    try {
      // Obtain the time
      long t = (new Date()).getTime();
      int numberOfCycles = 0;

      // Run the precycle to load the case base
      LogFactory.getLog(this.getClass()).info("Running precycle()");
      CBRCaseBase caseBase = app.preCycle();

      if (!(caseBase instanceof jcolibri.casebase.CachedLinealCaseBase))
        LogFactory.getLog(this.getClass())
            .warn("Evaluation should be executed using a cached case base");

      ArrayList originalCases = new ArrayList(caseBase.getCases());
      ArrayList querySet = new ArrayList();
      ArrayList caseBaseSet = new ArrayList();

      // Split the case base
      splitCaseBaseFromFile(originalCases, querySet, caseBaseSet, file);

      int totalSteps = querySet.size();
      jcolibri.util.ProgressController.init(
          getClass(), "Same Split - Hold Out Evaluation", totalSteps);

      // Clear the caseBase
      caseBase.forgetCases(originalCases);

      // Set the cases that acts as case base in this repetition
      caseBase.learnCases(caseBaseSet);

      // Run cycle for each case in querySet
      for (Object o : querySet) {
        CBRCase c = (CBRCase) o;
        // Run the cycle
        LogFactory.getLog(this.getClass()).info("Running cycle() " + numberOfCycles);
        app.cycle(c);

        jcolibri.util.ProgressController.step(getClass());
        numberOfCycles++;
      }

      jcolibri.util.ProgressController.finish(getClass());

      // Revert case base to original state
      caseBase.forgetCases(originalCases);
      caseBase.learnCases(originalCases);

      // Run the poscycle to finish the application
      LogFactory.getLog(this.getClass()).info("Running postcycle()");
      app.postCycle();

      t = (new Date()).getTime() - t;

      // Obtain and complete the evaluation result
      report.setTotalTime(t);
      report.setNumberOfCycles(numberOfCycles);

    } catch (Exception e) {
      LogFactory.getLog(this.getClass()).error(e);
    }
  }