Example usage for com.google.common.util.concurrent AtomicDouble AtomicDouble

List of usage examples for com.google.common.util.concurrent AtomicDouble AtomicDouble

Introduction

In this page you can find the example usage for com.google.common.util.concurrent AtomicDouble AtomicDouble.

Prototype

public AtomicDouble(double initialValue) 

Source Link

Document

Creates a new AtomicDouble with the given initial value.

Usage

From source file:com.netflix.spinnaker.kork.metrics.SpectatorMetricWriter.java

private AtomicDouble getGaugeStorage(Id id) {
    final AtomicDouble newGauge = new AtomicDouble(0);
    final AtomicDouble existingGauge = gauges.putIfAbsent(id, newGauge);
    if (existingGauge == null) {
        return newGauge;
    }//from ww w .ja  va 2 s  .  c  o  m

    return existingGauge;
}

From source file:it.stilo.g.algo.PageRankPI.java

public static ArrayList<DoubleValues> compute(final WeightedGraph g, double beta, double sigma, int runner) {
    long time = System.currentTimeMillis();
    double[] ranks = new double[g.size];
    double[] oldRanks;
    int realSize = 0;
    for (int i = 0; i < g.size; i++) {
        if (g.in[i] != null || g.out[i] != null) {
            realSize++;//from ww w .  j a  v a  2  s. co  m
        }
    }

    double iV = 1d / (double) realSize;

    for (int i = 0; i < g.size; i++) {
        if (g.in[i] != null || g.out[i] != null) {
            ranks[i] = iV;
        }
    }

    double diff = 0;

    do {
        AtomicDouble S = new AtomicDouble(0.0);
        CountDownLatch first = new CountDownLatch(runner);
        CountDownLatch second = new CountDownLatch(runner);
        CountDownLatch third = new CountDownLatch(runner);

        oldRanks = Arrays.copyOf(ranks, ranks.length);

        Thread[] workers = new Thread[runner];
        for (int i = 0; i < runner; i++) {
            workers[i] = new Thread(
                    new PageRankPI(g, first, second, third, ranks, beta, realSize, S, i, runner));
            workers[i].setName("" + i);
            workers[i].start();
        }
        try {
            third.await();
        } catch (InterruptedException e) {
            logger.debug(e);
        }

    } while (ArraysUtil.L1(ArraysUtil.sub(oldRanks, ranks)) > sigma);

    ArrayList<DoubleValues> list = new ArrayList<DoubleValues>(realSize);
    for (int i = 0; i < ranks.length; i++) {
        if (g.in[i] != null || g.out[i] != null) {
            list.add(new DoubleValues(i, ranks[i]));
        }
    }
    Collections.sort(list);

    logger.info(((System.currentTimeMillis() - time) / 1000d) + "s");
    return list;
}

From source file:io.watchcat.node.monitoring.threshold.LoadAverageThresholds.java

@PostConstruct
public void postConstruct() {
    int numberOfCores = loadAverage.getNumberOfCpuCores();
    oneMinuteAverageCriticalThreshold = new AtomicDouble(numberOfCores + 3);
    oneMinuteAverageMajorThreshold = new AtomicDouble(numberOfCores + 2);
    oneMinuteAverageMinorThreshold = new AtomicDouble(numberOfCores + 1);

    fiveMinuteAverageCriticalThreshold = new AtomicDouble(numberOfCores + 2);
    fiveMinuteAverageMajorThreshold = new AtomicDouble(numberOfCores + 1);
    fiveMinuteAverageMinorThreshold = new AtomicDouble(numberOfCores);

    fifteenMinuteAverageCriticalThreshold = new AtomicDouble(numberOfCores + 0.25);
    fifteenMinuteAverageMajorThreshold = new AtomicDouble(numberOfCores);
    fifteenMinuteAverageMinorThreshold = new AtomicDouble(numberOfCores - 0.25);
}

From source file:eu.amidst.core.learning.parametric.ParallelMaximumLikelihood.java

/**
 * {@inheritDoc}/*  ww  w .  j  a  va2s  .  c o m*/
 */
@Override
public void initLearning() {
    efBayesianNetwork = new EF_BayesianNetwork(dag);
    if (laplace) {
        sumSS = efBayesianNetwork.createInitSufficientStatistics();
        dataInstanceCount = new AtomicDouble(1.0); //Initial counts
    } else {
        sumSS = efBayesianNetwork.createZeroSufficientStatistics();
        dataInstanceCount = new AtomicDouble(0.0); //Initial counts
    }
}

From source file:eu.amidst.dynamic.learning.parametric.ParallelMaximumLikelihood.java

/**
 * {@inheritDoc}/*from  w w  w  . ja va 2s  . c o m*/
 */
@Override
public void initLearning() {
    efBayesianNetwork = new EF_DynamicBayesianNetwork(dag);
    if (laplace) {
        sumSS = efBayesianNetwork.createInitSufficientStatistics();
        dataInstanceCount = new AtomicDouble(1.0); //Initial counts
    } else {
        sumSS = efBayesianNetwork.createZeroSufficientStatistics();
        dataInstanceCount = new AtomicDouble(0.0); //Initial counts
    }
}

From source file:eu.amidst.dynamic.learning.parametric.ParallelMLMissingData.java

/**
 * {@inheritDoc}//from  ww w.jav  a2 s.  c  o m
 */
@Override
public void initLearning() {
    efBayesianNetwork = new EF_DynamicBayesianNetwork(dag);
    if (laplace) {
        sumSS = DynamicPartialSufficientSatistics.createInitPartialSufficientStatistics(efBayesianNetwork);
        dataInstanceCount = new AtomicDouble(1.0); //Initial counts
    } else {
        sumSS = DynamicPartialSufficientSatistics.createZeroPartialSufficientStatistics(efBayesianNetwork);
        dataInstanceCount = new AtomicDouble(0.0); //Initial counts
    }
}

From source file:eu.amidst.core.learning.parametric.ParallelMLMissingData.java

/**
 * {@inheritDoc}//  w  w  w  .  jav  a 2  s .c  o m
 */
@Override
public void initLearning() {
    efBayesianNetwork = new EF_BayesianNetwork(dag);
    if (laplace) {
        sumSS = PartialSufficientSatistics.createInitPartialSufficientStatistics(efBayesianNetwork);
        dataInstanceCount = new AtomicDouble(1.0); //Initial counts
    } else {
        sumSS = PartialSufficientSatistics.createZeroPartialSufficientStatistics(efBayesianNetwork);
        dataInstanceCount = new AtomicDouble(0.0); //Initial counts
    }
}

From source file:it.stilo.g.algo.Leadership.java

public static ArrayList<DoubleValues> compute(final WeightedGraph g, double sigma, int runner) {
    long time = System.currentTimeMillis();
    double[] hub = new double[g.size];
    double[] auth = new double[g.size];
    double[] oldAuth;

    double iV = 1; //Hubness & Authority scores initialized by dafault to 1.

    for (int i = 0; i < g.size; i++) {
        if (g.in[i] != null || g.out[i] != null) {
            auth[i] = iV;//from w w w.j  a  v  a2s. co m
            hub[i] = iV;
        }
    }

    //Shared accoumulator for normalization phase.
    AtomicDouble SAuth = new AtomicDouble(0.0);
    AtomicDouble SHub = new AtomicDouble(0.0);
    int count = 0;
    do {
        SAuth.set(0.0);
        SHub.set(0.0);
        CountDownLatch authority = new CountDownLatch(runner);
        CountDownLatch hubness = new CountDownLatch(runner);
        CountDownLatch normalizationStep = new CountDownLatch(runner);

        oldAuth = Arrays.copyOf(auth, auth.length);

        Thread[] workers = new Thread[runner];
        for (int i = 0; i < runner; i++) {
            workers[i] = new Thread(
                    new Leadership(g, authority, hubness, normalizationStep, hub, auth, SHub, SAuth, i, runner),
                    "" + i);
            workers[i].start();
        }

        try {
            normalizationStep.await();
        } catch (InterruptedException e) {
            logger.debug(e);
        }
        count++;
    } while (ArraysUtil.L1(ArraysUtil.sub(oldAuth, auth)) > sigma); //Repeat until reach the desiderd precision.

    ArrayList<DoubleValues> leader = new ArrayList<DoubleValues>();

    //Create ranking lists for Hubness & Authority
    for (int i = 0; i < auth.length; i++) {
        if (g.in[i] != null || g.out[i] != null) {
            leader.add(new DoubleValues(i, (auth[i] + hub[i]) / 2.0d));
        }
    }

    Collections.sort(leader);

    logger.trace(((System.currentTimeMillis() - time) / 1000d) + "s\t" + count);
    return leader;
}

From source file:it.stilo.g.algo.HubnessAuthority.java

public static ArrayList<ArrayList<DoubleValues>> compute(final WeightedGraph g, double sigma, int runner) {
    long time = System.currentTimeMillis();
    double[] hub = new double[g.size];
    double[] auth = new double[g.size];
    double[] oldAuth;

    double iV = 1; //Hubness & Authority scores initialized by dafault to 1.

    for (int i = 0; i < g.size; i++) {
        if (g.in[i] != null || g.out[i] != null) {
            auth[i] = iV;//  w w w .  j a  va2  s .co m
            hub[i] = iV;
        }
    }

    //Shared accoumulator for normalization phase.
    AtomicDouble SAuth = new AtomicDouble(0.0);
    AtomicDouble SHub = new AtomicDouble(0.0);
    int count = 0;
    do {
        SAuth.set(0.0);
        SHub.set(0.0);
        CountDownLatch authority = new CountDownLatch(runner);
        CountDownLatch hubness = new CountDownLatch(runner);
        CountDownLatch normalizationStep = new CountDownLatch(runner);

        oldAuth = Arrays.copyOf(auth, auth.length);

        Thread[] workers = new Thread[runner];
        for (int i = 0; i < runner; i++) {
            workers[i] = new Thread(new HubnessAuthority(g, authority, hubness, normalizationStep, hub, auth,
                    SHub, SAuth, i, runner), "" + i);
            workers[i].start();
        }

        try {
            normalizationStep.await();
        } catch (InterruptedException e) {
            logger.debug(e);
        }
        count++;
    } while (ArraysUtil.L1(ArraysUtil.sub(oldAuth, auth)) > sigma); //Repeat until reach the desiderd precision.

    ArrayList<DoubleValues> listAuth = new ArrayList<DoubleValues>();
    ArrayList<DoubleValues> listHub = new ArrayList<DoubleValues>();

    //Create ranking lists for Hubness & Authority
    for (int i = 0; i < auth.length; i++) {
        if (g.in[i] != null || g.out[i] != null) {
            listAuth.add(new DoubleValues(i, auth[i]));
            listHub.add(new DoubleValues(i, hub[i]));
        }
    }

    Collections.sort(listAuth);
    Collections.sort(listHub);

    ArrayList<ArrayList<DoubleValues>> list = new ArrayList<ArrayList<DoubleValues>>();
    list.add(new ArrayList(listAuth));
    list.add(new ArrayList(listHub));

    logger.trace(((System.currentTimeMillis() - time) / 1000d) + "s\t" + count);
    return list;
}

From source file:it.geosolutions.jaiext.stats.HistogramMode.java

@Override
protected synchronized void clearStats() {
    // All the bins are set to 0
    for (int i = 0; i < numBins; i++) {
        bins[i] = new AtomicDouble(0);
    }//from  w  w  w. j  a v  a 2  s  . c o m
}