コード例 #1
0
  private XLog[] createdXFolds() {

    if (log.size() < fold) fold = log.size();
    XLog[] logs = new XLog[fold];

    for (int i = 0; i < fold; i++) {
      logs[i] = factory.createLog(log.getAttributes());
    }

    if (log.size() == fold) {
      int pos = 0;
      for (XTrace t : log) {
        logs[pos].add(t);
        pos++;
      }
    } else {
      boolean finish = false;
      while (!finish) {
        finish = true;
        for (XTrace t : log) {
          int pos = r.nextInt(fold);
          logs[pos].add(t);
        }
        for (int i = 0; i < logs.length; i++) {
          if (logs[i].size() == 0) {
            finish = false;
          }
        }
        if (!finish) {
          for (int i = 0; i < fold; i++) {
            logs[i].clear();
          }
        }
      }
    }

    return logs;
  }
コード例 #2
0
  @Override
  public Measure computeMeasurement(
      UIPluginContext pluginContext,
      XEventClassifier xEventClassifier,
      PetrinetWithMarking petrinetWithMarking,
      MiningAlgorithm miningAlgorithm,
      XLog log) {
    Measure measure = new Measure();
    double fitness = 0.0;
    this.log = log;
    XLog[] logs = createdXFolds();

    AlignmentBasedFitness alignmentBasedFitness = new AlignmentBasedFitness();

    for (int i = 0; i < fold; i++) {
      XLog log1 = factory.createLog(log.getAttributes());
      for (int j = 0; j < fold; j++) {
        if (j != i) {
          log1.addAll(logs[j]);
        }
      }

      try {
        petrinetWithMarking = miningAlgorithm.minePetrinet(pluginContext, log1, false);
        Double f =
            alignmentBasedFitness
                .computeMeasurement(
                    pluginContext, xEventClassifier, petrinetWithMarking, miningAlgorithm, logs[i])
                .getValue();
        fitness += (f != null) ? f : 0.0;
      } catch (Exception e) {
        return measure;
      }
    }

    measure.setValue(fitness / (double) fold);
    return measure;
  }