List of usage examples for java.lang Double NEGATIVE_INFINITY
double NEGATIVE_INFINITY
To view the source code for java.lang Double NEGATIVE_INFINITY.
Click Source Link
From source file:bachelorthesis.methods.detection.bayesian.BayesianDetection.java
private double[][] offlineCpd(Value[] data) { int n = data.length; double[] Q = new double[n]; double[] g = new double[n]; double[] G = new double[n]; double[][] P = new double[n][n]; Arrays.fill(g, Math.log(1.d / (data.length + 1))); G[0] = g[0];// w ww .ja v a 2s. c o m for (int i = 1; i < G.length; i++) { G[i] = Math.log((Math.exp(G[i - 1]) + Math.exp(g[i]))); } for (double[] array : P) { Arrays.fill(array, Double.NEGATIVE_INFINITY); } P[n - 1][n - 1] = gaussianObsLogLikelihood(data, n - 1, n); Q[n - 1] = P[n - 1][n - 1]; for (int t = n - 2; t >= 0; t--) { double p_next_cp = Double.NEGATIVE_INFINITY; for (int s = t; s < n - 1; s++) { P[t][s] = gaussianObsLogLikelihood(data, t, s + 1); double summand = P[t][s] + Q[s + 1] + g[s + 1 - t]; p_next_cp = Math.log((Math.exp(p_next_cp) + Math.exp(summand))); if (summand - p_next_cp < BAYESIAN_TRUNCATE) { break; } } P[t][n - 1] = gaussianObsLogLikelihood(data, t, n); double antiG; if (G[n - 1 - t] < -1e-15) { antiG = Math.log(1.d - Math.exp(G[n - 1 - t])); } else { antiG = Math.log(-G[n - 1 - t]); } Q[t] = Math.log((Math.exp(p_next_cp) + Math.exp(P[t][n - 1] + antiG))); } double[][] Pcp = new double[n - 1][n - 1]; for (double[] array : Pcp) { Arrays.fill(array, Double.NEGATIVE_INFINITY); } for (int t = 0; t < n - 1; t++) { Pcp[0][t] = P[0][t] + Q[t + 1] + g[t] - Q[0]; if (Double.isNaN(Pcp[0][t])) { Pcp[0][t] = Double.NEGATIVE_INFINITY; } } for (int j = 1; j < n - 1; j++) { for (int t = j; t < n - 1; t++) { double[] tmp_cond = copyOfRange(Pcp[j - 1], j - 1, t); tmp_cond = add(tmp_cond, getSameEntryOfAllArrays(copyOfRange(P, j, t + 1), t)); double summand = Q[t + 1]; tmp_cond = forEach(tmp_cond, value -> value + summand); tmp_cond = add(tmp_cond, copyOfRange(g, 0, t - j + 1)); double[] negativePart = forEach(copyOfRange(Q, j, t + 1), value -> -value); tmp_cond = add(tmp_cond, negativePart); double[] tempArray = forEach(tmp_cond, value -> Math.exp(value)); Pcp[j][t] = Math.log(sum(tempArray)); if (Double.isNaN(Pcp[j][t])) { Pcp[j][t] = Double.NEGATIVE_INFINITY; } } } return Pcp; }
From source file:com.clust4j.algo.KDTree.java
@Override void initNode(NearestNeighborHeapSearch tree, int i_node, int idx_start, int idx_end) { int n_features = tree.N_FEATURES, i, j; double rad = 0; double[] lowerBounds = tree.node_bounds[0][i_node]; double[] upperBounds = tree.node_bounds[1][i_node]; double[][] data = tree.data_arr; int[] idx_array = tree.idx_array; double[] data_row; // Get node bounds for (j = 0; j < n_features; j++) { lowerBounds[j] = Double.POSITIVE_INFINITY; upperBounds[j] = Double.NEGATIVE_INFINITY; }/*from w w w . jav a 2s . c o m*/ // Compute data range for (i = idx_start; i < idx_end; i++) { data_row = data[idx_array[i]]; for (j = 0; j < n_features; j++) { lowerBounds[j] = FastMath.min(lowerBounds[j], data_row[j]); upperBounds[j] = FastMath.max(upperBounds[j], data_row[j]); } // The python code does not increment up to the range boundary, // the java for loop does. So we must decrement j by one. j--; if (tree.infinity_dist) rad = FastMath.max(rad, 0.5 * (upperBounds[j] - lowerBounds[j])); else rad += FastMath.pow(0.5 * FastMath.abs(upperBounds[j] - lowerBounds[j]), tree.dist_metric.getP()); } tree.node_data[i_node].idx_start = idx_start; tree.node_data[i_node].idx_end = idx_end; // radius assignment tree.node_data[i_node].radius = Math.pow(rad, 1.0 / tree.dist_metric.getP()); }
From source file:de.tudarmstadt.lt.lm.mapbased.CountingLM.java
public double getNgramLogProbabilityFromIds(List<Integer> ngram) { // check length assert ngram//from w ww . jav a 2 s . c o m .size() <= _order : "Length of Ngram must be lower or equal to the order of the language model."; if (ngram.size() < 1) return Double.NEGATIVE_INFINITY; // c(w_1 ... w_n) Integer nominator = _ngrams_of_order.getQuantity(ngram); if (nominator == 0) return Double.NEGATIVE_INFINITY; // c(w_1) / N if (ngram.size() == 1) return Math.log10(nominator) - Math.log10(_sum_one_grams); // c(w_1 ... w_n-1) Integer denominator = _ngrams_of_lower_order.getQuantity(ngram.subList(0, ngram.size() - 1)); if (denominator == 0) return Double.NEGATIVE_INFINITY; double logprob = Math.log10(nominator) - Math.log10(denominator); return logprob; }
From source file:com.google.blockly.model.FieldNumber.java
/** * Sets the constraints on valid number values. * <p/>/*from w ww . j av a 2 s . c om*/ * Changing the constraints may trigger a {@link ChangeEvent}, even if the value does not * change. * * @param min The minimum allowed value, inclusive. * @param max The maximum allowed value, inclusive. * @param precision The precision of allowed values. Valid values are multiples of this number, * such as 1, 0.1, 100, or 0.125. */ public void setConstraints(double min, double max, double precision) { if (max == Double.POSITIVE_INFINITY || Double.isNaN(max)) { max = NO_CONSTRAINT; } else if (max == Double.NEGATIVE_INFINITY) { throw new IllegalArgumentException("Max cannot be -Inf. No valid values would exist."); } if (min == Double.NEGATIVE_INFINITY || Double.isNaN(min)) { min = NO_CONSTRAINT; } else if (min == Double.POSITIVE_INFINITY) { throw new IllegalArgumentException("Min cannot be Inf. No valid values would exist."); } if (precision == 0 || Double.isNaN(precision)) { precision = NO_CONSTRAINT; } if (Double.isInfinite(precision)) { throw new IllegalArgumentException("Precision cannot be infinite."); } if (!Double.isNaN(min) && !Double.isNaN(max) && min > max) { throw new IllegalArgumentException("Minimum value must be less than max. Found " + min + " > " + max); } if (!Double.isNaN(precision) && precision <= 0) { throw new IllegalArgumentException("Precision must be positive. Found " + precision); } double effectiveMin = Double.isNaN(min) ? -Double.MAX_VALUE : min; double effectiveMax = Double.isNaN(max) ? Double.MAX_VALUE : max; if (!Double.isNaN(precision)) { if (effectiveMin < 0) { double multiplier = Math.floor(-effectiveMin / precision); effectiveMin = precision * -multiplier; } else { double multiplier = Math.ceil(effectiveMin / precision); effectiveMin = precision * multiplier; } if (effectiveMax < 0) { double multiplier = Math.ceil(-effectiveMax / precision); effectiveMax = precision * -multiplier; } else { double multiplier = Math.floor(effectiveMax / precision); effectiveMax = precision * multiplier; } if (effectiveMin > effectiveMax) { throw new IllegalArgumentException("No valid value in range."); } } mMin = min; mMax = max; mPrecision = precision; mEffectiveMin = effectiveMin; mEffectiveMax = effectiveMax; mIntegerPrecision = (precision == Math.round(precision)); if (!hasPrecision()) { mFormatter = NAIVE_DECIMAL_FORMAT; } else if (mIntegerPrecision) { mFormatter = INTEGER_DECIMAL_FORMAT; } else { String precisionStr = NAIVE_DECIMAL_FORMAT.format(precision); int decimalChar = precisionStr.indexOf('.'); if (decimalChar == -1) { mFormatter = INTEGER_DECIMAL_FORMAT; } else { int significantDigits = precisionStr.length() - decimalChar; StringBuilder sb = new StringBuilder("0."); char[] sigDigitsFormat = new char[significantDigits]; Arrays.fill(sigDigitsFormat, '#'); sb.append(sigDigitsFormat); mFormatter = new DecimalFormat(sb.toString()); } } setValueImpl(mValue, true); }
From source file:org.jfree.data.statistics.DefaultMultiValueCategoryDataset.java
/** * Adds a list of values to the dataset (<code>null</code> and Double.NaN * items are automatically removed) and sends a {@link DatasetChangeEvent} * to all registered listeners.//w w w.j ava 2 s. c om * * @param values a list of values (<code>null</code> not permitted). * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). */ public void add(List values, Comparable rowKey, Comparable columnKey) { ParamChecks.nullNotPermitted(values, "values"); ParamChecks.nullNotPermitted(rowKey, "rowKey"); ParamChecks.nullNotPermitted(columnKey, "columnKey"); List vlist = new ArrayList(values.size()); Iterator iterator = values.listIterator(); while (iterator.hasNext()) { Object obj = iterator.next(); if (obj instanceof Number) { Number n = (Number) obj; double v = n.doubleValue(); if (!Double.isNaN(v)) { vlist.add(n); } } } Collections.sort(vlist); this.data.addObject(vlist, rowKey, columnKey); if (vlist.size() > 0) { double maxval = Double.NEGATIVE_INFINITY; double minval = Double.POSITIVE_INFINITY; for (int i = 0; i < vlist.size(); i++) { Number n = (Number) vlist.get(i); double v = n.doubleValue(); minval = Math.min(minval, v); maxval = Math.max(maxval, v); } // update the cached range values... if (this.maximumRangeValue == null) { this.maximumRangeValue = new Double(maxval); } else if (maxval > this.maximumRangeValue.doubleValue()) { this.maximumRangeValue = new Double(maxval); } if (this.minimumRangeValue == null) { this.minimumRangeValue = new Double(minval); } else if (minval < this.minimumRangeValue.doubleValue()) { this.minimumRangeValue = new Double(minval); } this.rangeBounds = new Range(this.minimumRangeValue.doubleValue(), this.maximumRangeValue.doubleValue()); } fireDatasetChanged(); }
From source file:com.rapidminer.operator.preprocessing.filter.InfiniteValueReplenishment.java
@Override public double getReplacedValue() { try {/*from www . jav a 2 s . c o m*/ int chosen = getParameterAsInt(PARAMETER_REPLENISHMENT_WHAT); if (chosen == 0) { return Double.POSITIVE_INFINITY; } } catch (Exception e) { } return Double.NEGATIVE_INFINITY; }
From source file:dr.inference.distribution.GammaDistributionModel.java
public double logPdf(double x) { if (x < offset) return Double.NEGATIVE_INFINITY; return GammaDistribution.logPdf(x - offset, getShape(), getScale()); }
From source file:dr.math.distributions.BetaDistribution.java
/** * the natural log of the probability density function of the distribution * * @param x argument//w w w .ja v a2 s . c o m * @return log pdf value */ public double logPdf(double x) { recomputeZ(); if (x < 0 || x > 1) { return Double.NEGATIVE_INFINITY; } else if (x == 0) { if (alpha < 1) { // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime // exceptions is bad. Better to return NaN and let the calling code deal with it. return Double.NaN; // throw MathRuntimeException.createIllegalArgumentException( // "Cannot compute beta density at 0 when alpha = {0,number}", alpha); } if (alpha == 1) { return 0; } return Double.NEGATIVE_INFINITY; } else if (x == 1) { if (beta < 1) { // AR - throwing exceptions deep in numerical code causes trouble. Catching runtime // exceptions is bad. Better to return NaN and let the calling code deal with it. return Double.NaN; // throw MathRuntimeException.createIllegalArgumentException( // "Cannot compute beta density at 1 when beta = %.3g", beta); } if (beta == 1) { return 0; } return Double.NEGATIVE_INFINITY; } else { double logX = Math.log(x); double log1mX = Math.log1p(-x); return (alpha - 1) * logX + (beta - 1) * log1mX - z; } }
From source file:com.rapidminer.operator.preprocessing.weighting.EqualLabelWeighting.java
@Override public List<ParameterType> getParameterTypes() { List<ParameterType> types = super.getParameterTypes(); ParameterType type = new ParameterTypeDouble(PARAMETER_TOTAL_WEIGHT, "The total weight distributed over all examples.", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 1); type.setExpert(false);//from w ww . j a va 2 s .c o m types.add(type); return types; }
From source file:edu.dfci.cccb.mev.deseq.domain.simple.FileBackedDESeq.java
private Double number(int index, String[] split) { String value = string(index, split); if ("Inf".equals(value)) return Double.POSITIVE_INFINITY; else if ("-Inf".equals(value)) return Double.NEGATIVE_INFINITY; else if ("NA".equals(value)) return Double.NaN; else/*from w ww. j av a2 s. c o m*/ return parseDouble(value); }