Example usage for java.util.stream IntStream sequential

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

Introduction

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

Prototype

@Override
    IntStream sequential();

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    IntStream i = IntStream.of(1, 2, 3, 4, 5, 6, 7);
    IntStream o = i.sequential();
    o.forEach(System.out::println);
}

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

/**
 * {@inheritDoc}//  w  w  w  . j av  a 2 s.  com
 */
@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)));
    //        }

}