public double getCost(V value) { return costFunction.applyAsDouble(value); }
public static <T extends MatchedExpression> T getBestMatched(List<T> matches, ToDoubleFunction<MatchedExpression> scorer) { if (matches == null || matches.isEmpty()) return null; T best = null; double bestScore = Double.NEGATIVE_INFINITY; for (T m : matches) { double s = scorer.applyAsDouble(m); if (best == null || s > bestScore) { best = m; bestScore = s; } } return best; }
@Override public double applyAsDouble(T object) throws NullPointerException { final A intermediate = before.apply(object); return after.applyAsDouble(intermediate); }
@Override public Double apply(T object) { final A intermediate = before.apply(object); if (intermediate == null) return null; return after.applyAsDouble(intermediate); } }
public long recommend( ToDoubleFunction<Bracket> parameter ) { double factor = differenceFactor(); double lowerParam = parameter.applyAsDouble( lower ); double upperParam = parameter.applyAsDouble( upper ); double diff = upperParam - lowerParam; double recommend = lowerParam + (diff * factor); return mebiBytes( (long) (recommend * 1024.0) ); } }
/** * This computes the average over all folds of the function we're trying to optimize. * The input triple contains, in order, the train set, the test set, and the saved state. * You don't have to use the saved state if you don't want to. */ public double computeAverage (ToDoubleFunction<Triple<GeneralDataset<L, F>,GeneralDataset<L, F>,SavedState>> function) { double sum = 0; Iterator<Triple<GeneralDataset<L, F>,GeneralDataset<L, F>,SavedState>> foldIt = iterator(); while (foldIt.hasNext()) { sum += function.applyAsDouble(foldIt.next()); } return sum / kFold; }
@Override public double applyAsDouble(ENTITY object) throws NullPointerException { return mapper.applyAsDouble(field.get(object)); } }
@Override public Double apply(ENTITY entity) { final V value = field.get(entity); if (value == null) return null; else return mapper.applyAsDouble(value); }
@Override public double applyAsDouble(T object) throws NullPointerException { return mapper.applyAsDouble(delegate.apply(object)); }
@Override public double applyAsDouble(T object) { return this.mapper.applyAsDouble(this.inner.apply(object)); }
/** * Uses Neumaier's variant of the Kahan summation algorithm in order to sum double values. * <p> * See <a href="https://en.wikipedia.org/wiki/Kahan_summation_algorithm">Kahan summation algorithm</a>. * * @param <T> element type * @param ts the elements * @param toDouble function which maps elements to {@code double} values * @return A pair {@code [sum, size]}, where {@code sum} is the compensated sum and {@code size} is the number of elements which were summed. */ static <T> double[] neumaierSum(Iterable<T> ts, ToDoubleFunction<T> toDouble) { double simpleSum = 0.0; double sum = 0.0; double compensation = 0.0; int size = 0; for (T t : ts) { final double d = toDouble.applyAsDouble(t); final double tmp = sum + d; compensation += (Math.abs(sum) >= Math.abs(d)) ? (sum - tmp) + d : (d - tmp) + sum; sum = tmp; simpleSum += d; size++; } sum += compensation; if (size > 0 && Double.isNaN(sum) && Double.isInfinite(simpleSum)) { sum = simpleSum; } return new double[] { sum, size }; } }
@Override public Comparator<ENTITY> thenComparingDouble(ToDoubleFunction<? super ENTITY> keyExtractor) { if (keyExtractor instanceof Getter) { @SuppressWarnings("unchecked") final Getter<ENTITY> getter = (Getter<ENTITY>) keyExtractor; final Optional<Comparator<ENTITY>> result = then(getter); if (result.isPresent()) { return result.get(); } } return (a, b) -> { final int c = compare(a, b); if (c == 0) { final double oa = keyExtractor.applyAsDouble(a); final double ob = keyExtractor.applyAsDouble(b); return Double.compare(oa, ob); } else return c; }; }
@Override public Double apply(T object) { return delegate.isNull(object) ? null : mapper.applyAsDouble(delegate.apply(object)); }
@Override public ToDouble<T> orElse(Double value) { return object -> delegate.isNull(object) ? value : mapper.applyAsDouble(delegate.apply(object)); }
E mEnd = itemInterval.getEnd(); PartialScoredList<T,E> bestk = bestNonOverlapping.get(mEnd); double itemScore = scoreFunc.applyAsDouble(item); if (bestk == null) { bestk = new PartialScoredList<>();
@Override public boolean next(DoublePredicate consumer) { return source.next(e -> consumer.test(mapper.applyAsDouble(e))); }
@Override public void accept(String key, float[] value) { if (allowedPredicate.test(key)) { double score = rescoreFn.applyAsDouble(key, scoreFn.applyAsDouble(value)); // Only proceed if score can possibly exceed (cached) minimum score in the queue. if (score > topScoreLowerBound) { // If full, if (topN.size() >= howMany) { // Must double-check against next value because new one may still not be bigger if (score > (topScoreLowerBound = topN.peek().getSecond())) { // Swap in new, larger value for old smallest one topN.poll(); topN.add(new Pair<>(key, score)); } } else { topN.add(new Pair<>(key, score)); } } } }
@Override public ToDouble<T> orElseGet(ToDouble<T> getter) { return object -> delegate.isNull(object) ? getter.applyAsDouble(object) : mapper.applyAsDouble(delegate.apply(object)); }
/** * Maps the function across all rows, appending the results to a new NumberColumn * * @param fun function to map * @return the NumberColumn with the results */ public DoubleColumn map(ToDoubleFunction<Double> fun) { DoubleColumn result = DoubleColumn.create(name()); for (double t : this) { try { result.append(fun.applyAsDouble(t)); } catch (Exception e) { result.appendMissing(); } } return result; }
public final void compute() { final ToDoubleFunction<Map.Entry<K,V>> transformer; final DoubleBinaryOperator reducer; if ((transformer = this.transformer) != null && (reducer = this.reducer) != null) { double r = this.basis; for (int i = baseIndex, f, h; batch > 0 && (h = ((f = baseLimit) + i) >>> 1) > i;) { addToPendingCount(1); (rights = new MapReduceEntriesToDoubleTask<K,V> (this, batch >>>= 1, baseLimit = h, f, tab, rights, transformer, r, reducer)).fork(); } for (Node<K,V> p; (p = advance()) != null; ) r = reducer.applyAsDouble(r, transformer.applyAsDouble(p)); result = r; CountedCompleter<?> c; for (c = firstComplete(); c != null; c = c.nextComplete()) { @SuppressWarnings("unchecked") MapReduceEntriesToDoubleTask<K,V> t = (MapReduceEntriesToDoubleTask<K,V>)c, s = t.rights; while (s != null) { t.result = reducer.applyAsDouble(t.result, s.result); s = t.rights = s.nextRight; } } } } }