Exemple #1
0
  private void onXValueChange(double oldValue, double newValue, CachedPerson person) {
    Double yVal = (Double) person.getData(yDataKey);
    int oldBucketIndex = xDataDiscr.index(oldValue);
    double hValue1 = changeBucketContent(oldBucketIndex, yVal, false);

    int newBucketIndex = xDataDiscr.index(newValue);
    double hValue2 = changeBucketContent(newBucketIndex, yVal, true);

    hamiltonianValue += (hValue1 + hValue2);
  }
  @Override
  public void onChange(Object dataKey, Object oldValue, Object newValue, CachedElement person) {
    if (this.dataKey == null) this.dataKey = Converters.getObjectKey(attrKey);

    if (this.dataKey.equals(dataKey)) {
      int bucket = discretizer.index((Double) oldValue);
      double diff1 = changeBucketContent(bucket, -1);

      bucket = discretizer.index((Double) newValue);
      double diff2 = changeBucketContent(bucket, 1);

      hamiltonianValue += (diff1 + diff2) / normFactor;
    }
  }
Exemple #3
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);
    }
  }
Exemple #4
0
  private void onYValueChange(double oldValue, double newValue, CachedPerson person) {
    Double xVal = (Double) person.getData(xDataKey);
    int bucketIndex = xDataDiscr.index(xVal);

    double oldDiff = calculateDiff(bucketIndex);

    double delta = newValue - oldValue;
    double sum = bucketSums.get(bucketIndex);
    bucketSums.set(bucketIndex, sum + delta);

    double newDiff = calculateDiff(bucketIndex);

    hamiltonianValue += newDiff - oldDiff;
  }
  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;
  }