本文整理匯總了Java中com.google.common.util.concurrent.AtomicDouble類的典型用法代碼示例。如果您正苦於以下問題:Java AtomicDouble類的具體用法?Java AtomicDouble怎麽用?Java AtomicDouble使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AtomicDouble類屬於com.google.common.util.concurrent包,在下文中一共展示了AtomicDouble類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testGet_concurrent
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
public void testGet_concurrent() {
assertTrue(ArbitraryInstances.get(BlockingDeque.class).isEmpty());
assertTrue(ArbitraryInstances.get(BlockingQueue.class).isEmpty());
assertTrue(ArbitraryInstances.get(DelayQueue.class).isEmpty());
assertTrue(ArbitraryInstances.get(SynchronousQueue.class).isEmpty());
assertTrue(ArbitraryInstances.get(PriorityBlockingQueue.class).isEmpty());
assertTrue(ArbitraryInstances.get(ConcurrentMap.class).isEmpty());
assertTrue(ArbitraryInstances.get(ConcurrentNavigableMap.class).isEmpty());
ArbitraryInstances.get(Executor.class).execute(ArbitraryInstances.get(Runnable.class));
assertNotNull(ArbitraryInstances.get(ThreadFactory.class));
assertFreshInstanceReturned(
BlockingQueue.class, BlockingDeque.class, PriorityBlockingQueue.class,
DelayQueue.class, SynchronousQueue.class,
ConcurrentMap.class, ConcurrentNavigableMap.class,
AtomicReference.class, AtomicBoolean.class,
AtomicInteger.class, AtomicLong.class, AtomicDouble.class);
}
示例2: runMaxPublishLatencyTest
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
private void runMaxPublishLatencyTest() throws Throwable {
int highestRequestRate = 0;
for (AtomicDouble publishLatency = new AtomicDouble(0);
publishLatency.get() < maxPublishLatencyMillis;
Client.requestRate = (int) (Client.requestRate * 1.1)) {
Map<ClientType, Controller.LoadtestStats> statsMap = runTest(null);
statsMap.forEach(
(type, stats) -> {
if (type.isPublisher()) {
publishLatency.set(
LatencyDistribution.getNthPercentileUpperBound(
stats.bucketValues, maxPublishLatencyPercentile));
}
});
if (publishLatency.get() < maxPublishLatencyMillis) {
highestRequestRate = Client.requestRate;
}
}
log.info("Maximum Request Rate: " + highestRequestRate);
controller.shutdown(null);
}
示例3: testForEachValue
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
/**
* Test of forEachIn method, of class ReflectionHelper.
*/
@Test
public void testForEachValue() {
// Test Integers
final int int_sum = int_a + int_b + int_c;
final AtomicInteger intCounter = new AtomicInteger();
ReflectionHelper.forEachValueIn(this, Integer.class, intCounter::addAndGet);
assertEquals("Sum all of type int.", int_sum, intCounter.get());
// Test Doubles
final double double_sum = double_a + double_b + double_c;
final AtomicDouble doubleCounter = new AtomicDouble();
ReflectionHelper.forEachValueIn(this, Double.class, doubleCounter::addAndGet);
assertEquals("Sum all of type int.", double_sum, doubleCounter.get(), 0.0);
// Test All
final AtomicDouble numberCounter = new AtomicDouble();
ReflectionHelper.forEachValueIn(this, Number.class, n -> numberCounter.addAndGet(n.doubleValue()));
assertEquals("Sum all of numbers.", int_sum + double_sum, numberCounter.get(), 0.0);
}
示例4: testForEachValue
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
/**
* Test of forEachIn method, of class ReflectionHelper.
*/
@Test
public void testForEachValue() {
// Test Integers
final int int_sum = int_a + int_b + int_c;
final AtomicInteger intCounter = new AtomicInteger();
ReflectionHelper.forEachValueIn(this, Integer.class, intCounter::addAndGet);
assertEquals("Sum all of type int.", int_sum, intCounter.get());
// Test Doubles
final double double_sum = double_a + double_b + double_c;
final AtomicDouble doubleCounter = new AtomicDouble();
ReflectionHelper.forEachValueIn(this, Double.class, doubleCounter::addAndGet);
assertEquals("Sum all of type int.", double_sum, doubleCounter.get(), 0.0);
// Test All
final AtomicDouble numberCounter = new AtomicDouble();
ReflectionHelper.forEachValueIn(this, Number.class, n -> numberCounter.addAndGet(n.doubleValue()));
assertEquals("Sum all of numbers.", int_sum + double_sum, numberCounter.get(), 0.0);
}
示例5: getValue
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
@Override
public double getValue() {
final AtomicDouble logProbSum = new AtomicDouble(0);
final ParallelThreadPool ptp = new ParallelThreadPool();
for (final TreeNode<TSGNode> tree : treeCorpus) {
for (final TreeNode<TSGNode> root : TSGNode.getAllRootsOf(tree)) {
ptp.pushTask(new Runnable() {
@Override
public void run() {
logProbSum
.addAndGet(computeLog2PosteriorProbabilityOfRule(
root, true));
}
});
}
}
ptp.waitForTermination();
return logProbSum.get();
}
示例6: calculateCorpusLogProb
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
/**
* Calculate the log-probability of the whole corpus, given the TSG.
*
* @return
*/
protected SampleStats calculateCorpusLogProb() {
final AtomicDouble logProbSum = new AtomicDouble(0.);
final AtomicInteger nNodes = new AtomicInteger(0);
final ParallelThreadPool ptp = new ParallelThreadPool();
for (final TreeNode<TSGNode> tree : treeCorpus) {
ptp.pushTask(new Runnable() {
@Override
public void run() {
logProbSum
.addAndGet(computePosteriorLog2ProbabilityForTree(tree));
nNodes.addAndGet(tree.getTreeSize());
}
});
}
ptp.waitForTermination();
return new SampleStats(logProbSum.get(), nNodes.get());
}
示例7: computeContextData
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
/**
*
* Computes coefficients a, b, c and d (available) and computes the association
* rate based on these coefficients.
*
* These coefficients are made available through the not-thread safe methods <code>#getLastX()</code>.
*
* @param x
* the base term
* @param y
* the co term
* @return
* the association rate
*/
public ContextData computeContextData(CrossTable crossTable, Term x, Term y) {
ContextData data = new ContextData();
// A = (x & y)
data.setA((int)x.getContext().getNbCooccs(y));
// B = (x & not(y))
AtomicDouble a_plus_b = crossTable.getAPlusB().get(x);
data.setB(a_plus_b == null ? 0 : a_plus_b.intValue() - data.getA());
// int b = x.getFrequency() - a;
// C = (not(x) & y)
AtomicDouble a_plus_c = crossTable.getAPlusC().get(y);
data.setC(a_plus_c == null ? 0 : a_plus_c.intValue() - data.getA());
// int c = y.getFrequency() - a;
// D = (not(x) & not(y))
data.setD(crossTable.getTotalCoOccurrences() - data.getA() - data.getB() - data.getC());
return data;
}
示例8: computeCrossTable
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
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);
}
示例9: Leadership
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
private Leadership(WeightedGraph g,
CountDownLatch authority, CountDownLatch hubness, CountDownLatch normalizationStep,
double[] countHub, double[] countAuth,
AtomicDouble SHub, AtomicDouble SAuth,
int chunk, int runner) {
this.g = g;
this.chunk = chunk;
this.runner = runner;
this.authorityStep = authority;
this.hubnessStep = hubness;
this.normalizationStep = normalizationStep;
this.hub = countHub;
this.auth = countAuth;
this.SHub = SHub;
this.SAuth = SAuth;
}
示例10: HubnessAuthority
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
private HubnessAuthority(WeightedGraph g,
CountDownLatch authority, CountDownLatch hubness, CountDownLatch normalizationStep,
double[] countHub, double[] countAuth,
AtomicDouble SHub, AtomicDouble SAuth,
int chunk, int runner) {
this.g = g;
this.chunk = chunk;
this.runner = runner;
this.authorityStep = authority;
this.hubnessStep = hubness;
this.normalizationStep = normalizationStep;
this.hub = countHub;
this.auth = countAuth;
this.SHub = SHub;
this.SAuth = SAuth;
}
示例11: testGet_concurrent
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
public void testGet_concurrent() {
assertTrue(ArbitraryInstances.get(BlockingDeque.class).isEmpty());
assertTrue(ArbitraryInstances.get(BlockingQueue.class).isEmpty());
assertTrue(ArbitraryInstances.get(DelayQueue.class).isEmpty());
assertTrue(ArbitraryInstances.get(SynchronousQueue.class).isEmpty());
assertTrue(ArbitraryInstances.get(PriorityBlockingQueue.class).isEmpty());
assertTrue(ArbitraryInstances.get(ConcurrentMap.class).isEmpty());
assertTrue(ArbitraryInstances.get(ConcurrentNavigableMap.class).isEmpty());
ArbitraryInstances.get(Executor.class).execute(ArbitraryInstances.get(Runnable.class));
assertNotNull(ArbitraryInstances.get(ThreadFactory.class));
assertFreshInstanceReturned(
BlockingQueue.class,
BlockingDeque.class,
PriorityBlockingQueue.class,
DelayQueue.class,
SynchronousQueue.class,
ConcurrentMap.class,
ConcurrentNavigableMap.class,
AtomicReference.class,
AtomicBoolean.class,
AtomicInteger.class,
AtomicLong.class,
AtomicDouble.class);
}
示例12: getStatistics
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
private static Statistics getStatistics(Observable<CellValue> cells) {
final AtomicDouble sum = new AtomicDouble(0);
final AtomicDouble sumSquares = new AtomicDouble(0);
log.info("calculating mean and sd");
long count = cells
// add to sum and sumSquares
.doOnNext(new Action1<CellValue>() {
@Override
public void call(CellValue cell) {
sum.addAndGet(cell.getValue());
sumSquares.addAndGet(cell.getValue() * cell.getValue());
}
})
// count
.count()
// block and get
.toBlocking().single();
double mean = sum.get() / count;
double variance = sumSquares.get() / count - mean * mean;
double sd = Math.sqrt(variance);
log.info("calculated");
Statistics stats = new Statistics(mean, sd, count);
log.info(stats);
return stats;
}
示例13: aggregate
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
private void aggregate(Metric metric) {
List<AggregationRule> rules = aggregationConfiguration.getRules().get(metric.getTenant());
if (rules == null) {
return;
}
ConcurrentMap<MetricKey, AtomicDouble> timestampMap = getTimestampMap(metric.getTimestamp());
for(AggregationRule rule : rules) {
Matcher m = rule.getSource().matcher(metric.getPath());
if (m.matches()) {
String destinationPath = rule.getDestination().replace("<data>", m.group("data"));
MetricKey destinationKey = new MetricKey(metric.getTenant(), destinationPath, metric.getRollup(), metric.getPeriod(), metric.getTimestamp());
getMetricValue(timestampMap, destinationKey).addAndGet(metric.getValue());
}
}
}
示例14: gradient
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
@Override
public Gradient gradient() {
if (yIncs == null)
yIncs = zeros(Y.shape());
if (gains == null)
gains = ones(Y.shape());
AtomicDouble sumQ = new AtomicDouble(0);
/* Calculate gradient based on barnes hut approximation with positive and negative forces */
INDArray posF = Nd4j.create(Y.shape());
INDArray negF = Nd4j.create(Y.shape());
if (tree == null)
tree = new SpTree(Y);
tree.computeEdgeForces(rows, cols, vals, N, posF);
for (int n = 0; n < N; n++)
tree.computeNonEdgeForces(n, theta, negF.slice(n), sumQ);
INDArray dC = posF.subi(negF.divi(sumQ));
Gradient ret = new DefaultGradient();
ret.gradientForVariable().put(Y_GRAD, dC);
return ret;
}
示例15: export
import com.google.common.util.concurrent.AtomicDouble; //導入依賴的package包/類
/**
* Exports an {@link AtomicDouble}, which will be included in time series tracking.
*
* @param name The name to export the stat with.
* @param doubleVar The variable to export.
* @return A reference to the {@link AtomicDouble} provided.
*/
public static AtomicDouble export(String name, final AtomicDouble doubleVar) {
export(new StatImpl<Double>(name) {
@Override public Double read() { return doubleVar.doubleValue(); }
});
return doubleVar;
}