Example usage for java.util.stream DoubleStream of

List of usage examples for java.util.stream DoubleStream of

Introduction

In this page you can find the example usage for java.util.stream DoubleStream of.

Prototype

public static DoubleStream of(double... values) 

Source Link

Document

Returns a sequential ordered stream whose elements are the specified values.

Usage

From source file:Main.java

public static void main(String[] args) {
    DoubleStream d = DoubleStream.of(1.2);

    d.forEach(System.out::println);

}

From source file:Main.java

public static void main(String[] args) {
    List<String> stringList = Arrays.asList("1.2", "2.2", "3", "4", "5");

    stringList.stream().flatMapToDouble(n -> DoubleStream.of(Double.parseDouble(n)))
            .forEach(System.out::println);
}

From source file:edu.washington.gs.skyline.model.quantification.PValues.java

public static double[] adjustPValues(double[] pValues) {
    List<Pair<Double, Integer>> entries = new ArrayList<>();
    DoubleStream.of(pValues).forEach(value -> entries.add(Pair.of(value, entries.size())));
    Collections.sort(entries);/* w ww . j  av a2  s .  c o m*/
    double currentMin = 1.0;
    double[] result = new double[entries.size()];
    for (int i = entries.size() - 1; i >= 0; i--) {
        double value = entries.get(i).getLeft() * entries.size() / (i + 1);
        currentMin = Math.min(value, currentMin);
        result[entries.get(i).getRight()] = currentMin;
    }
    return result;
}

From source file:jp.ac.tohoku.ecei.sb.metabolomeqc.basiccorrector.helper.CoefficientOfVariation.java

public static double evaluate(double[] values) {
    double mean = DoubleStream.of(values).sum() / values.length;
    StandardDeviation standardDeviation = new StandardDeviation();
    double sd = standardDeviation.evaluate(values, mean);
    return sd / mean;
}

From source file:bigdataproject.KDistances.java

void getKSortedNearestNeighbors(int k) {
    double[] allK = new double[k * samples.length];
    int index = 0;
    for (double[] distRow : distanceMatrix) {
        Arrays.sort(distRow);/*w ww.java 2 s  .  c om*/
        double[] subK = Arrays.copyOfRange(distRow, 1, k);
        for (int j = 0; j < subK.length; j++) {
            final double value = subK[j];
            if (!DoubleStream.of(allK).anyMatch(x -> x == value)) {
                allK[index++] = value;
            }
        }
    }
    double[] finalArray = Arrays.copyOfRange(allK, 0, index);
    Arrays.sort(finalArray);
    Karray = finalArray;
}

From source file:jp.ac.tohoku.ecei.sb.metabolomeqc.basiccorrector.CompoundCVFilter.java

@Override
public IntensityMatrix doCorrection(IntensityMatrix original) {
    List<Sample> globalQC = original.getGlobalQCSamples();
    if (globalQC.size() == 0)
        throw new IllegalArgumentException("No global QC");
    Sample selectedGlobalQC = globalQC.get(0);

    log.info("selected global QC {}", selectedGlobalQC);

    Map<Integer, Map<Plate, Double>> compound2cv = new HashMap<>();
    Map<Integer, Compound> id2compound = new HashMap<>();

    for (Compound oneCompound : original.getRowKeys()) {
        compound2cv.put(oneCompound.getId(), new HashMap<>());
        id2compound.put(oneCompound.getId(), oneCompound);
    }/* www. j a v  a 2  s .c  o m*/

    for (Compound oneCompound : original.getRowKeys()) {
        for (Map.Entry<Plate, List<Injection>> onePlate : original.getInjectionsByPlate().entrySet()) {
            double[] globalInjectionValues = onePlate.getValue().stream()
                    .filter(i -> i.getSample().equals(selectedGlobalQC) && !i.isIgnored())
                    .mapToDouble(i -> original.get(oneCompound, i)).toArray();
            double mean = DoubleStream.of(globalInjectionValues).sum() / globalInjectionValues.length;
            StandardDeviation standardDeviation = new StandardDeviation();
            double sd = standardDeviation.evaluate(globalInjectionValues, mean);
            double cv = sd / mean;

            compound2cv.get(oneCompound.getId()).put(onePlate.getKey(), cv);
            oneCompound.setAttribute(String.format("Plate-%d-CV", onePlate.getKey().getId()),
                    String.valueOf(cv));
        }
    }

    Map<Integer, Double> maxcv = new HashMap<>();
    List<Compound> newCompounds = new ArrayList<>();
    for (Map.Entry<Integer, Map<Plate, Double>> one : compound2cv.entrySet()) {
        maxcv.put(one.getKey(), one.getValue().values().stream().max(Double::compare).get());
        id2compound.get(one.getKey()).setAttribute("MaxCV", maxcv.get(one.getKey()));
        if (maxcv.get(one.getKey()) < CVThreshold) {
            newCompounds.add(id2compound.get(one.getKey()));
        }
    }

    IntensityMatrixImpl newMatrix = new IntensityMatrixImpl(newCompounds.size(), original.getSize()[1]);
    newMatrix.setRowKeys(newCompounds);
    newMatrix.setColumnKeys(original.getColumnKeys());

    for (Compound oneCompound : newCompounds) {
        for (Injection oneInjection : original.getColumnKeys()) {
            newMatrix.put(oneCompound, oneInjection, original.get(oneCompound, oneInjection));
        }
    }

    return newMatrix;
}

From source file:com.facebook.presto.operator.aggregation.TestCorrelationAggregation.java

private Double[] box(double[] values) {
    return DoubleStream.of(values).boxed().toArray(Double[]::new);
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.collective_score.scorers.EditDistanceCollectiveAnswerScorer.java

@Override
public Map<String, Double> score(JCas jcas, Answer answer) {
    Map<Answer, Double> neighbor2distance = distances.row(answer);
    ImmutableMap.Builder<String, Double> builder = ImmutableMap.builder();
    for (int topLimit : topLimits) {
        double[] distances = answers.subList(0, Math.min(answers.size(), topLimit)).stream()
                .mapToDouble(neighbor -> neighbor2distance.getOrDefault(neighbor, 0.0)).toArray();
        builder.put("edit-distance-min-" + topLimit, Doubles.min(distances));
        builder.put("edit-distance-max-" + topLimit, Doubles.max(distances));
        builder.put("edit-distance-avg-" + topLimit, DoubleStream.of(distances).average().orElse(0.0));
    }//from w w w  . j  av  a2 s . c om
    return builder.build();
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.collective_score.scorers.ShapeDistanceCollectiveAnswerScorer.java

@Override
public Map<String, Double> score(JCas jcas, Answer answer) {
    ImmutableMap.Builder<String, Double> builder = ImmutableMap.builder();
    Map<Answer, Double> neighbor2distance = distances.row(answer);
    Map<Answer, Double> neighbor2bdistance = bdistances.row(answer);
    for (int topLimit : topLimits) {
        double[] distances = answers.subList(0, Math.min(answers.size(), topLimit)).stream()
                .mapToDouble(neighbor -> neighbor2distance.getOrDefault(neighbor, 0.0)).toArray();
        builder.put("shape-distance-min-" + topLimit, Doubles.min(distances));
        builder.put("shape-distance-max-" + topLimit, Doubles.max(distances));
        builder.put("shape-distance-avg-" + topLimit, DoubleStream.of(distances).average().orElse(0.0));
        double[] bdistances = answers.subList(0, Math.min(answers.size(), topLimit)).stream()
                .mapToDouble(neighbor -> neighbor2bdistance.getOrDefault(neighbor, 0.0)).toArray();
        builder.put("shape-bdistance-min-" + topLimit, Doubles.min(bdistances));
        builder.put("shape-bdistance-max-" + topLimit, Doubles.max(bdistances));
        builder.put("shape-bdistance-avg-" + topLimit, DoubleStream.of(bdistances).average().orElse(0.0));
    }//from w  w  w . ja  v  a 2s. c  o  m
    return builder.build();
}

From source file:com.jscriptive.moneyfx.ui.account.AccountFrame.java

private String getAbsSum(List<AccountItem> accountItems) {
    double sum = accountItems.parallelStream()
            .flatMapToDouble(item -> DoubleStream.of(abs(item.getBalance().doubleValue()))).sum();
    return CurrencyFormat.getInstance().format(sum);
}