Example usage for java.util.stream DoubleStream concat

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

Introduction

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

Prototype

public static DoubleStream concat(DoubleStream a, DoubleStream b) 

Source Link

Document

Creates a lazily concatenated stream whose elements are all the elements of the first stream followed by all the elements of the second stream.

Usage

From source file:Main.java

public static void main(String[] args) {
    DoubleStream i = DoubleStream.concat(DoubleStream.of(1.0, 2.0, 3.3), DoubleStream.of(4.4, 5.5, 6.6, 7.7));
    Stream<Double> o = i.boxed();

    o.forEach(System.out::println);
}

From source file:org.jamocha.rating.fraj.RatingProvider.java

private double rateBetaWithExistentials(final StatisticsProvider statisticsProvider,
        final PathNodeFilterSet toRate,
        final Map<Set<PathFilterList>, List<Pair<List<Set<PathFilterList>>, List<PathFilter>>>> componentToJoinOrder,
        final Map<Path, Set<PathFilterList>> pathToPreNetworkComponents) {
    final Set<Path> positiveExistentialPaths = toRate.getPositiveExistentialPaths();
    final Set<Path> negativeExistentialPaths = toRate.getNegativeExistentialPaths();
    final Set<Set<PathFilterList>> positiveExistentialComponents = new HashSet<>(),
            negativeExistentialComponents = new HashSet<>(), regularComponents = new HashSet<>();
    final Set<Set<PathFilterList>> preNetworkComponents = new HashSet<>(pathToPreNetworkComponents.values());
    for (final Set<PathFilterList> preNetworkComponent : preNetworkComponents) {
        final PathCollector<HashSet<Path>> pathCollector = PathCollector.newHashSet();
        preNetworkComponent.forEach(pathCollector::collectAllInLists);
        final HashSet<Path> paths = pathCollector.getPaths();
        if (!Collections.disjoint(paths, positiveExistentialPaths)) {
            positiveExistentialComponents.add(preNetworkComponent);
        } else if (!Collections.disjoint(paths, negativeExistentialPaths)) {
            negativeExistentialComponents.add(preNetworkComponent);
        } else {/*w  w w  .  j  a v a2s.  c  om*/
            regularComponents.add(preNetworkComponent);
        }
    }
    final Map<Set<PathFilterList>, Data> preNetworkComponentToData = preNetworkComponents.stream()
            .collect(toMap(Function.identity(), statisticsProvider::getData));
    final Map<Set<PathFilterList>, PathFilter> existentialComponentToFilter = componentToJoinOrder.values()
            .iterator().next().stream().filter(p -> !regularComponents.contains(p.getLeft().iterator().next()))
            .collect(toMap(p -> p.getLeft().iterator().next(), p -> p.getRight().iterator().next()));

    final double tupleSize = regularComponents.stream()
            .mapToDouble(c -> preNetworkComponentToData.get(c).getTupleSize()).sum();
    final double tuplesPerPage = statisticsProvider.getPageSize() / tupleSize;
    final double unfilteredRowCount = calcBetaUnfilteredSize(statisticsProvider, componentToJoinOrder,
            pathToPreNetworkComponents, regularComponents);
    final double rowCount = unfilteredRowCount * DoubleStream
            .concat(positiveExistentialComponents.stream()
                    .mapToDouble(component -> 1 - Math.pow(
                            (1 - statisticsProvider.getJSF(regularComponents, component,
                                    existentialComponentToFilter.get(component), pathToPreNetworkComponents)),
                            preNetworkComponentToData.get(component).getRowCount())),
                    negativeExistentialComponents.stream().mapToDouble(component -> Math.pow(
                            (1 - statisticsProvider.getJSF(regularComponents, component,
                                    existentialComponentToFilter.get(component), pathToPreNetworkComponents)),
                            preNetworkComponentToData.get(component).getRowCount())))
            .reduce(1.0, (a, b) -> a * b);
    final double xOverUX = rowCount / unfilteredRowCount;
    // joinsize is needed twice per component, thus pre-calculate it
    final Map<Set<PathFilterList>, Double> regularComponentToJoinSize = regularComponents.stream()
            .collect(toMap(Function.identity(),
                    component -> joinSize(statisticsProvider, component, componentToJoinOrder.get(component),
                            positiveExistentialComponents, negativeExistentialComponents,
                            pathToPreNetworkComponents, xOverUX)));
    // dnrating (30a)
    final double finsert = xOverUX
            * regularComponents.stream()
                    .mapToDouble(component -> preNetworkComponentToData.get(component).getFinsert()
                            * regularComponentToJoinSize.get(component))
                    .sum()
            + DoubleStream.concat(negativeExistentialComponents.stream().mapToDouble(component -> {
                final double jsf = statisticsProvider.getJSF(regularComponents, component,
                        existentialComponentToFilter.get(component), pathToPreNetworkComponents);
                return preNetworkComponentToData.get(component).getFdelete() * rowCount * (jsf / (1 - jsf));
            }), positiveExistentialComponents.stream()
                    .mapToDouble(component -> preNetworkComponentToData.get(component).getFinsert() * rowCount
                            * statisticsProvider.getJSF(regularComponents, component,
                                    existentialComponentToFilter.get(component), pathToPreNetworkComponents)))
                    .sum();
    // dnrating (30b)
    final double fdelete = DoubleStream.concat(
            regularComponents.stream().mapToDouble(c -> preNetworkComponentToData.get(c).getFdelete()),
            DoubleStream.concat(negativeExistentialComponents.stream()
                    .mapToDouble(component -> preNetworkComponentToData.get(component).getFdelete() * rowCount
                            * statisticsProvider.getJSF(regularComponents, component,
                                    existentialComponentToFilter.get(component), pathToPreNetworkComponents)),
                    positiveExistentialComponents.stream().mapToDouble(component -> {
                        final double jsf = statisticsProvider.getJSF(regularComponents, component,
                                existentialComponentToFilter.get(component), pathToPreNetworkComponents);
                        return preNetworkComponentToData.get(component).getFinsert() * rowCount
                                * (jsf / (1 - jsf));
                    })))
            .sum();
    // publish information to statistics provider
    {
        final Set<PathFilterList> filters = new HashSet<>();
        componentToJoinOrder.keySet().forEach(filters::addAll);
        filters.add(toRate);
        statisticsProvider.setData(filters, new Data(finsert, fdelete, rowCount, tupleSize));
    }
    final double mUxBeta = m(unfilteredRowCount, tuplesPerPage);
    // dnrating (40)
    final double runtimeCost = DoubleStream.concat(regularComponents.stream().mapToDouble(component -> {
        final Data data = preNetworkComponentToData.get(component);
        return data.getFinsert()
                * costPosInsVarII(statisticsProvider, component, componentToJoinOrder.get(component),
                        regularComponents, pathToPreNetworkComponents)
                + data.getFdelete() * (mUxBeta + cardenas(mUxBeta, regularComponentToJoinSize.get(component)));
    }), Stream.concat(positiveExistentialComponents.stream(), negativeExistentialComponents.stream())
            .mapToDouble(component -> {
                final Data data = preNetworkComponentToData.get(component);
                return data.getFinsert() * 2
                        * jc(statisticsProvider, statisticsProvider.getJSF(regularComponents, component,
                                existentialComponentToFilter.get(component), pathToPreNetworkComponents), data,
                                1)
                        + data.getFdelete() * costNegDelVarII(statisticsProvider, component,
                                componentToJoinOrder.get(component), pathToPreNetworkComponents);
            })).sum();
    final double memoryCost = unfilteredRowCount * (tupleSize
            + 0.15 * (positiveExistentialComponents.size() + negativeExistentialComponents.size()));
    return cpuAndMemCostCombiner.applyAsDouble(runtimeCost, memoryCost);
}