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

The following examples show how to use com.google.common.util.concurrent.AtomicDouble. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MaximumLikelihoodFading.java    From toolbox with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void runLearning() {

    efBayesianNetwork = new EF_BayesianNetwork(dag);

    dataInstanceCount = new AtomicDouble(0);
    sumSS = efBayesianNetwork.createZeroSufficientStatistics();
    for (DataOnMemory<DataInstance> batch : dataStream.iterableOverBatches(windowsSize)){
        SufficientStatistics batchSS = batch.stream()
                .map(efBayesianNetwork::getSufficientStatistics)
                .reduce(SufficientStatistics::sumVectorNonStateless).get();

        sumSS.multiplyBy(fadingFactor);
        sumSS.sum(batchSS);

        dataInstanceCount.set(dataInstanceCount.get()*fadingFactor + windowsSize);
    }
}
 
Example #2
Source File: Contextualizer.java    From termsuite-core with Apache License 2.0 6 votes vote down vote up
public CrossTable computeCrossTable() {
		
		int totalCoOccurrences = 0;
	    Map<Term, AtomicDouble> aPlusB = Maps.newConcurrentMap() ;
	    Map<Term, AtomicDouble> aPlusC = Maps.newConcurrentMap();

        Term term;
        for (Iterator<TermService> it1 = terminology.getTerms().iterator(); 
        		it1.hasNext() ;) {
            term = it1.next().getTerm();
//            this.totalFrequency++;
            if(term.getContext() == null)
            	continue;
        	ContextVector context = term.getContext();
            for (ContextVector.Entry entry : context.getEntries()) {
            	totalCoOccurrences += entry.getNbCooccs();
                getScoreFromMap(aPlusB, term).addAndGet(entry.getNbCooccs());
                getScoreFromMap(aPlusC, entry.getCoTerm()).addAndGet(entry.getNbCooccs());
            }
        }
        
        return new CrossTable(aPlusB, aPlusC, totalCoOccurrences);
    }
 
Example #3
Source File: ParallelMLMissingData.java    From toolbox with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public double updateModel(DataStream<DynamicDataInstance> dataStream) {

    Stream<DataOnMemory<DynamicDataInstance>> stream = null;
    if (parallelMode){
        stream = dataStream.parallelStreamOfBatches(windowsSize);
    }else{
        stream = dataStream.streamOfBatches(windowsSize);
    }


    dataInstanceCount = new AtomicDouble(0); //Initial count

    this.sumSS = stream
            .peek(batch -> {
                dataInstanceCount.getAndAdd(batch.getNumberOfDataInstances());
                if (debug) System.out.println("Parallel ML procesando "+(int)dataInstanceCount.get() +" instances");
            })
            .map(batch -> {
                return batch.stream()
                        .map(dataInstance -> computeCountSufficientStatistics(this.efBayesianNetwork, dataInstance))
                        .reduce(DynamicPartialSufficientSatistics::sumNonStateless).get();
            })
            .reduce(DynamicPartialSufficientSatistics::sumNonStateless).get();

    if (laplace) {
        DynamicPartialSufficientSatistics initSS = DynamicPartialSufficientSatistics.createInitPartialSufficientStatistics(efBayesianNetwork);
        sumSS.sum(initSS);
    }

    return Double.NaN;
}
 
Example #4
Source File: MainMenuGuiService.java    From ForgeHax with MIT License 5 votes vote down vote up
private void drawHistory() {
  AtomicDouble offset = new AtomicDouble();
  messageHistory
      .stream()
      .limit(100)
      .forEach(
          str -> {
            MC.fontRenderer.drawString(
                str, 5, (this.height - 50 - offset.intValue()), Colors.WHITE.toBuffer());
            offset.addAndGet(10);
          });
}
 
Example #5
Source File: Walking.java    From PokeMate with GNU General Public License v3.0 5 votes vote down vote up
public static void walk( final Context context, S2LatLng end) { // PokeStop Walking
    context.getWalking().set(true);
    S2LatLng start = S2LatLng.fromDegrees(context.getLat().get(), context.getLng().get());
    S2LatLng diff = end.sub(start);
    double distance = start.getEarthDistance(end);
    long timeout = 200L;
    double timeRequired = distance / Config.getSpeed();
    final AtomicDouble stepsRequired = new AtomicDouble(timeRequired / (timeout / 1000D));
    double deltaLat = diff.latDegrees() / stepsRequired.get();
    double deltaLng = diff.lngDegrees() / stepsRequired.get();
    logger.debug("starting to walk");
    //Schedule a timer to walk every 200 ms


    new Timer().scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            context.getApi().setLocation(context.getLat().addAndGet(deltaLat), context.getLng().addAndGet(deltaLng), new Random().nextInt(10));
            stepsRequired.getAndAdd(-1);
            if (stepsRequired.get() <= 0) {
                logger.debug("Setting a new destination");
                context.getWalking().set(false);
                context.addTask(new TagPokestop(context));
                context.addTask(new Navigate(context, new LatLng(context.getLat().get() - VARIANCE, context.getLng().get() - VARIANCE),
                    new LatLng(context.getLat().get() + VARIANCE, context.getLng().get() + VARIANCE)));
                cancel();
            }
        }
    }, 0, timeout);
}
 
Example #6
Source File: SumService.java    From disthene with MIT License 5 votes vote down vote up
private void flush() {
    Collection<Metric> metricsToFlush = new ArrayList<>();

    while(accumulator.size() > 0 && (accumulator.firstKey() < DateTime.now(DateTimeZone.UTC).getMillis() / 1000 - distheneConfiguration.getCarbon().getAggregatorDelay())) {
        ConcurrentMap<MetricKey, AtomicDouble> timestampMap = accumulator.pollFirstEntry().getValue();

        for(Map.Entry<MetricKey, AtomicDouble> entry : timestampMap.entrySet()) {
            metricsToFlush.add(new Metric(entry.getKey(), entry.getValue().get()));
        }
    }

    if (metricsToFlush.size() > 0) {
        doFlush(metricsToFlush, getFlushRateLimiter(metricsToFlush.size()));
    }
}
 
Example #7
Source File: DocumentProjectionService.java    From termsuite-core with Apache License 2.0 5 votes vote down vote up
public double getProjectionScore(TerminologyService referenceTerminology) {
	AtomicDouble sum = new AtomicDouble(0);
	AtomicDouble total = new AtomicDouble(0);
	List<Term> top100 = topN(100).collect(toList());
	for(Term docTerm :top100) {
		total.addAndGet(docTerm.getSpecificity());
		int baseRank = getBaseRankInRefTermino(referenceTerminology, docTerm);
		if(baseRank > 0 && baseRank < 500)
			sum.addAndGet(docTerm.getSpecificity());
	}
	return sum.doubleValue() / total.doubleValue();
}
 
Example #8
Source File: AreaBarChart.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public AreaBarChart(@Nonnull ModularFeatureListRow row, AtomicDouble progress) {
  XYChart.Series data = new XYChart.Series();
  int i = 1;
  int size = row.getFeatures().size();
  for (Entry<RawDataFile, ModularFeature> entry : row.getFeatures().entrySet()) {
    Property<Float> areaProperty = entry.getValue().get(AreaType.class);
    data.getData().add(
        new XYChart.Data("" + i, areaProperty.getValue() == null ? 0f : areaProperty.getValue()));
    i++;
    if (progress != null)
      progress.addAndGet(1.0 / size);
  }

  final CategoryAxis xAxis = new CategoryAxis();
  final NumberAxis yAxis = new NumberAxis();
  final BarChart<String, Number> bc = new BarChart<String, Number>(xAxis, yAxis);
  bc.setLegendVisible(false);
  bc.setMinHeight(100);
  bc.setPrefHeight(100);
  bc.setMaxHeight(100);
  bc.setBarGap(3);
  bc.setCategoryGap(3);
  bc.setPrefWidth(150);

  bc.getData().addAll(data);
  this.getChildren().add(bc);
}
 
Example #9
Source File: AreaShareChart.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public AreaShareChart(@Nonnull ModularFeatureListRow row, AtomicDouble progress) {
  Float sum = row.streamFeatures().map(ModularFeature::getArea).filter(p -> p.getValue() != null)
      .map(Property<Float>::getValue).reduce(0f, Float::sum);

  List<Rectangle> all = new ArrayList<>();
  int i = 0;
  int size = row.getFeatures().size();
  for (Entry<RawDataFile, ModularFeature> entry : row.getFeatures().entrySet()) {
    Property<Float> areaProperty = entry.getValue().get(AreaType.class);
    if (areaProperty.getValue() != null) {
      // color from sample
      Color color = entry.getValue().get(RawColorType.class).getValue();
      if (color == null)
        color = Color.DARKORANGE;

      float ratio = areaProperty.getValue() / sum;
      Rectangle rect = new Rectangle();
      rect.setFill(color);
      // bind width
      rect.widthProperty().bind(this.widthProperty().multiply(ratio));
      rect.setHeight(i % 2 == 0 ? 20 : 25);
      all.add(rect);
      i++;
      if (progress != null)
        progress.addAndGet(1.0 / size);
    }
  }
  HBox box = new HBox(0, all.toArray(Rectangle[]::new));
  box.setPrefWidth(100);
  box.setAlignment(Pos.CENTER_LEFT);

  this.getChildren().add(box);
}
 
Example #10
Source File: UserMetricsTask.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param registry              the metrics registry
 * @param dataServices          The {@link DataServices} instance to use
 * @param userMetricsProperties the properties that configure this task
 */
public UserMetricsTask(
    final MeterRegistry registry,
    final DataServices dataServices,
    final UserMetricsProperties userMetricsProperties
) {
    this.registry = registry;
    this.persistenceService = dataServices.getPersistenceService();
    this.userMetricsProperties = userMetricsProperties;
    this.activeUsersCount = new AtomicDouble(Double.NaN);

    // Register gauge for count of distinct users with active jobs.
    Gauge.builder(USER_ACTIVE_USERS_METRIC_NAME, this::getUsersCount)
        .register(registry);
}
 
Example #11
Source File: ClutchAutoScaler.java    From mantis with Apache License 2.0 5 votes vote down vote up
public ClutchController(StageScalingPolicy.ScalingReason metric, StageSchedulingInfo stageSchedulingInfo, ClutchPIDConfig config, AtomicDouble gainFactor, long initialSize, long min, long max) {
    this.metric = metric;
    this.config = config;
    this.gainFactor = gainFactor;
    this.initialSize = initialSize;
    this.stageSchedulingInfo = stageSchedulingInfo;
    this.min = min;
    this.max = max;

    this.integrator = new Integrator(this.initialSize, this.min - 1, this.max + 1);
}
 
Example #12
Source File: Object2Expr.java    From symja_android_library with GNU General Public License v3.0 5 votes vote down vote up
private static IExpr convert(Number n) {
	if (n instanceof Integer) {
		return F.ZZ(((Integer) n).longValue());
	}
	if (n instanceof Double) {
		return F.num(((Double) n).doubleValue());
	}
	if (n instanceof Long) {
		return F.ZZ(((Long) n).longValue());
	}
	if (n instanceof BigInteger) {
		return F.integer((BigInteger) n);
	}
	if (n instanceof BigDecimal) {
		return F.num(new Apfloat(((BigDecimal) n).doubleValue()));
	}
	if (n instanceof Float) {
		return F.num(((Float) n).doubleValue());
	}
	if (n instanceof AtomicDouble) {
		return F.num(((AtomicDouble) n).doubleValue());
	}
	if (n instanceof AtomicInteger) {
		return F.ZZ(((AtomicInteger) n).longValue());
	}
	if (n instanceof AtomicLong) {
		return F.ZZ(((AtomicLong) n).longValue());
	}
	return F.num(((Number) n).doubleValue());
}
 
Example #13
Source File: PrimitiveByteCastExtensions.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Convert the given value to {@code AtomicDouble}.
 *
 * @param number a number of {@code byte} type.
 * @return the equivalent value to {@code number} of {@code AtomicDouble} type.
 */
@Pure
@Inline(value = "new $2($1)", imported = AtomicDouble.class)
public static AtomicDouble toAtomicDouble(byte number) {
	return new AtomicDouble(number);
}
 
Example #14
Source File: CodeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void toAtomicDouble_long() {
	AtomicDouble value = toAtomicDouble(left);
	assertNotNull(value);
	assertEpsilonEquals(4., value.doubleValue());
}
 
Example #15
Source File: CodeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void operator_greaterEqualsThan_Byte_Number() {
	assertTrue(operator_greaterEqualsThan(left, new AtomicDouble(right)));
	assertFalse(operator_greaterEqualsThan(left2, new AtomicDouble(right)));
	assertTrue(operator_greaterEqualsThan(left, new AtomicDouble(left)));
}
 
Example #16
Source File: MicroMeterMetricCollector.java    From secor with Apache License 2.0 4 votes vote down vote up
@Override
public void gauge(String label, double value, String topic) {
    Metrics.gauge(label, Collections.singletonList(
        Tag.of("topic", topic)), new AtomicDouble(0)).set(value);
}
 
Example #17
Source File: PrimitiveShortCastExtensions.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Convert the given value to {@code AtomicDouble}.
 *
 * @param number a number of {@code short} type.
 * @return the equivalent value to {@code number} of {@code AtomicDouble} type.
 */
@Pure
@Inline(value = "new $2($1)", imported = AtomicDouble.class)
public static AtomicDouble toAtomicDouble(short number) {
	return new AtomicDouble(number);
}
 
Example #18
Source File: CodeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void operator_lessThan_Byte_Number() {
	assertFalse(operator_lessThan(left, new AtomicDouble(right)));
	assertTrue(operator_lessThan(left2, new AtomicDouble(right)));
	assertFalse(operator_lessThan(left, new AtomicDouble(left)));
}
 
Example #19
Source File: CodeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void operator_lessThan_Byte_Number() {
	assertFalse(operator_lessThan(left, new AtomicDouble(right)));
	assertTrue(operator_lessThan(left2, new AtomicDouble(right)));
	assertFalse(operator_lessThan(left, new AtomicDouble(left)));
}
 
Example #20
Source File: CodeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void toAtomicDouble_short() {
	AtomicDouble value = toAtomicDouble(left);
	assertNotNull(value);
	assertEpsilonEquals(4., value.doubleValue());
}
 
Example #21
Source File: CodeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void operator_greaterThan_short_Number() {
	assertTrue(operator_greaterThan(left, new AtomicDouble(right)));
	assertFalse(operator_greaterThan(left2, new AtomicDouble(right)));
	assertFalse(operator_greaterThan(left, new AtomicDouble(left)));
}
 
Example #22
Source File: BigDecimalCastExtensions.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Convert the given value to {@code AtomicDouble}. This function is not null-safe.
 *
 * @param number a number of {@code BigDecimal} type.
 * @return the equivalent value to {@code number} of {@code AtomicDouble} type.
 */
@Pure
@Inline(value = "new $2($1.doubleValue())", imported = AtomicDouble.class)
public static AtomicDouble toAtomicDouble(BigDecimal number) {
	return new AtomicDouble(number.doubleValue());
}
 
Example #23
Source File: CountingMetric.java    From Eagle with Apache License 2.0 4 votes vote down vote up
public CountingMetric(long timestamp, Map<String, String> dimensions, String metricName, AtomicDouble value) {
	super(timestamp, dimensions, metricName, value);
}
 
Example #24
Source File: CodeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void operator_greaterThan_Byte_Number() {
	assertTrue(operator_greaterThan(left, new AtomicDouble(right)));
	assertFalse(operator_greaterThan(left2, new AtomicDouble(right)));
	assertFalse(operator_greaterThan(left, new AtomicDouble(left)));
}
 
Example #25
Source File: CodeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void operator_equals_Byte_Number() {
	assertFalse(operator_equals(left, new AtomicDouble(right)));
	assertFalse(operator_equals(left2, new AtomicDouble(right)));
	assertTrue(operator_equals(left, new AtomicDouble(left)));
}
 
Example #26
Source File: CodeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void operator_greaterEqualsThan_short_Number() {
	assertTrue(operator_greaterEqualsThan(left, new AtomicDouble(right)));
	assertFalse(operator_greaterEqualsThan(left2, new AtomicDouble(right)));
	assertTrue(operator_greaterEqualsThan(left, new AtomicDouble(left)));
}
 
Example #27
Source File: CrossTable.java    From termsuite-core with Apache License 2.0 4 votes vote down vote up
public Map<Term, AtomicDouble> getAPlusC() {
	return aPlusC;
}
 
Example #28
Source File: CodeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void operator_equals_Byte_Number() {
	assertFalse(operator_equals(left, new AtomicDouble(right)));
	assertFalse(operator_equals(left2, new AtomicDouble(right)));
	assertTrue(operator_equals(left, new AtomicDouble(left)));
}
 
Example #29
Source File: CodeTest.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Test
public void operator_lessThan_Byte_Number() {
	assertFalse(operator_lessThan(left, new AtomicDouble(right)));
	assertTrue(operator_lessThan(left2, new AtomicDouble(right)));
	assertFalse(operator_lessThan(left, new AtomicDouble(left.doubleValue())));
}
 
Example #30
Source File: EagleMetric.java    From eagle with Apache License 2.0 4 votes vote down vote up
public EagleMetric(long latestUserTimeClock, String name, double value, long granularity) {
    this.latestUserTimeClock = latestUserTimeClock;
    this.name = name;
    this.value = new AtomicDouble(value);
    this.granularity = granularity;
}