Package com.google.common.util.concurrent

Examples of com.google.common.util.concurrent.AtomicDouble


    );

    final ImmutableList.Builder<Bucket> builder = ImmutableList.builder();
    final PeekingIterator<Long> iterator = Iterators.peekingIterator(bucketUpperBounds.iterator());

    final AtomicDouble sum = new AtomicDouble();
    final AtomicDouble lastSum = new AtomicDouble();

    // for computing weighed average of values in bucket
    final AtomicDouble bucketWeightedSum = new AtomicDouble();

    final double normalizationFactor = weight(TimeUnit.MILLISECONDS.toSeconds(clock.getMillis()));

    postOrderTraversal(root, new Callback() {
      public boolean process(Node node) {

        while (iterator.hasNext() && iterator.peek() <= node.getUpperBound()) {
          double bucketCount = sum.get() - lastSum.get();

          Bucket bucket = new Bucket(
              bucketCount / normalizationFactor, bucketWeightedSum.get() / bucketCount);

          builder.add(bucket);
          lastSum.set(sum.get());
          bucketWeightedSum.set(0);
          iterator.next();
        }

        bucketWeightedSum.addAndGet(node.getMiddle() * node.weightedCount);
        sum.addAndGet(node.weightedCount);
        return iterator.hasNext();
      }
    });

    while (iterator.hasNext()) {
      double bucketCount = sum.get() - lastSum.get();
      Bucket bucket = new Bucket(
          bucketCount / normalizationFactor, bucketWeightedSum.get() / bucketCount);

      builder.add(bucket);

      iterator.next();
    }
View Full Code Here


    return Math.max(leftMaxWeight, rightMaxWeight) + node.weightedCount;
  }

  @VisibleForTesting
  synchronized void validate() {
    final AtomicDouble sumOfWeights = new AtomicDouble();
    final AtomicInteger actualNodeCount = new AtomicInteger();
    final AtomicInteger actualNonZeroNodeCount = new AtomicInteger();

    if (root != null) {
      validateStructure(root);

      postOrderTraversal(root, new Callback() {
        @Override
        public boolean process(Node node) {
          sumOfWeights.addAndGet(node.weightedCount);
          actualNodeCount.incrementAndGet();

          if (node.weightedCount > ZERO_WEIGHT_THRESHOLD) {
            actualNonZeroNodeCount.incrementAndGet();
          }

          return true;
        }
      });
    }

    checkState(Math.abs(sumOfWeights.get() - weightedCount) < ZERO_WEIGHT_THRESHOLD,
               "Computed weight (%s) doesn't match summary (%s)", sumOfWeights.get(),
               weightedCount);

    checkState(actualNodeCount.get() == totalNodeCount,
      "Actual node count (%s) doesn't match summary (%s)",
      actualNodeCount.get(), totalNodeCount);
View Full Code Here

    public Serializable getClassificationByMaxProb(AttributesMap attributes) {
        Map<Serializable, AtomicDouble> probTotals = Maps.newHashMap();
        for (Tree tree : trees) {
            Leaf leaf =tree.node.getLeaf(attributes);
            for (Serializable classification : leaf.getClassifications()) {
                AtomicDouble ttlProb = probTotals.get(classification);
                if (ttlProb == null) {
                    ttlProb = new AtomicDouble(0);
                    probTotals.put(classification, ttlProb);
                }
                ttlProb.addAndGet(leaf.getProbability(classification));
            }
        }
        Serializable bestClassification = null;
        double bestClassificationTtlProb = 0;
        for (Map.Entry<Serializable, AtomicDouble> classificationProb : probTotals.entrySet()) {
View Full Code Here

TOP

Related Classes of com.google.common.util.concurrent.AtomicDouble

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.