Java Code Examples for com.google.common.util.concurrent.AtomicDouble#set()

The following examples show how to use com.google.common.util.concurrent.AtomicDouble#set() . 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: FeatureShapeChart.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public FeatureShapeChart(@Nonnull ModularFeatureListRow row, AtomicDouble progress) {
  try {
    final NumberAxis xAxis = new NumberAxis();
    final NumberAxis yAxis = new NumberAxis();
    final LineChart<Number, Number> bc = new LineChart<>(xAxis, yAxis);

    DataPoint max = null;
    double maxRT = 0;
    int size = row.getFeatures().size();
    int fi = 0;
    for (ModularFeature f : row.getFeatures().values()) {
      XYChart.Series<Number, Number> data = new XYChart.Series<>();
      List<Integer> scans = f.getScanNumbers();
      List<DataPoint> dps = f.getDataPoints();
      RawDataFile raw = f.getRawDataFile();
      // add data points retention time -> intensity
      for (int i = 0; i < scans.size(); i++) {
        DataPoint dp = dps.get(i);
        double retentionTime = raw.getScan(scans.get(i)).getRetentionTime();
        double intensity = dp == null ? 0 : dp.getIntensity();
        data.getData().add(new XYChart.Data<>(retentionTime, intensity));
        if (dp != null && (max == null || max.getIntensity() < dp.getIntensity())) {
          max = dp;
          maxRT = retentionTime;
        }
        if (progress != null)
          progress.addAndGet(1.0 / size / scans.size());
      }
      fi++;
      bc.getData().add(data);
      if (progress != null)
        progress.set((double) fi / size);
    }

    bc.setLegendVisible(false);
    bc.setMinHeight(100);
    bc.setPrefHeight(100);
    bc.setMaxHeight(100);
    bc.setPrefWidth(150);
    bc.setCreateSymbols(false);

    // do not add data to chart
    xAxis.setAutoRanging(false);
    xAxis.setUpperBound(maxRT + 1.5d);
    xAxis.setLowerBound(maxRT - 1.5d);

    bc.setOnScroll(new EventHandler<>() {
      @Override
      public void handle(ScrollEvent event) {
        NumberAxis axis = xAxis;
        final double minX = xAxis.getLowerBound();
        final double maxX = xAxis.getUpperBound();
        double d = maxX - minX;
        double x = event.getX();
        double direction = event.getDeltaY();
        if (direction > 0) {
          if (d > 0.3) {
            axis.setLowerBound(minX + 0.1);
            axis.setUpperBound(maxX - 0.1);
          }
        } else {
          axis.setLowerBound(minX - 0.1);
          axis.setUpperBound(maxX + 0.1);
        }
        event.consume();
      }
    });

    this.getChildren().add(bc);
  } catch (Exception ex) {
    logger.log(Level.WARNING, "error in DP", ex);
  }
}
 
Example 3
Source File: LatLongFromLocation.java    From PokeMate with GNU General Public License v3.0 4 votes vote down vote up
public AtomicDouble getLatitude() {
    AtomicDouble atomicLat =  new AtomicDouble();
    atomicLat.set(latitude);
    return atomicLat;
}
 
Example 4
Source File: LatLongFromLocation.java    From PokeMate with GNU General Public License v3.0 4 votes vote down vote up
public AtomicDouble getLongitude() {
    AtomicDouble atomicLng =  new AtomicDouble();
    atomicLng.set(longitude);
    return atomicLng;
}
 
Example 5
Source File: PokeMate.java    From PokeMate with GNU General Public License v3.0 4 votes vote down vote up
private PokeMate() throws LoginFailedException, RemoteServerException {

        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(60, TimeUnit.SECONDS);
        builder.readTimeout(60, TimeUnit.SECONDS);
        builder.writeTimeout(60, TimeUnit.SECONDS);
        OkHttpClient http = builder.build();
        CredentialProvider auth;

        AtomicDouble lat;
        AtomicDouble lng;
        // Co-ordinates by location name
        if (Config.isUseCustomNamedLocation()) {
            LatLongFromLocation fromLocation = new LatLongFromLocation(Config.getGoogleApiKey());
            String namedLocation = Config.getCustomNamedLocation();
            fromLocation.parseLocation(namedLocation);

            lat = fromLocation.getLatitude();
            lng = fromLocation.getLongitude();

            logger.info("Using Custom Location {} with lat/lon {}, {}", namedLocation, lat, lng);

        } else { // Use given co-ordindates instead
            AtomicDouble alat = new AtomicDouble();
            alat.set(Double.parseDouble(Config.getProperties().getProperty("latitude")) + getSmallRandom());
            lat = alat;

            AtomicDouble alng = new AtomicDouble();
            alng.set(Double.parseDouble(Config.getProperties().getProperty("longitude")) + getSmallRandom());
            lng = alng;

            logger.info("Using Coordinates {}, {}", lat, lng);
        }

        auth = Context.Login(http);

        logger.info("Logged in as {}", Config.getUsername());

        //PokemonGo go = new PokemonGo(auth, http);
        PokemonGo go = new PokemonGo(auth, http, new SystemTimeImpl());
        // Generate Device
        DeviceInfo deviceInfo = new DeviceInfo();
        byte[] b = new byte[16];
        new Random().nextBytes(b);
        deviceInfo.setDeviceId(Hex.encodeHexString(b));
        deviceInfo.setDeviceBrand("Apple");
        deviceInfo.setDeviceModel(Config.getDeviceSettings().get(2));
        deviceInfo.setDeviceModelBoot(Config.getDeviceSettings().get(0) + "," + Config.getDeviceSettings().get(1)); //TODO: Fix this stupid hack
        deviceInfo.setHardwareManufacturer("Apple");
        deviceInfo.setHardwareModel(Config.getDeviceSettings().get(3));
        deviceInfo.setFirmwareBrand("iPhone OS");
        deviceInfo.setFirmwareType(Config.getOsVersion());

        go.setDeviceInfo(deviceInfo);

        context = new Context(go, go.getPlayerProfile(), false, auth, http);
        context.setLat(lat);
        context.setLng(lng);
        go.setLocation(context.getLat().get(), context.getLng().get(), 0);
        Time.sleep(5000);
        new Update(context).run();

        if (Config.isShowUI()) {
            PokeMateUI.setPoke(this);
            new Thread(() -> Application.launch(PokeMateUI.class, "")).start();
        }
        Time.sleep(500);
        TaskController controller = new TaskController(context);
        controller.start();
        startTime = System.currentTimeMillis();
    }
 
Example 6
Source File: TrainingDataLoader.java    From EasySRL with Apache License 2.0 4 votes vote down vote up
/**
 * Build a chart for the sentence using the specified supertagger beam. If the chart exceeds the maximum size, beta
 * is doubled and the parser will re-try. When the function returns, beta will contain the value of the beam used
 * for the returned chart.
 *
 */
CompressedChart parseSentence(final List<String> sentence, final AtomicDouble beta,
		final Collection<Category> rootCategories) {
	final CompressedChart compressed;

	final List<Collection<Category>> categories = new ArrayList<>();
	final List<List<ScoredCategory>> tagsForSentence = tagger.tag(InputWord.listOf(sentence));
	for (final List<ScoredCategory> tagsForWord : tagsForSentence) {
		final List<Category> tagsForWord2 = new ArrayList<>();

		final double threshold = beta.doubleValue() * Math.exp(tagsForWord.get(0).getScore());

		for (final ScoredCategory leaf : tagsForWord) {
			if (Math.exp(leaf.getScore()) < threshold) {
				break;
			}
			tagsForWord2.add(leaf.getCategory());
		}

		categories.add(tagsForWord2);
	}

	// Find set of all parses
	final ChartCell[][] chart = parser.parse(sentence, categories);

	if (chart == null) {
		if (beta.doubleValue() * 2 < 0.1 && backoff) {
			beta.set(beta.doubleValue() * 2);
			return parseSentence(sentence, beta, rootCategories);
		} else {
			return null;
		}
	}
	if (chart[0][chart.length - 1] == null || chart[0][chart.length - 1].getEntries().size() == 0) {
		return null;
	}

	compressed = CompressedChart.make(InputWord.listOf(sentence), chart, cutoffsDictionary, unaryRules,
			rootCategories);

	return compressed;
}
 
Example 7
Source File: SlideWindowDependencyTest.java    From status with Apache License 2.0 4 votes vote down vote up
@Test
public void test() throws Exception {
    final AtomicDouble failedRatio = new AtomicDouble(0);
    final AtomicLong time = new AtomicLong(System.currentTimeMillis());
    final double errorRange = 0.0001;
    final TestDependency testDependency = new TestDependency(failedRatio, time, 0.05, 0.1, 0.2, 600 * 1000);
    // Test OK
    CheckResult checkResult = testDependency.call();
    assertEquals(CheckStatus.OK, checkResult.getStatus());
    assertEquals(0, Double.valueOf(checkResult.getErrorMessage()), errorRange);
    // Test MINOR
    failedRatio.set(0.12);
    time.addAndGet(100 * 1000);
    checkResult = testDependency.call();
    assertEquals(CheckStatus.MINOR, checkResult.getStatus());
    assertEquals(0.06, Double.valueOf(checkResult.getErrorMessage()), errorRange);
    // Test MAJOR
    failedRatio.set(0.24);
    time.addAndGet(100 * 1000);
    checkResult = testDependency.call();
    assertEquals(CheckStatus.MAJOR, checkResult.getStatus());
    assertEquals(0.12, Double.valueOf(checkResult.getErrorMessage()), errorRange);
    // Test OUTAGE
    failedRatio.set(0.48);
    time.addAndGet(200 * 1000);
    checkResult = testDependency.call();
    assertEquals(CheckStatus.OUTAGE, checkResult.getStatus());
    assertEquals(0.24, Double.valueOf(checkResult.getErrorMessage()), errorRange);
    // Test ping throw Exception
    failedRatio.set(100);
    time.addAndGet(100 * 1000);
    checkResult = testDependency.call();
    assertEquals(CheckStatus.OUTAGE, checkResult.getStatus());
    assertEquals(0.34, Double.valueOf(checkResult.getErrorMessage()), errorRange);
    // Remove one point
    failedRatio.set(0.48);
    time.addAndGet(100 * 1000);
    checkResult = testDependency.call();
    assertEquals(CheckStatus.OUTAGE, checkResult.getStatus());
    assertEquals(0.476, Double.valueOf(checkResult.getErrorMessage()), errorRange);
    // Remove two point
    failedRatio.set(0);
    time.addAndGet(200 * 1000);
    checkResult = testDependency.call();
    assertEquals(CheckStatus.OUTAGE, checkResult.getStatus());
    assertEquals(0.49, Double.valueOf(checkResult.getErrorMessage()), errorRange);
    // Remove all points and add a new one.
    failedRatio.set(0.04);
    time.addAndGet(700 * 1000);
    checkResult = testDependency.call();
    assertEquals(CheckStatus.OK, checkResult.getStatus());
    assertEquals(0.04, Double.valueOf(checkResult.getErrorMessage()), errorRange);
    // Test recalculate
    failedRatio.set(0.15);
    time.addAndGet(10000 * 1000);
    checkResult = testDependency.call();
    assertEquals(CheckStatus.MAJOR, checkResult.getStatus());
    assertEquals(0.15, Double.valueOf(checkResult.getErrorMessage()), errorRange);
    // Test recalculate with multiple points.
    failedRatio.set(0.1);
    time.addAndGet(3400 * 1000);
    testDependency.call();
    failedRatio.set(0.1);
    time.addAndGet(100 * 1000);
    testDependency.call();
    failedRatio.set(0.5);
    time.addAndGet(300 * 1000);
    checkResult = testDependency.call();
    assertEquals(CheckStatus.OUTAGE, checkResult.getStatus());
    assertEquals(0.25, Double.valueOf(checkResult.getErrorMessage()), errorRange);
}