예제 #1
0
  private void generateRules(ArrayList<Itemset> Lk, int clas) {
    int i, uncover;
    Itemset itemset;
    double confidence[] = new double[2];
    double var1[] = new double[2];
    double var2[] = new double[2];

    for (i = Lk.size() - 1; i >= 0; i--) {
      itemset = Lk.get(i);
      var2 = itemset.getSupport();
      if (var2[0] > 0.0) {
        var1 = itemset.getSupportClass();
        confidence[0] = var1[0] / var2[0];
        confidence[1] = var1[1] / var2[1];
      } else {
        confidence[0] = confidence[1] = 0.0;
      }
      if (confidence[0] > 0.4) {
        this.ruleBaseClase.add(itemset);
        ruleStage1++;
      }
      if (confidence[0] > this.minconf) Lk.remove(i);
    }

    if (this.ruleBaseClase.size() > 500000) {
      this.ruleBaseClase.reduceRules(clas);
      // System.out.println("Number of rules: " + this.ruleBase.size());
      System.gc();
    }
  }
예제 #2
0
  private void generateLarge(ArrayList<Itemset> Lk, int clas) {
    int i, j, size;
    ArrayList<Itemset> Lnew;
    Itemset newItemset, itemseti, itemsetj;

    size = Lk.size();

    if (size > 1) {
      if (((Lk.get(0)).size() < this.nVariables) && ((Lk.get(0)).size() < this.depth)) {
        Lnew = new ArrayList<Itemset>();

        for (i = 0; i < size - 1; i++) {
          itemseti = Lk.get(i);
          for (j = i + 1; j < size; j++) {
            itemsetj = Lk.get(j);
            if (this.isCombinable(itemseti, itemsetj)) {
              newItemset = itemseti.clone();
              newItemset.add((itemsetj.get(itemsetj.size() - 1)).clone());
              newItemset.calculateSupports(this.dataBase, this.train);
              if (newItemset.getSupportClass()[0] >= this.minsup) Lnew.add(newItemset);
            }
          }

          this.generateRules(Lnew, clas);
          this.generateLarge(Lnew, clas);
          Lnew.clear();
          System.gc();
        }
      }
    }
  }
예제 #3
0
  /**
   * It adds a rule to the rule base
   *
   * @param itemset itemset to be added
   * @param time Time of the rule
   */
  public void add(Itemset itemset, long time) {
    int i;
    Item item;

    int[] antecedent = new int[n_variables];
    for (i = 0; i < n_variables; i++) antecedent[i] = -1; // Don't care

    for (i = 0; i < itemset.size(); i++) {
      item = itemset.get(i);
      antecedent[item.getVariable()] = item.getValue();
    }

    Rule r = new Rule(this.dataBase);
    r.asignaAntecedente(antecedent);
    r.setConsequent(itemset.getClas());
    r.setConfidence(itemset.getSupportClass() / itemset.getSupport());
    r.setSupport(itemset.getSupportClass());
    r.setTime(time);
    this.ruleBase.add(r);
  }
예제 #4
0
  private void generateL2(int clas) {
    int i, j, k, uncover;
    Item item;
    Itemset itemset;

    this.L2.clear();
    itemset = new Itemset(clas);

    for (i = 0; i < this.nVariables; i++) {
      if (this.dataBase.numLabels(i) > 1) {
        for (j = 0; j < this.dataBase.numLabels(i); j++) {
          item = new Item(i, j);
          itemset.add(item);
          itemset.calculateSupports(this.dataBase, this.train);
          if (itemset.getSupportClass()[0] >= this.minsup) this.L2.add(itemset.clone());
          itemset.remove(0);
        }
      }
    }

    this.generateRules(this.L2, clas);
  }