Refine search
@SuppressWarnings( "unchecked" ) public static DoubleStream toDoubleStream( Object list ) { if ( list == null ) { return DoubleStream.empty(); } else if ( list instanceof SequenceValue ) { throw new IllegalArgumentException( "Need to implement support for SequenceValue in CompiledConversionUtils.toDoubleStream" ); } else if ( list instanceof List ) { return ((List) list).stream().mapToDouble( n -> ((Number) n).doubleValue() ); } else if ( Object[].class.isAssignableFrom( list.getClass() ) ) { return Arrays.stream( (Object[]) list ).mapToDouble( n -> ((Number) n).doubleValue() ); } else if ( list instanceof float[] ) { float[] array = (float[]) list; return IntStream.range( 0, array.length ).mapToDouble( i -> array[i] ); } else if ( list instanceof double[] ) { return DoubleStream.of( (double[]) list ); } throw new IllegalArgumentException( format( "Can not be converted to stream: %s", list.getClass().getName() ) ); }
/** * Creates equal {@link Weights} for a number of input sets {@code count} with a weight of one. * * @param count number of input sets. Must be greater or equal to zero. * @return equal {@link Weights} for a number of input sets with a weight of one. */ public static Weights fromSetCount(int count) { Assert.isTrue(count >= 0, "Count of input sorted sets must be greater or equal to zero!"); return new Weights(IntStream.range(0, count).mapToDouble(value -> 1).boxed().collect(Collectors.toList())); }
public static double[] simpleMovingAverage(double[] values, int n) { double[] sums = Arrays.copyOf(values, values.length); // <1> Arrays.parallelPrefix(sums, Double::sum); // <2> int start = n - 1; return IntStream.range(start, sums.length) // <3> .mapToDouble(i -> { double prefix = i == start ? 0 : sums[i - n]; return (sums[i] - prefix) / n; // <4> }) .toArray(); // <5> } // END simpleMovingAverage
/** * Create {@link VectorGenerator} with vectors having feature values generated by random producer. * * @param vectorSize Generated vector size. * @return Vector generator. */ public default VectorGenerator vectorize(int vectorSize) { return () -> VectorUtils.of(IntStream.range(0, vectorSize).mapToDouble(x -> get()).toArray()); }
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; }
return IntStream.range(0, floatArray.length) .mapToDouble(i -> floatArray[i]) .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("float"), (float) element)) .collect(Collectors.toList()); return IntStream.range(0, booleanArray.length) .map(i -> booleanArray[i] ? 1 : 0) .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("boolean"), element == 1))
return IntStream.range(0, floatArray.length) .mapToDouble(i -> floatArray[i]) .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("float"), (float) element, hiveFieldNames)) .collect(Collectors.toList()); return IntStream.range(0, booleanArray.length) .map(i -> booleanArray[i] ? 1 : 0) .mapToObj((element) -> convertToORCObject(TypeInfoFactory.getPrimitiveTypeInfo("boolean"), element == 1, hiveFieldNames))
public static double clock(final int loops, final Runnable runnable) { runnable.run(); // warm-up return IntStream.range(0, loops).mapToDouble(i -> { long t = System.nanoTime(); runnable.run(); return (System.nanoTime() - t) * 0.000001; }).sum() / loops; }
public static <S> Pair<Double, S> clockWithResult(final int loops, final Supplier<S> supplier) { final S result = supplier.get(); // warm up return Pair.with(IntStream.range(0, loops).mapToDouble(i -> { long t = System.nanoTime(); supplier.get(); return (System.nanoTime() - t) * 0.000001; }).sum() / loops, result); } }
/** * Scan double stream. * * @return the double stream */ public DoubleStream scan() { return IntStream.range(-1000, 1000).mapToDouble(x -> x / 300.0); }
/** * Dot double. * * @param a the a * @param b the b * @return the double */ public static double dot(double[] a, double[] b) { return IntStream.range(0, a.length).mapToDouble(i -> a[i] * b[i]).sum(); }
/** * Dot double. * * @param a the a * @param b the b * @return the double */ public static double dot(double[] a, double[] b) { return IntStream.range(0, a.length).mapToDouble(i -> a[i] * b[i]).sum(); }
public static double clock(final int loops, final Runnable runnable) { runnable.run(); // warm-up return IntStream.range(0, loops).mapToDouble(i -> { long t = System.nanoTime(); runnable.run(); return (System.nanoTime() - t) * 0.000001; }).sum() / loops; }
private double[] reweight(final double[] x, final double[] weight, final double correctionD) { return IntStream.range(0, x.length) .mapToDouble(i -> weight[i] + model.learningRate * correctionD * x[i]) // Main Part, +1 strategy .toArray(); }
protected String getASRangeString(double[] damage) { return IntStream.range(0, damage.length).mapToDouble(i -> damage[i] / 10.0) .mapToObj(d -> { if (d > 0.5) { return Integer.toString((int)Math.round(d)); } else if (d > 0) { return "0*"; } else { return "0"; } }).collect(Collectors.joining("/")); }
/** * Returns a sequential stream of the alleles with this chromosome as its * source. * * @since 4.3 * * @return a sequential stream of alleles */ public DoubleStream doubleStream() { return IntStream.range(0, length()).mapToDouble(this::doubleValue); }
public double[] toArray() { return IntStream.range(0, capacity) .mapToDouble(this::get) .toArray(); } }
public static <S> Pair<Double, S> clockWithResult(final int loops, final Supplier<S> supplier) { final S result = supplier.get(); // warm up return Pair.with(IntStream.range(0, loops).mapToDouble(i -> { long t = System.nanoTime(); supplier.get(); return (System.nanoTime() - t) * 0.000001; }).sum() / loops, result); } }
/** * Add double [ ]. * * @param a the a * @param b the b * @return the double [ ] */ public static double[] add(double[] a, double[] b) { return IntStream.range(0, a.length).mapToDouble(i -> a[i] + b[i]).toArray(); }
/** * Dot double. * * @param a the a * @param b the b * @return the double */ public static double dot(@Nonnull final List<DoubleBuffer<UUID>> a, @Nonnull final List<DoubleBuffer<UUID>> b) { assert a.size() == b.size(); return IntStream.range(0, a.size()).mapToDouble(i -> a.get(i).dot(b.get(i))).sum(); }