Example usage for java.util.stream IntStream mapToDouble

List of usage examples for java.util.stream IntStream mapToDouble

Introduction

In this page you can find the example usage for java.util.stream IntStream mapToDouble.

Prototype

DoubleStream mapToDouble(IntToDoubleFunction mapper);

Source Link

Document

Returns a DoubleStream consisting of the results of applying the given function to the elements of this stream.

Usage

From source file:Main.java

public static void main(String[] args) {
    IntStream i = IntStream.of(6, 5, 7, 1, 2, 3, 3);
    DoubleStream d = i.mapToDouble(Math::sin);
    d.forEach(System.out::println);
}

From source file:eu.amidst.core.inference.ImportanceSamplingRobust.java

/**
 * {@inheritDoc}/*  w  w  w .j av  a  2  s .c  om*/
 */
@Override
public void runInference() {

    LocalRandomGenerator randomGenerator = new LocalRandomGenerator(seed);

    IntStream weightedSampleStream = IntStream.range(0, sampleSize).parallel();

    if (!parallelMode) {
        weightedSampleStream = weightedSampleStream.sequential();
    }

    //            weightedSampleStream = IntStream.range(0, sampleSize).parallel()
    //                    .mapToObj(i -> generateSample(randomGenerator.current()));
    //        } else {
    //            weightedSampleStream = IntStream.range(0, sampleSize).sequential()
    //                    .mapToObj(i -> generateSample(randomGenerator.current()));
    //        }

    double logSumWeights = weightedSampleStream.mapToDouble(i -> {
        WeightedAssignment weightedSample = generateSample(randomGenerator.current());
        updatePosteriorDistributions(weightedSample.assignment, weightedSample.logWeight);
        //updateLogProbabilityOfEvidence(weightedSample.logWeight);

        //logProbOfEvidence = robustSumOfLogarithms(logProbOfEvidence,weightedSample.logWeight-Math.log(sampleSize));

        //System.out.println(weightedSample.logWeight);

        //System.out.println(logProbOfEvidence);

        return weightedSample.logWeight;

    }).reduce(this::robustSumOfLogarithms).getAsDouble();

    //        return weightedSampleStream.mapToDouble(ws -> ws.logWeight - Math.log(sampleSize)).reduce(this::robustSumOfLogarithms).getAsDouble();

    //logProbOfEvidence = robustSumOfLogarithms(logProbOfEvidence,-Math.log(sampleSize));

    if (evidence != null) {
        logProbOfEvidence = logSumWeights - Math.log(sampleSize);
    } else {
        logProbOfEvidence = 0;
    }

    //        if(saveDataOnMemory_) {
    //            weightedSampleList = weightedSampleStream.collect(Collectors.toList());
    //            //weightedSampleList.forEach(weightedAssignment -> System.out.println("Weight: " + weightedAssignment.logWeight + " for assignment " + weightedAssignment.assignment.getValue(this.model.getVariables().getListOfVariables().get(0)) + " prob " + model.getLogProbabiltyOf(weightedAssignment.assignment)));
    //        }

}