Esempio n. 1
0
  private double changeBucketContent(int bucketIndex, int value) {
    double simVal = simFreq.get(bucketIndex);
    double refVal = refFreq.get(bucketIndex) * scaleFactor;
    //        double oldDiff = Math.abs(simVal - refVal)/refVal;
    double oldDiff = calculateError(simVal, refVal);

    simFreq.set(bucketIndex, simFreq.get(bucketIndex) + value);

    simVal = simFreq.get(bucketIndex);
    refVal = refFreq.get(bucketIndex) * scaleFactor;
    //        double newDiff = Math.abs(simVal - refVal)/refVal;
    double newDiff = calculateError(simVal, refVal);

    return newDiff - oldDiff;
  }
Esempio n. 2
0
  private DynamicIntArray initHistogram(Set<? extends Attributable> elements, String key) {
    DynamicIntArray array = new DynamicIntArray(12, 0);

    for (Attributable element : elements) {
      String strVal = element.getAttribute(key);
      if (strVal != null) {
        double value = Double.parseDouble(strVal);
        int bucket = discretizer.index(value);
        array.set(bucket, array.get(bucket) + 1);
      }
    }

    return array;
  }
Esempio n. 3
0
  public UnivariatFrequency(
      Set<? extends Attributable> refElements,
      Set<? extends Attributable> simElements,
      String attrKey,
      Discretizer discretizer) {
    this.discretizer = discretizer;
    this.attrKey = attrKey;

    refFreq = initHistogram(refElements, attrKey);
    simFreq = initHistogram(simElements, attrKey);

    scaleFactor = simElements.size() / (double) refElements.size();
    normFactor = 1; // simElements.size();

    int size = Math.max(simFreq.size(), refFreq.size());
    for (int i = 0; i < size; i++) {
      double simVal = simFreq.get(i);
      double refVal = refFreq.get(i) * scaleFactor;

      //            hamiltonianValue += (Math.abs(simVal - refVal)/ refVal)/normFactor;
      hamiltonianValue += calculateError(simVal, refVal) / normFactor;
    }
  }
Esempio n. 4
0
  private void initReferenceValues(
      Set<? extends Person> persons, String xAttrKey, String yAttrKey) {
    referenceValues = new DynamicDoubleArray(100, Double.NaN);

    DynamicDoubleArray sums = new DynamicDoubleArray(100, Double.NaN);
    DynamicIntArray counts = new DynamicIntArray(100, -1);

    calculateBuckets(persons, sums, counts, xAttrKey, yAttrKey);

    for (int i = 0; i < sums.size(); i++) {
      double sum = sums.get(i);
      int cnt = counts.get(i);
      if (!Double.isNaN(sum) && cnt > 0) {
        referenceValues.set(i, sum / (double) cnt);
      }
    }
  }
Esempio n. 5
0
  private double calculateDiff(int bucketIndex) {
    double refValue = referenceValues.get(bucketIndex);
    if (Double.isNaN(refValue)) {
      // There is no reference value for this bucket. We cannot do any comparison.
      return 0.0;
    } else {
      double sum = bucketSums.get(bucketIndex);
      int cnt = bucketCounts.get(bucketIndex);

      if (!Double.isNaN(sum) && cnt > 0) {
        double simValue = sum / (double) cnt;

        return Math.abs(refValue - simValue);
      } else {
        return 0.0;
      }
    }
  }
Esempio n. 6
0
  private double changeBucketContent(int bucketIndex, double value, boolean add) {
    double oldDiff = calculateDiff(bucketIndex);

    double sum = bucketSums.get(bucketIndex);
    int count = bucketCounts.get(bucketIndex);

    if (add) {
      bucketSums.set(bucketIndex, sum + value);
      bucketCounts.set(bucketIndex, count + 1);
    } else {
      bucketSums.set(bucketIndex, sum - value);
      bucketCounts.set(bucketIndex, count - 1);
    }

    double newDiff = calculateDiff(bucketIndex);

    return newDiff - oldDiff;
  }