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

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

Introduction

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

Prototype

public double doubleValue() 

Source Link

Document

Returns the value of this AtomicDouble as a double .

Usage

From source file:jurls.core.becca.DefaultZiptie.java

public static double getExponentialSum(RealMatrix c, double exponent, int rowStart, int rowEnd, int colStart,
        int colEnd) {
    AtomicDouble s = new AtomicDouble(0);
    c.walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() {
        @Override/*from  w w  w .j a v a  2 s.c  o m*/
        public void visit(int row, int column, double value) {
            s.addAndGet(Math.pow(value, exponent));
        }
    }, rowStart, rowEnd, colStart, colEnd);
    return s.doubleValue();
}

From source file:com.sri.ai.praise.model.v1.imports.uai.UAIMARSolver.java

private static double calculateCompressedEntries(Expression compressedTableExpression) {
    AtomicDouble count = new AtomicDouble(0);

    visitCompressedTableEntries(compressedTableExpression, count);

    return count.doubleValue();
}

From source file:com.twitter.common.stats.Stats.java

/**
 * 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.
 *///from   w w w .  j av  a2  s.c  om
public static AtomicDouble export(String name, final AtomicDouble doubleVar) {
    export(new StatImpl<Double>(name) {
        @Override
        public Double read() {
            return doubleVar.doubleValue();
        }
    });

    return doubleVar;
}

From source file:jurls.core.becca.DefaultZiptie.java

public static double getGeneralizedMean(RealMatrix c, double exponent, int rowStart, int rowEnd, int colStart,
        int colEnd) {
    AtomicDouble s = new AtomicDouble(0);
    AtomicInteger n = new AtomicInteger(0);
    c.walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() {
        @Override//from   w  w w  .ja v a2  s.  co m
        public void visit(int row, int column, double value) {
            s.addAndGet(Math.pow(value, exponent));
            n.incrementAndGet();
        }
    }, rowStart, rowEnd, colStart, colEnd);

    return (1.0 / n.doubleValue()) * Math.pow(s.doubleValue(), 1.0 / exponent);
}

From source file:io.prometheus.client.AtomicDoubleSerializer.java

@Override
public JsonElement serialize(final AtomicDouble src, final Type typeOfSrc,
        final JsonSerializationContext context) {
    return new JsonPrimitive(src.doubleValue());
}

From source file:jurls.core.becca.DefaultZiptie.java

public double getRowGeneralizedMean(RealMatrix c, Function<Integer, Double> rowEntryMultiplier, double exponent,
        int rowStart, int rowEnd, int column) {
    AtomicDouble s = new AtomicDouble(0);
    AtomicInteger n = new AtomicInteger(0);
    c.walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() {
        @Override// ww w.j  a v a 2 s . com
        public void visit(int row, int column, double value) {
            double a = Math.pow(value, exponent);
            double b = rowEntryMultiplier.apply(row);
            s.addAndGet(a * b);
            n.incrementAndGet();
        }
    }, rowStart, rowEnd, column, column);

    return (1.0 / n.doubleValue()) * Math.pow(s.doubleValue(), 1.0 / exponent);
}

From source file:pt.ua.ri.search.ProximitySearch.java

@Override
public Iterable<Result> search(String query) {

    String nquery = null;/*from   w w  w. j  a  v a  2 s . c o m*/
    int dist = 1;

    Matcher m = queryPattern.matcher(query);
    if (m.matches()) {
        nquery = m.group("query");
        try {
            dist = Integer.parseInt(m.group("dist"));
        } catch (NumberFormatException ex) {
            dist = 1;
        }
    }

    if (nquery == null) {
        return super.search(query);
    }

    List<Result> ret = new ArrayList<>();
    Map<String, IndexTuple> tokenInfos = new HashMap<>();
    TObjectFloatHashMap<String> palavrasNLize = new TObjectFloatHashMap<>();
    TIntFloatMap docsnLize = new TIntFloatHashMap();
    tok.setText(query);

    List<String> palavras = new ArrayList<>();
    while (tok.hasNext()) {
        palavras.add(tok.next().getString());
    }

    final AtomicDouble queryLength = new AtomicDouble(0.0);

    for (String palavra : palavras) {
        index.get(palavra).ifPresent(postingList -> {
            tokenInfos.put(palavra, postingList);
            int df = postingList.getDocumentFrequency();
            float idf = (float) (Math.log(index.numberOfDocuments()) - Math.log(df));
            queryLength.addAndGet(idf * idf);
            palavrasNLize.put(palavra, idf);
        });
    }

    queryLength.set(Math.sqrt(queryLength.doubleValue()));
    palavrasNLize.transformValues(new TransformationFunction(queryLength.floatValue()));
    Iterator<String> it = palavras.iterator();

    // for each two words
    if (it.hasNext()) {
        String p_actual;
        String p_next = it.next();
        ProximityIndexTuple t_ac;
        ProximityIndexTuple t_nx = (ProximityIndexTuple) tokenInfos.get(p_next);
        while (it.hasNext()) {
            p_actual = p_next;
            p_next = it.next();
            t_ac = t_nx;
            t_nx = (ProximityIndexTuple) tokenInfos.get(p_next);
            // get all documents from both words
            // see documents in common

            Collection<Integer> isect = CollectionUtils.intersection(t_ac.getDocumentsID(),
                    t_nx.getDocumentsID());

            // for each document get positions of words

            for (int doc_id : isect) {
                Iterable<Integer> lp_ac = t_ac.getDocumentPositions(doc_id);
                Iterable<Integer> lp_nx = t_nx.getDocumentPositions(doc_id);

                Iterator<Integer> it_ac = lp_ac.iterator();
                Iterator<Integer> it_nx = lp_nx.iterator();

                if (!it_ac.hasNext() || !it_nx.hasNext()) {
                    break;
                }

                int pos_ac = it_ac.next(), pos_nx = it_nx.next();
                float score = docsnLize.containsKey(doc_id) ? docsnLize.get(doc_id) : 0;

                score += comparePos(pos_ac, pos_nx, dist, doc_id, palavrasNLize, p_actual, p_next, t_ac, t_nx);

                while (score <= 0.0f && (it_ac.hasNext() || it_nx.hasNext())) {
                    if (pos_ac < pos_nx) {
                        if (it_ac.hasNext()) {
                            pos_ac = it_ac.next();
                        } else {
                            pos_nx = it_nx.next();
                        }
                    } else {
                        if (it_nx.hasNext()) {
                            pos_nx = it_nx.next();
                        } else {
                            pos_ac = it_ac.next();
                        }
                    }

                    score += comparePos(pos_ac, pos_nx, dist, doc_id, palavrasNLize, p_actual, p_next, t_ac,
                            t_nx);
                }
                if (score > 0.0f) {
                    docsnLize.put(doc_id, score);
                }
            }
        }
    }

    docsnLize.forEachEntry((int doc_id, float score) -> ret.add(new SimpleResult(doc_id, score)));
    Collections.sort(ret);
    return ret;
}

From source file:org.deeplearning4j.plot.BarnesHutTsne.java

@Override
public double score() {
    // Get estimate of normalization term
    INDArray buff = Nd4j.create(numDimensions);
    AtomicDouble sum_Q = new AtomicDouble(0.0);
    for (int n = 0; n < N; n++)
        tree.computeNonEdgeForces(n, theta, buff, sum_Q);

    // Loop over all edges to compute t-SNE error
    double C = .0;
    INDArray linear = Y;/*from   www .j  a  v  a  2 s.c o m*/
    for (int n = 0; n < N; n++) {
        int begin = rows.getInt(n);
        int end = rows.getInt(n + 1);
        int ind1 = n;
        for (int i = begin; i < end; i++) {
            int ind2 = cols.getInt(i);
            buff.assign(linear.slice(ind1));
            buff.subi(linear.slice(ind2));

            double Q = pow(buff, 2).sum(Integer.MAX_VALUE).getDouble(0);
            Q = (1.0 / (1.0 + Q)) / sum_Q.doubleValue();
            C += vals.getDouble(i) * FastMath.log(vals.getDouble(i) + Nd4j.EPS_THRESHOLD)
                    / (Q + Nd4j.EPS_THRESHOLD);
        }
    }

    return C;
}

From source file:com.demigodsrpg.aspect.bloodlust.BloodlustAspectII.java

@Ability(name = "Deathblow", command = "deathblow", info = "Deal massive amounts of damage, increasing with each kill.", cost = 3500, cooldown = 200000, type = Ability.Type.ULTIMATE)
public AbilityResult deathblowAbility(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    PlayerModel model = DGData.PLAYER_R.fromPlayer(player);

    final AtomicDouble damage = new AtomicDouble(10.0);
    final AtomicInteger deaths = new AtomicInteger(0);

    final List<LivingEntity> targets = new ArrayList<LivingEntity>();
    final Location startloc = player.getLocation();
    for (LivingEntity e : player.getWorld().getLivingEntities()) {
        if (e.getLocation().toVector().isInSphere(player.getLocation().toVector(), 35) && !targets.contains(e)) // jumps to the nearest entity
        {// w ww  . jav  a 2  s .co m
            if (e instanceof Player
                    && DGData.PLAYER_R.fromPlayer((Player) e).getFaction().equals(model.getFaction()))
                continue;
            targets.add(e);
        }
    }
    if (targets.size() == 0) {
        player.sendMessage("There are no targets to attack.");
        return AbilityResult.OTHER_FAILURE;
    }

    final double savedHealth = player.getHealth();

    for (int i = 0; i < targets.size(); i++) {
        final int ii = i;
        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(DGData.PLUGIN, () -> {
            player.teleport(targets.get(ii));
            player.setHealth(savedHealth);
            player.getLocation().setPitch(targets.get(ii).getLocation().getPitch());
            player.getLocation().setYaw(targets.get(ii).getLocation().getYaw());
            if (targets.get(ii).getHealth() - damage.doubleValue() <= 0.0) {
                damage.set(10.0 + deaths.incrementAndGet() * 1.2);
                player.sendMessage(getGroup().getColor() + "Damage is now " + damage.doubleValue());
            }
            targets.get(ii).damage(damage.doubleValue(), player);
        }, i * 10);
    }

    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(DGData.PLUGIN, () -> {
        player.teleport(startloc);
        player.setHealth(savedHealth);
        player.sendMessage(targets.size() + " targets were struck with the power of bloodlust.");
    }, targets.size() * 10);

    return AbilityResult.SUCCESS;
}

From source file:com.court.controller.CollectionSheetFxmlController.java

private void bindSubTotalTo(TextField chk_amt_txt) {

    AtomicDouble ins_total = new AtomicDouble(0.0);
    AtomicDouble sub_total = new AtomicDouble(0.0);
    List<Member> mList = collection_tbl.getItems();

    mList.stream().forEach(m -> {/*ww  w .j  av  a  2s  .co  m*/
        ins_total.addAndGet(m.getMemberLoans().stream().mapToDouble(MemberLoan::getLoanInstallment).sum());

        List<MemberSubscriptions> mbrSubs = new ArrayList<>(m.getMemberSubscriptions());

        boolean flag = FxUtilsHandler.hasPreviousSubscriptions(m.getId());
        if (flag) {
            sub_total.addAndGet(mbrSubs.stream().mapToDouble(a -> a.getAmount()).sum());
        } else {
            sub_total.addAndGet(mbrSubs.stream().filter(s -> !s.getRepaymentType().equalsIgnoreCase("Once"))
                    .mapToDouble(a -> a.getAmount()).sum());
        }

    });
    total = ins_total.doubleValue() + sub_total.doubleValue();
    chk_amt_txt.setText(TextFormatHandler.CURRENCY_DECIMAL_FORMAT.format(total));
}