예제 #1
0
파일: Rule.java 프로젝트: triguero/Keel3.0
  /**
   * Constructor with parameters. It creates a specific rule from a given sample
   *
   * @param database Data Base associated to the general rule base that includes this rule
   * @param n_classes Number of classes in the training set
   * @param tnorm T-norm used to compute the compatibility degree
   * @param tconorm T-conorm used to compute the compatibility degree
   * @param rule_weight Way of computing the rule weight
   * @param sample Data sample used to generate this rule
   * @param sample_class Output class associated to the data sample used to generate this rule
   */
  public Rule(
      DataBase database,
      int n_classes,
      int tnorm,
      int tconorm,
      int rule_weight,
      double[] sample,
      int sample_class) {
    antecedent = new ArrayList<FuzzyAntecedent>(database.numVariables());
    clas = sample_class;
    t_norm = tnorm;
    t_conorm = tconorm;
    ruleWeight = rule_weight;
    level = 2;
    n_e = true;

    for (int i = 0; i < database.numVariables(); i++) {
      double max = 0.0;
      int etq = -1;
      double per;
      for (int j = 0; j < database.numLabels(); j++) {
        per = database.membershipFunction(i, j, sample[i]);
        if (per > max) {
          max = per;
          etq = j;
        }
      }
      if (max == 0.0) {
        System.err.println("There was an error while searching for the antecedent of the rule");
        System.err.println("Example: ");
        for (int j = 0; j < database.numVariables(); j++) {
          System.err.print(sample[j] + "\t");
        }
        System.err.println("Variable " + i);
        System.exit(1);
      }

      FuzzyAntecedent new_antecedent =
          new FuzzyAntecedent(database.clone(i, etq), i, database.numLabels());
      antecedent.add((FuzzyAntecedent) new_antecedent);
    }
  }