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 Project: termsuite-core   Author: termsuite   File: Contextualizer.java    License: 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 #2
Source Project: toolbox   Author: amidst   File: MaximumLikelihoodFading.java    License: 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 #3
Source Project: mantis   Author: Netflix   File: ClutchAutoScaler.java    License: 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 #4
Source Project: mzmine3   Author: mzmine   File: AreaShareChart.java    License: 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 #5
Source Project: mzmine3   Author: mzmine   File: AreaBarChart.java    License: 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 #6
Source Project: ForgeHax   Author: fr1kin   File: MainMenuGuiService.java    License: 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 #7
Source Project: PokeMate   Author: SwipeX   File: Walking.java    License: 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 #8
Source Project: symja_android_library   Author: axkr   File: Object2Expr.java    License: 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 #9
Source Project: termsuite-core   Author: termsuite   File: DocumentProjectionService.java    License: 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 #10
Source Project: disthene   Author: EinsamHauer   File: SumService.java    License: 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 #11
Source Project: genie   Author: Netflix   File: UserMetricsTask.java    License: 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 #12
Source Project: toolbox   Author: amidst   File: ParallelMLMissingData.java    License: 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 #13
Source Project: sarl   Author: sarl   File: CodeTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void operator_equals_short_Number() {
	assertFalse(operator_equals(left, new AtomicDouble(right)));
	assertFalse(operator_equals(left2, new AtomicDouble(right)));
	assertTrue(operator_equals(left, new AtomicDouble(left)));
}
 
Example #14
Source Project: sarl   Author: sarl   File: CodeTest.java    License: 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 #15
Source Project: secor   Author: pinterest   File: MicroMeterMetricCollector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void metric(String label, double value, String topic) {
    Metrics.gauge(label, Collections.singletonList(
        Tag.of("topic", topic)), new AtomicDouble(0)).set(value);
}
 
Example #16
Source Project: mantis   Author: Netflix   File: PIDController.java    License: Apache License 2.0 4 votes vote down vote up
public static PIDController of(Double kp, Double ki, Double kd, Double deltaT, AtomicDouble dampener) {
    return new PIDController(kp, ki, kd, deltaT, dampener);
}
 
Example #17
Source Project: sarl   Author: sarl   File: CodeTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void operator_notEquals_Byte_Number() {
	assertTrue(operator_notEquals(left, new AtomicDouble(right)));
	assertTrue(operator_notEquals(left2, new AtomicDouble(right)));
	assertFalse(operator_notEquals(left, new AtomicDouble(left)));
}
 
Example #18
Source Project: sarl   Author: sarl   File: CodeTest.java    License: 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 #19
Source Project: sarl   Author: sarl   File: CodeTest.java    License: 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 #20
Source Project: pepper-metrics   Author: zrbcool   File: HealthStatsDefault.java    License: Apache License 2.0 4 votes vote down vote up
public Map<String, AtomicDouble> getGaugeCollector() {
    return gaugeCollector;
}
 
Example #21
Source Project: sarl   Author: sarl   File: CodeTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void operator_lessEqualsThan_Byte_Number() {
	assertFalse(operator_lessEqualsThan(left, new AtomicDouble(right)));
	assertTrue(operator_lessEqualsThan(left2, new AtomicDouble(right)));
	assertTrue(operator_lessEqualsThan(left, new AtomicDouble(left)));
}
 
Example #22
Source Project: pepper-metrics   Author: zrbcool   File: AbstractHealthPrinter.java    License: Apache License 2.0 4 votes vote down vote up
protected String buildGaugeLog(String key, Map<String, AtomicDouble> gaugeCollector) {
    return key + " = " + gaugeCollector.get(key);
}
 
Example #23
Source Project: sarl   Author: sarl   File: CodeTest.java    License: 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 #24
Source Project: sarl   Author: sarl   File: CodeTest.java    License: 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 #25
Source Project: sarl   Author: sarl   File: CodeTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void operator_notEquals_short_Number() {
	assertTrue(operator_notEquals(left, new AtomicDouble(right)));
	assertTrue(operator_notEquals(left2, new AtomicDouble(right)));
	assertFalse(operator_notEquals(left, new AtomicDouble(left)));
}
 
Example #26
Source Project: sarl   Author: sarl   File: CodeTest.java    License: 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 #27
Source Project: localization_nifi   Author: wangrenlei   File: DataDogReportingTask.java    License: Apache License 2.0 4 votes vote down vote up
protected ConcurrentHashMap<String, AtomicDouble> getMetricsMap() {
    return new ConcurrentHashMap<>();
}
 
Example #28
Source Project: localization_nifi   Author: wangrenlei   File: TestDataDogReportingTask.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected ConcurrentHashMap<String, AtomicDouble> getMetricsMap() {
    return metricsMap;
}
 
Example #29
Source Project: sarl   Author: sarl   File: CodeTest.java    License: 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 #30
Source Project: sarl   Author: sarl   File: CodeTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void operator_lessEqualsThan_short_Number() {
	assertFalse(operator_lessEqualsThan(left, new AtomicDouble(right)));
	assertTrue(operator_lessEqualsThan(left2, new AtomicDouble(right)));
	assertTrue(operator_lessEqualsThan(left, new AtomicDouble(left)));
}