/** * Update the feature value of this field. */ public void setFeatureValue(float featureValue) { if (Float.isFinite(featureValue) == false) { throw new IllegalArgumentException("featureValue must be finite, got: " + featureValue + " for feature " + fieldsData + " on field " + name); } if (featureValue < Float.MIN_NORMAL) { throw new IllegalArgumentException("featureValue must be a positive normal float, got: " + featureValue + "for feature " + fieldsData + " on field " + name + " which is less than the minimum positive normal float: " + Float.MIN_NORMAL); } this.featureValue = featureValue; }
/** * BM25 with the supplied parameter values. * @param k1 Controls non-linear term frequency normalization (saturation). * @param b Controls to what degree document length normalizes tf values. * @throws IllegalArgumentException if {@code k1} is infinite or negative, or if {@code b} is * not within the range {@code [0..1]} */ public BM25Similarity(float k1, float b) { if (Float.isFinite(k1) == false || k1 < 0) { throw new IllegalArgumentException("illegal k1 value: " + k1 + ", must be a non-negative finite value"); } if (Float.isNaN(b) || b < 0 || b > 1) { throw new IllegalArgumentException("illegal b value: " + b + ", must be between 0 and 1"); } this.k1 = k1; this.b = b; }
/** * Constructor setting all Axiomatic hyperparameters * @param s hyperparam for the growth function * @param queryLen the query length * @param k hyperparam for the primitive weighting function */ public Axiomatic(float s, int queryLen, float k) { if (Float.isFinite(s) == false || Float.isNaN(s) || s < 0 || s > 1) { throw new IllegalArgumentException("illegal s value: " + s + ", must be between 0 and 1"); } if (Float.isFinite(k) == false || Float.isNaN(k) || k < 0 || k > 1) { throw new IllegalArgumentException("illegal k value: " + k + ", must be between 0 and 1"); } if (queryLen < 0 || queryLen > Integer.MAX_VALUE) { throw new IllegalArgumentException("illegal query length value: " + queryLen + ", must be larger 0 and smaller than MAX_INT"); } this.s = s; this.queryLen = queryLen; this.k = k; }
Params withRequestsPerSecond(float requestsPerSecond) { // the default in AbstractBulkByScrollRequest is Float.POSITIVE_INFINITY, // but we don't want to add that to the URL parameters, instead we use -1 if (Float.isFinite(requestsPerSecond)) { return putParam("requests_per_second", Float.toString(requestsPerSecond)); } else { return putParam("requests_per_second", "-1"); } }
/** * Return a new {@link Query} that will score documents as * {@code weight * S^a / (S^a + pivot^a)} where S is the value of the static feature. * @param fieldName field that stores features * @param featureName name of the feature * @param weight weight to give to this feature, must be in (0,64] * @param pivot feature value that would give a score contribution equal to weight/2, must be in (0, +Infinity) * @param exp exponent, higher values make the function grow slower before 'pivot' and faster after 'pivot', must be in (0, +Infinity) * @throws IllegalArgumentException if w is not in (0,64] or either k or a are not in (0, +Infinity) */ public static Query newSigmoidQuery(String fieldName, String featureName, float weight, float pivot, float exp) { if (weight <= 0 || weight > MAX_WEIGHT) { throw new IllegalArgumentException("weight must be in (0, " + MAX_WEIGHT + "], got: " + weight); } if (pivot <= 0 || Float.isFinite(pivot) == false) { throw new IllegalArgumentException("pivot must be > 0, got: " + pivot); } if (exp <= 0 || Float.isFinite(exp) == false) { throw new IllegalArgumentException("exp must be > 0, got: " + exp); } Query q = new FeatureQuery(fieldName, featureName, new SigmoidFunction(pivot, exp)); if (weight != 1f) { q = new BoostQuery(q, weight); } return q; }
private static Query newSaturationQuery(String fieldName, String featureName, float weight, Float pivot) { if (weight <= 0 || weight > MAX_WEIGHT) { throw new IllegalArgumentException("weight must be in (0, " + MAX_WEIGHT + "], got: " + weight); } if (pivot != null && (pivot <= 0 || Float.isFinite(pivot) == false)) { throw new IllegalArgumentException("pivot must be > 0, got: " + pivot); } Query q = new FeatureQuery(fieldName, featureName, new SaturationFunction(fieldName, featureName, pivot)); if (weight != 1f) { q = new BoostQuery(q, weight); } return q; }
/** * Return a new {@link Query} that will score documents as * {@code weight * Math.log(scalingFactor + S)} where S is the value of the static feature. * @param fieldName field that stores features * @param featureName name of the feature * @param weight weight to give to this feature, must be in (0,64] * @param scalingFactor scaling factor applied before taking the logarithm, must be in [1, +Infinity) * @throws IllegalArgumentException if weight is not in (0,64] or scalingFactor is not in [1, +Infinity) */ public static Query newLogQuery(String fieldName, String featureName, float weight, float scalingFactor) { if (weight <= 0 || weight > MAX_WEIGHT) { throw new IllegalArgumentException("weight must be in (0, " + MAX_WEIGHT + "], got: " + weight); } if (scalingFactor < 1 || Float.isFinite(scalingFactor) == false) { throw new IllegalArgumentException("scalingFactor must be >= 1, got: " + scalingFactor); } Query q = new FeatureQuery(fieldName, featureName, new LogFunction(scalingFactor)); if (weight != 1f) { q = new BoostQuery(q, weight); } return q; }
private void testNonTrivialAggregation(Float[] y, Float[] x) { SimpleRegression regression = new SimpleRegression(); for (int i = 0; i < x.length; i++) { regression.addData(x[i], y[i]); } float expected = (float) regression.getIntercept(); checkArgument(Float.isFinite(expected) && expected != 0.f, "Expected result is trivial"); testAggregation(expected, createBlockOfReals(y), createBlockOfReals(x)); } }
private void testNonTrivialAggregation(Float[] y, Float[] x) { SimpleRegression regression = new SimpleRegression(); for (int i = 0; i < x.length; i++) { regression.addData(x[i], y[i]); } float expected = (float) regression.getSlope(); checkArgument(Float.isFinite(expected) && expected != 0.0f, "Expected result is trivial"); testAggregation(expected, createBlockOfReals(y), createBlockOfReals(x)); } }
private void validateParsed(float value) { if (!Float.isFinite(value)) { throw new IllegalArgumentException("[float] supports only finite values, but got [" + value + "]"); } } },
/** * @param a input float array * @return true if array includes at least one Not-a-Number (NaN) or infinite value, false * otherwise */ public static boolean containsNanOrInfinite(float[] a) { for (float v : a) { if (Float.isNaN(v) || !Float.isFinite(v)) { return true; } } return false; }
/** * Converts to an integer array. if values are outside of the given boundaries, throws Exception. */ public static int[] toInteger(float[] input, int min, int max) { validateArray(input); int[] result = new int[input.length]; int i = 0; for (float v : input) { if (!Float.isFinite(v) || Float.isNaN(v)) { throw new IllegalStateException("Value" + v + " cannot be converted."); } if (v < min || v > max) { throw new IllegalStateException("Value" + v + "is outside of min-max boundaries."); } result[i] = (int) v; i++; } return result; }
private void validateParsed(float value) { if (!Float.isFinite(HalfFloatPoint.sortableShortToHalfFloat(HalfFloatPoint.halfFloatToSortableShort(value)))) { throw new IllegalArgumentException("[half_float] supports only finite values, but got [" + value + "]"); } } },
@Override public boolean fitsInDouble(Object receiver) { float originalReceiver = (float) receiver; double castValue = originalReceiver; return !Float.isFinite(originalReceiver) || castValue == originalReceiver; }
@Override public boolean fitsInDouble(Object receiver) { float originalReceiver = (float) receiver; double castValue = originalReceiver; return !Float.isFinite(originalReceiver) || castValue == originalReceiver; }
private void validateParsed(float value) { if (!Float.isFinite(value)) { throw new IllegalArgumentException("[float] supports only finite values, but got [" + value + "]"); } } },
static private void constTest() { System.out.println("Float.isInfinite(Float.POSITIVE_INFINITY): " + Float.isInfinite(Float.POSITIVE_INFINITY)); System.out.println("Float.isInfinite(Float.NEGATIVE_INFINITY): " + Float.isInfinite(Float.NEGATIVE_INFINITY)); System.out.println("Float.isInfinite(Float.NaN): " + Float.isInfinite(Float.NaN)); System.out.println("Float.isFinite(Float.POSITIVE_INFINITY): " + Float.isFinite(Float.POSITIVE_INFINITY)); System.out.println("Float.isFinite(Float.NEGATIVE_INFINITY): " + Float.isFinite(Float.NEGATIVE_INFINITY)); System.out.println("Float.isFinite(Float.NaN): " + Float.isFinite(Float.NaN)); System.out.println("Float.isNaN(Float.POSITIVE_INFINITY): " + Float.isNaN(Float.POSITIVE_INFINITY)); System.out.println("Float.isNaN(Float.NEGATIVE_INFINITY): " + Float.isNaN(Float.NEGATIVE_INFINITY)); System.out.println("Float.isNaN(Float.NaN): " + Float.isNaN(Float.NaN)); }
Params withRequestsPerSecond(float requestsPerSecond) { // the default in AbstractBulkByScrollRequest is Float.POSITIVE_INFINITY, // but we don't want to add that to the URL parameters, instead we use -1 if (Float.isFinite(requestsPerSecond)) { return putParam(RethrottleRequest.REQUEST_PER_SECOND_PARAMETER, Float.toString(requestsPerSecond)); } else { return putParam(RethrottleRequest.REQUEST_PER_SECOND_PARAMETER, "-1"); } }
private void testNonTrivialAggregation(Float[] y, Float[] x) { SimpleRegression regression = new SimpleRegression(); for (int i = 0; i < x.length; i++) { regression.addData(x[i], y[i]); } float expected = (float) regression.getIntercept(); checkArgument(Float.isFinite(expected) && expected != 0.f, "Expected result is trivial"); testAggregation(expected, createBlockOfReals(y), createBlockOfReals(x)); } }
private void testNonTrivialAggregation(Float[] y, Float[] x) { SimpleRegression regression = new SimpleRegression(); for (int i = 0; i < x.length; i++) { regression.addData(x[i], y[i]); } float expected = (float) regression.getSlope(); checkArgument(Float.isFinite(expected) && expected != 0.0f, "Expected result is trivial"); testAggregation(expected, createBlockOfReals(y), createBlockOfReals(x)); } }