Esempio n. 1
0
  /**
   * It prints the whole rulebase
   *
   * @return The whole rulebase
   */
  public String printString() {
    int i, j, ant;
    String[] names = train.names();
    String[] clases = train.clases();
    String cadena = new String("");

    ant = 0;

    for (i = 0; i < this.ruleBase.size(); i++) {
      Rule r = this.ruleBase.get(i);
      cadena += (i + 1) + ": ";
      for (j = 0; j < n_variables && r.antecedente[j] < 0; j++) ;
      if (j < n_variables && r.antecedente[j] >= 0) {
        cadena += names[j] + " IS " + r.dataBase.print(j, r.antecedente[j]);
        ant++;
      }
      for (j++; j < n_variables - 1; j++) {
        if (r.antecedente[j] >= 0) {
          cadena += " AND " + names[j] + " IS " + r.dataBase.print(j, r.antecedente[j]);
          ant++;
        }
      }
      if (j < n_variables && r.antecedente[j] >= 0) {
        cadena +=
            " AND "
                + names[j]
                + " IS "
                + r.dataBase.print(j, r.antecedente[j])
                + ": "
                + clases[r.clase]
                + "\n";
        ant++;
      } else cadena += ": " + clases[r.clase] + "\n";
    }

    cadena += (i + 1) + ": Default IS " + clases[0] + "\n"; // Default class

    cadena += "\n\n";
    cadena += "@Dsupp and Dconf:\n\n";
    for (i = 0; i < this.ruleBase.size(); i++) {
      Rule rule = this.ruleBase.get(i);
      cadena += (i + 1) + ": ";
      cadena += "Dsupp: " + rule.getSupport() + " AND Dconf: " + rule.getConfidence() + "\n";
    }

    cadena =
        "@Number of rules: "
            + (this.ruleBase.size() + 1)
            + " Number of Antecedents by rule: "
            + ant * 1.0 / (this.ruleBase.size() + 1.0)
            + "\n\n"
            + cadena;

    return (cadena);
  }