Ejemplo n.º 1
0
  private void calculateBuckets(
      Set<? extends Person> persons,
      DynamicDoubleArray sums,
      DynamicIntArray counts,
      String xAttrKey,
      String yAttrKey) {
    TIntDoubleHashMap sumBuckets = new TIntDoubleHashMap();
    TIntIntHashMap countBuckets = new TIntIntHashMap();

    for (Person person : persons) {
      String xValStr = person.getAttribute(xAttrKey);
      String yValStr = person.getAttribute(yAttrKey);

      if (xValStr != null && yValStr != null) {
        double xVal = Double.parseDouble(xValStr);
        double yVal = Double.parseDouble(yValStr);

        int bucketIdx = xDataDiscr.index(xVal);

        sumBuckets.adjustOrPutValue(bucketIdx, yVal, yVal);
        countBuckets.adjustOrPutValue(bucketIdx, 1, 1);
      }
    }

    TIntDoubleIterator it = sumBuckets.iterator();
    for (int i = 0; i < sumBuckets.size(); i++) {
      it.advance();
      int bucketIndex = it.key();
      double sum = it.value();
      int cnt = countBuckets.get(bucketIndex);

      sums.set(bucketIndex, sum);
      counts.set(bucketIndex, cnt);
    }
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
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;
  }
Ejemplo n.º 4
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;
  }