/** * Builds VectorGeneratorsFamily instance. * * @param seed Seed. * @return Vector generators family. */ public VectorGeneratorsFamily build(long seed) { A.notEmpty(family, "family.size != 0"); double sumOfWeigts = weights.stream().mapToDouble(x -> x).sum(); double[] probs = weights.stream().mapToDouble(w -> w / sumOfWeigts).toArray(); List<VectorGenerator> mappedFamilily = family.stream().map(mapper).collect(Collectors.toList()); return new VectorGeneratorsFamily(mappedFamilily, new DiscreteRandomProducer(seed, probs)); } }
private SymbolStatsEstimate buildSymbolStatistics(List<Object> values, Session session, Type type) { List<Object> nonNullValues = values.stream() .filter(Objects::nonNull) .collect(toImmutableList()); if (nonNullValues.isEmpty()) { return SymbolStatsEstimate.zero(); } double[] valuesAsDoubles = nonNullValues.stream() .map(value -> toStatsRepresentation(metadata, session, type, value)) .filter(OptionalDouble::isPresent) .mapToDouble(OptionalDouble::getAsDouble) .toArray(); double lowValue = DoubleStream.of(valuesAsDoubles).min().orElse(Double.NEGATIVE_INFINITY); double highValue = DoubleStream.of(valuesAsDoubles).max().orElse(Double.POSITIVE_INFINITY); double valuesCount = values.size(); double nonNullValuesCount = nonNullValues.size(); long distinctValuesCount = nonNullValues.stream().distinct().count(); return SymbolStatsEstimate.builder() .setNullsFraction((valuesCount - nonNullValuesCount) / valuesCount) .setLowValue(lowValue) .setHighValue(highValue) .setDistinctValuesCount(distinctValuesCount) .build(); } }
/** * Create new {@link Weights} given {@code weights} as {@code double}. * * @param weights must not be {@literal null}. * @return the {@link Weights} for {@code weights}. */ public static Weights of(double... weights) { Assert.notNull(weights, "Weights must not be null!"); return new Weights(DoubleStream.of(weights).boxed().collect(Collectors.toList())); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static DoubleStream stream(OptionalDouble optional) { return optional.isPresent() ? DoubleStream.of(optional.getAsDouble()) : DoubleStream.empty(); }
public static double min(double... values) { return DoubleStream.of(values) .min() .getAsDouble(); }
public static double max(double... values) { return DoubleStream.of(values) .max() .getAsDouble(); }
int[] intArray = (int[]) o; return Arrays.stream(intArray) .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("int"), element)) .collect(Collectors.toList()); .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("bigint"), element)) .collect(Collectors.toList()); return IntStream.range(0, floatArray.length) .mapToDouble(i -> floatArray[i]) .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("float"), (float) element)) .collect(Collectors.toList()); .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("double"), element)) .collect(Collectors.toList());
private AttributeDataset dataset(NumericColumn<?> responseCol, AttributeType type, List<Column<?>> variableCols) { List<Column<?>> convertedVariableCols = variableCols.stream() .map(col -> col.type() == ColumnType.STRING ? col : table.nCol(col.name())) .collect(Collectors.toList()); Attribute responseAttribute = type == AttributeType.NOMINAL ? colAsNominalAttribute(responseCol) : new NumericAttribute(responseCol.name()); AttributeDataset dataset = new AttributeDataset(table.name(), convertedVariableCols.stream().map(col -> colAsAttribute(col)).toArray(Attribute[]::new), responseAttribute); for (int i = 0; i < responseCol.size(); i++) { final int r = i; double[] x = IntStream.range(0, convertedVariableCols.size()) .mapToDouble(c -> getDouble(convertedVariableCols.get(c), dataset.attributes()[c], r)) .toArray(); dataset.add(x, responseCol.getDouble(r)); } return dataset; }
IntStream.range(0, ensembleSize).mapToObj( modelIdx -> getMapping( featuresVectorSize, featureSubspaceDim, environment.randomNumbersGenerator().nextLong())) .collect(Collectors.toList()) : null; List<DatasetTrainer<IgniteModel<Vector, Double>, L>> subspaceTrainers = IntStream.range(0, ensembleSize) .mapToObj(mdlIdx -> { AdaptableDatasetTrainer<Vector, Double, Vector, Double, ? extends IgniteModel, L> tr = .withEnvironmentBuilder(envBuilder); }) .map(CompositionUtils::unsafeCoerce) .collect(Collectors.toList()); subspaceTrainers)).afterTrainedModel(l -> aggregator.apply(l.stream().mapToDouble(Double::valueOf).toArray()));
.map( v -> materializeAnyResult( proxySpi, v ) ).collect( Collectors.toList() ) ) ); .mapToObj( id -> (AnyValue) ValueUtils.fromNodeProxy( proxySpi.newNodeProxy( id ) ) ) .collect( Collectors.toList() ) ); .mapToObj( id -> (AnyValue) ValueUtils.fromRelationshipProxy( proxySpi.newRelationshipProxy( id ) ) ) .collect( Collectors.toList() ) ); long[] array = ((LongStream) anyValue).toArray(); return Values.longArray( array ); double[] array = ((DoubleStream) anyValue).toArray(); return Values.doubleArray( array ); return VirtualValues.fromList( ((IntStream) anyValue).mapToObj( i -> Values.booleanValue( i != 0 ) ).collect( Collectors.toList() ) );
private static ChartData createLineChartData(Collection<Measurement> measurements, Collection<String> titles, Collection<Color> colors) { int maxLength = measurements.stream().mapToInt(Measurement::getLength).reduce(0, Math::max); int spanCount = min(CHART_MAX_SPAN_COUNT, maxLength); double step = (double) maxLength / spanCount; Collection<String> categories = DoubleStream.iterate(0.0D, v -> v + step).limit(spanCount + 1) .mapToObj(v -> Integer.toString((int) Math.round(v))).collect(toList()); Iterator<String> titleIterator = titles.iterator(); Iterator<Color> colorIterator = colors.iterator(); Collection<Series> series = measurements.stream() .map(it -> new Series(titleIterator.next(), colorIterator.next(), it.getDelays())).collect(toList()); return new ChartData(categories, series); }
/** * Create new {@link Weights} given {@code weights} as {@code int}. * * @param weights must not be {@literal null}. * @return the {@link Weights} for {@code weights}. */ public static Weights of(int... weights) { Assert.notNull(weights, "Weights must not be null!"); return new Weights(Arrays.stream(weights).mapToDouble(value -> value).boxed().collect(Collectors.toList())); }
StageStats stageStats = stageInfo.get().getStageStats(); double avgPositionsPerTask = stageInfo.get().getTasks().stream().mapToLong(task -> task.getStats().getProcessedInputPositions()).average().orElse(Double.NaN); double squaredDifferences = stageInfo.get().getTasks().stream().mapToDouble(task -> Math.pow(task.getStats().getProcessedInputPositions() - avgPositionsPerTask, 2)).sum(); double sdAmongTasks = Math.sqrt(squaredDifferences / stageInfo.get().getTasks().size()); .map(argument -> { if (argument.isConstant()) { NullableValue constant = argument.getConstant();
static String createSnippetFromObservations(Object o) { String snippet = "new " + o.getClass().getSimpleName() + "{ "; if (o instanceof int[]) { snippet += Arrays.stream((int[]) o).mapToObj(v -> v).map(Object::toString).collect(Collectors.joining(",")); } else if (o instanceof double[]) { snippet += Arrays.stream((double[]) o).mapToObj(v -> v).map(Object::toString).collect(Collectors.joining(",")); } else if (o instanceof long[]) { snippet += Arrays.stream((long[]) o).mapToObj(v -> v).map(Object::toString).collect(Collectors.joining(",")); } return snippet + "}"; }
private int getNewTaskCount() { if (scheduledNodes.isEmpty()) { return 1; } double fullTasks = sourceTasksProvider.get().stream() .filter(task -> !task.getState().isDone()) .map(TaskStatus::isOutputBufferOverutilized) .mapToDouble(full -> full ? 1.0 : 0.0) .average().orElse(0.0); long writtenBytes = writerTasksProvider.get().stream() .map(TaskStatus::getPhysicalWrittenDataSize) .mapToLong(DataSize::toBytes) .sum(); if ((fullTasks >= 0.5) && (writtenBytes >= (writerMinSizeBytes * scheduledNodes.size()))) { return 1; } return 0; }
@Override public Object calculate(List<?> data) { if (data.stream().anyMatch(Predicates.instanceOf(Double.class))) { return data.stream().map(info -> info == null ? 0.0d : info).filter(Predicates.instanceOf(Double.class)).mapToDouble(Double.class::cast).average().orElse(0.0); } if (data.stream().anyMatch(Predicates.instanceOf(Integer.class))) { return data.stream().map(info -> info == null ? 0 : info).filter(Predicates.instanceOf(Integer.class)).mapToInt(Integer.class::cast).average().orElse(0); } if (data.stream().anyMatch(Predicates.instanceOf(Long.class))) { return data.stream().map(info -> info == null ? 0L : info).filter(Predicates.instanceOf(Long.class)).mapToLong(Long.class::cast).average().orElse(0L); } return 0; } },
@VisibleForTesting static double calculateNullsFractionForPartitioningKey( HiveColumnHandle column, List<HivePartition> partitions, Map<String, PartitionStatistics> statistics, double averageRowsPerPartition, double rowCount) { if (rowCount == 0) { return 0; } double estimatedNullsCount = partitions.stream() .filter(partition -> partition.getKeys().get(column).isNull()) .map(HivePartition::getPartitionId) .mapToDouble(partitionName -> getPartitionRowCount(partitionName, statistics).orElse(averageRowsPerPartition)) .sum(); return normalizeFraction(estimatedNullsCount / rowCount); }
private List<Comparable> primitiveArrayToList(FieldSpec.DataType dataType, Object sortedValues) { List<Comparable> valueList; switch (dataType) { case INT: valueList = Arrays.stream((int[]) sortedValues).boxed().collect(Collectors.toList()); break; case LONG: valueList = Arrays.stream((long[]) sortedValues).boxed().collect(Collectors.toList()); break; case FLOAT: // Stream not available for float. valueList = new ArrayList<>(); for (float value : ((float[]) sortedValues)) { valueList.add(value); } break; case DOUBLE: valueList = Arrays.stream((double[]) sortedValues).boxed().collect(Collectors.toList()); break; default: throw new IllegalArgumentException("Illegal data type for mutable dictionary: " + dataType); } return valueList; } }