Esempio n. 1
0
  /**
   * Function to add the given itemset to given the value.
   *
   * @param valueIndex The index of the value.
   * @param itemset The itemset to add.
   */
  public final void add(int valueIndex, Itemset itemset) {
    int classIndex;
    double weight;

    classIndex = (int) itemset.getClassValue();
    weight = itemset.getWeight();
    perClassPerValue[valueIndex][classIndex] = perClassPerValue[valueIndex][classIndex] + weight;

    perValue[valueIndex] = perValue[valueIndex] + weight;
    perClass[classIndex] = perClass[classIndex] + weight;
    total = total + weight;
  }
Esempio n. 2
0
  /**
   * Funtion to add the given itemset to all values weighting it according to given weights.
   *
   * @param itemset The itemset to add.
   * @param weights The weights of the itemset for every value.
   */
  public final void addWeights(Itemset itemset, double[] weights) {
    int classIndex;
    int i;

    classIndex = (int) itemset.getClassValue();

    for (i = 0; i < perValue.length; i++) {
      double weight = itemset.getWeight() * weights[i];
      perClassPerValue[i][classIndex] = perClassPerValue[i][classIndex] + weight;
      perValue[i] = perValue[i] + weight;
      perClass[classIndex] = perClass[classIndex] + weight;
      total = total + weight;
    }
  }
Esempio n. 3
0
  /**
   * Function to shift all itemsets in given range from one value to another.
   *
   * @param from The minimum value.
   * @param to The maximum value.
   * @param source The dataset.
   * @param start The index of the first itemset to add.
   * @param end The index of the first itemset that will not be added.
   */
  public final void shiftRange(int from, int to, Dataset source, int start, int end) {
    int classIndex;
    double weight;
    Itemset itemset;
    int i;

    for (i = start; i < end; i++) {
      itemset = (Itemset) source.itemset(i);
      classIndex = (int) itemset.getClassValue();
      weight = itemset.getWeight();
      perClassPerValue[from][classIndex] -= weight;
      perClassPerValue[to][classIndex] += weight;
      perValue[from] -= weight;
      perValue[to] += weight;
    }
  }
Esempio n. 4
0
  /**
   * Function to add all itemsets in given range to given value.
   *
   * @param valueIndex The index of the value.
   * @param itemset The itemset to add.
   * @param start The index of the first itemset to add.
   * @param end The index of the first itemset that will not be added.
   * @throws Exception
   */
  public final void addRange(int valueIndex, Dataset source, int start, int end) {
    double sumOfWeights = 0;
    int classIndex;
    Itemset itemset;
    int i;

    for (i = start; i < end; i++) {
      itemset = (Itemset) source.itemset(i);
      classIndex = (int) itemset.getClassValue();
      sumOfWeights = sumOfWeights + itemset.getWeight();
      perClassPerValue[valueIndex][classIndex] += itemset.getWeight();
      perClass[classIndex] += itemset.getWeight();
    }

    perValue[valueIndex] += sumOfWeights;
    total += sumOfWeights;
  }
Esempio n. 5
0
  /**
   * Function to add all itemsets with unknown values for given attribute.
   *
   * @param source The dataset that contains all the itemsets.
   * @param attIndex The index of the attribute with possible unknown values.
   * @throws Exception
   */
  public final void addWithUnknownValue(Dataset source, int attIndex) {
    double[] probs;
    double weight, newWeight;
    int classIndex;
    Itemset itemset;
    int j;
    probs = new double[perValue.length];

    for (j = 0; j < perValue.length; j++) {
      // if ( Comparators.isEqual( total, 0 ) )
      if (total == 0) {
        probs[j] = 1.0 / probs.length;
      } else {
        probs[j] = perValue[j] / total;
      }
    }

    Enumeration enum2 = source.enumerateItemsets();

    while (enum2.hasMoreElements()) {
      itemset = (Itemset) enum2.nextElement();

      if (itemset.isMissing(attIndex)) {
        classIndex = (int) itemset.getClassValue();
        weight = itemset.getWeight();
        perClass[classIndex] = perClass[classIndex] + weight;
        total = total + weight;

        for (j = 0; j < perValue.length; j++) {
          newWeight = probs[j] * weight;
          perClassPerValue[j][classIndex] = perClassPerValue[j][classIndex] + newWeight;
          perValue[j] = perValue[j] + newWeight;
        }
      }
    }
  }