本文整理汇总了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;
}