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:gov.nasa.jpf.constraints.solvers.cw.CWSolver.java
public static Number evaluateAndSubtractSides(NumericBooleanExpression constraint, Valuation valuation) { Object leftVal = constraint.getLeft().evaluate(valuation); Object rightVal = constraint.getRight().evaluate(valuation); if (!(leftVal instanceof Number && rightVal instanceof Number) && !(leftVal instanceof Boolean && rightVal instanceof Boolean)) throw new IllegalStateException( "left and right hand side must evaluate to a number or boolean; not Ltype: " + leftVal.getClass().getName() + " RType: " + rightVal.getClass().getName()); Number l; //DELETE? if (leftVal instanceof Boolean) { Boolean lv = (Boolean) leftVal; l = (lv) ? 1.0 : 0.0;//from w ww . j av a 2s.c o m } else l = (Number) leftVal; boolean leftIsNegative = l.doubleValue() < 0; Number r; //DELETE? if (rightVal instanceof Boolean) { Boolean rv = (Boolean) rightVal; r = (rv) ? 1.0 : 0.0; } else r = (Number) rightVal; boolean rightIsNegative = r.doubleValue() < 0; //TODO: not sure if this is correct.. double check with original implementation Number result = l.doubleValue() - r.doubleValue(); if (leftIsNegative == rightIsNegative) { // Can neither overflow nor underflow return result; } boolean resultIsNegative = result.doubleValue() < 0; boolean underflowOccurred = leftIsNegative && !resultIsNegative; boolean overflowOccurred = rightIsNegative && resultIsNegative; if (!underflowOccurred && !overflowOccurred) { return result; } if (result instanceof Integer) { return (underflowOccurred ? Integer.MIN_VALUE : Integer.MAX_VALUE); } else if (result instanceof Double) { return (underflowOccurred ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY); } else { throw new AssertionError("Result has unknown number type: " + result); } }
From source file:gamlss.distributions.GT.java
/** Computes the cumulative distribution * function P(X <= q) for a random variable X . * whose values are distributed according to this distribution * @param q - value of quantile/*from ww w .j a va 2 s.c om*/ * @param mu - value of mu distribution parameter * @param sigma - value of sigma distribution parameter * @param nu - value of nu distribution parameter * @param tau - value of tau distribution parameter * @param lowerTail - logical, if TRUE (default), probabilities * are P[X <= x] otherwise, P[X > x]. * @param isLog - logical, if TRUE, probabilities p are given as log(p) * @return value of cumulative probability function values P(X <= q) */ public final double pGT(final double q, final double mu, final double sigma, final double nu, final double tau, final boolean lowerTail, final boolean isLog) { // {if (any(sigma < 0))stop(paste("sigma must be positive", "\n","")) if (sigma < 0) { System.err.println("sigma must be positive"); return -1.0; } //if (any(nu <= 0)) stop(paste("nu must be positive", "\n", "")) if (nu <= 0) { System.err.println("nu must be positive"); return -1.0; } //if (any(tau <=0)) stop(paste("tau must be positive", "\n", "")) if (tau < 0) { System.err.println("tau must be positive"); return -1.0; } //endInt <- (q[i]-mu[i])/sigma[i] final double endInt = (q - mu) / sigma; //cdf[i] <- integrate(function(x) //dGT(x, mu = 0, sigma = 1, nu = nu[i], //tau = tau[i]), -Inf, endInt)$value function.setNu(nu); function.setTau(tau); //double out = integrator.integrate(Integer.MAX_VALUE, function, Double.NEGATIVE_INFINITY, endInt); double out = integrator.integrate(Integer.MAX_VALUE, function, Double.NEGATIVE_INFINITY, endInt); //if(endInt>0&&cdf<0.001) cdf[i] <- 1 if (endInt > 0 && out < 0.001) { out = 1.0; } //if(lower.tail==TRUE) cdf <- cdf else cdf <- 1-cdf if (!lowerTail) { if (isLog) { out = FastMath.log(1 - out); } else { out = 1 - out; } } else if (isLog) { //if(log.p==FALSE) cdf <- cdf else cdf <- log(cdf) out = FastMath.log(out); } return out; }
From source file:ml.shifu.shifu.container.obj.ModelConfig.java
@JsonIgnore public Map<String, Double> getHybridColumnNames() throws IOException { String delimiter = StringUtils.isBlank(this.getHeaderDelimiter()) ? this.getDataSetDelimiter() : this.getHeaderDelimiter(); String hybridColumnNameFile = dataSet.getHybridColumnNameFile(); if (StringUtils.isBlank(hybridColumnNameFile)) { String defaultHybridColumnNameFile = Constants.COLUMN_META_FOLDER_NAME + File.separator + Constants.DEFAULT_HYBRID_COLUMN_FILE; if (ShifuFileUtils.isFileExists(defaultHybridColumnNameFile, SourceType.LOCAL)) { hybridColumnNameFile = defaultHybridColumnNameFile; LOG.warn(//from ww w . j av a 2 s . c o m "'dataSet::hybridColumnNameFile' is not set while default hybridColumnNameFile: {} is found, default hybrid file will be used.", defaultHybridColumnNameFile); } else { LOG.warn( "'dataSet::hybridColumnNameFile' is not set and default hybridColumnNameFile: {} is not found, no hybrid configs.", defaultHybridColumnNameFile); return new HashMap<String, Double>(); } } List<String> list = CommonUtils.readConfNamesAsList(hybridColumnNameFile, SourceType.LOCAL, delimiter); Map<String, Double> map = new HashMap<String, Double>(); for (String string : list) { if (string.contains(Constants.DEFAULT_DELIMITER)) { String[] splits = CommonUtils.split(string, Constants.DEFAULT_DELIMITER); double parNum = BinUtils.parseNumber(splits[1]); if (Double.isNaN(parNum)) { map.put(string, Double.NEGATIVE_INFINITY); } else { map.put(string, parNum); } } else { map.put(string, Double.NEGATIVE_INFINITY); } } return map; }
From source file:com.androzic.Androzic.java
public Route trackToRoute(Track track, float sensitivity) throws IllegalArgumentException { Route route = new Route(); List<Track.TrackPoint> points = track.getAllPoints(); Track.TrackPoint lrp = points.get(0); route.addWaypoint("RWPT0", lrp.latitude, lrp.longitude); if (points.size() < 2) throw new IllegalArgumentException("Track too short"); Track.TrackPoint cp = points.get(1); Track.TrackPoint lp = lrp;/* w w w. j a v a 2 s. c o m*/ Track.TrackPoint tp = null; int i = 1; int prx = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this).getString( getString(R.string.pref_navigation_proximity), getString(R.string.def_navigation_proximity))); double proximity = prx * sensitivity; double d = 0, t = 0, b, pb = 0, cb = -1, icb = 0, xtk = 0; while (i < points.size()) { cp = points.get(i); d += Geo.distance(lp.latitude, lp.longitude, cp.latitude, cp.longitude); b = Geo.bearing(lp.latitude, lp.longitude, cp.latitude, cp.longitude); t += Geo.turn(pb, b); if (Math.abs(t) >= 360) { t = t - 360 * Math.signum(t); } //Log.d("ANDROZIC", i+","+b+","+t); lp = cp; pb = b; i++; // calculate initial track if (cb < 0) { if (d > proximity) { cb = Geo.bearing(lrp.latitude, lrp.longitude, cp.latitude, cp.longitude); pb = cb; t = 0; icb = cb + 180; if (icb >= 360) icb -= 360; // Log.w("ANDROZIC", "Found vector:" + cb); } continue; } // find turn if (Math.abs(t) > 10) { if (tp == null) { tp = cp; // Log.w("ANDROZIC", "Found turn: "+i); continue; } } else if (tp != null && xtk < proximity / 10) { tp = null; xtk = 0; // Log.w("ANDROZIC", "Reset turn: "+i); } // if turn in progress check xtk if (tp != null) { double xd = Geo.distance(cp.latitude, cp.longitude, tp.latitude, tp.longitude); double xb = Geo.bearing(cp.latitude, cp.longitude, tp.latitude, tp.longitude); xtk = Geo.xtk(xd, icb, xb); // turned at sharp angle if (xtk == Double.NEGATIVE_INFINITY) xtk = Geo.xtk(xd, cb, xb); // Log.w("ANDROZIC", "XTK: "+xtk); if (Math.abs(xtk) > proximity * 3) { lrp = tp; route.addWaypoint("RWPT" + route.length(), lrp.latitude, lrp.longitude); cb = Geo.bearing(lrp.latitude, lrp.longitude, cp.latitude, cp.longitude); // Log.e("ANDROZIC", "Set WPT: "+(route.length()-1)+","+cb); pb = cb; t = 0; icb = cb + 180; if (icb >= 360) icb -= 360; tp = null; d = 0; xtk = 0; } continue; } // if still direct but pretty far away add a point if (d > proximity * 200) { lrp = cp; route.addWaypoint("RWPT" + route.length(), lrp.latitude, lrp.longitude); // Log.e("ANDROZIC", "Set WPT: "+(route.length()-1)); d = 0; } } lrp = points.get(i - 1); route.addWaypoint("RWPT" + route.length(), lrp.latitude, lrp.longitude); route.name = "RT_" + track.name; route.show = true; return route; }
From source file:jp.furplag.util.commons.NumberUtilsTest.java
/** * {@link jp.furplag.util.commons.NumberUtils#contains(java.lang.Object, java.lang.Number, java.lang.Number)}. *///from ww w. ja va 2 s .c o m @SuppressWarnings("unchecked") @Test public void testContains() { assertEquals("null", false, contains(null, null, null)); assertEquals("null", false, contains(null, 0, null)); assertEquals("null", false, contains(null, null, 10)); assertEquals("null", false, contains(null, 0, 10)); assertEquals("null: from", true, contains(0, null, 10)); assertEquals("null: from: overflow", false, contains(11, null, 10)); assertEquals("null: to", true, contains(0, 0, null)); assertEquals("null: to", true, contains(11, 10, null)); assertEquals("null: to: less", false, contains(1, 10, null)); assertEquals("fraction: Double", true, contains(Math.PI, 0, 10)); assertEquals("fraction: Float", true, contains(Float.MIN_VALUE, 0, 10)); assertEquals("NaN", false, contains(Float.NaN, -Float.MAX_VALUE, Float.MAX_VALUE)); assertEquals("NaN", false, contains(Float.NaN, null, Float.POSITIVE_INFINITY)); assertEquals("NaN", true, contains(Float.NaN, Float.NaN, Float.POSITIVE_INFINITY)); assertEquals("NaN", true, contains(Float.NaN, null, Float.NaN)); assertEquals("NaN", true, contains(Float.NaN, Double.NaN, Float.NaN)); assertEquals("-Infinity: from", true, contains(1, Float.NEGATIVE_INFINITY, null)); assertEquals("-Infinity: to", false, contains(1, null, Float.NEGATIVE_INFINITY)); assertEquals("Infinity: from", false, contains(1, Float.POSITIVE_INFINITY, null)); assertEquals("Infinity: to", true, contains(1, null, Float.POSITIVE_INFINITY)); assertEquals("Infinity: only", false, contains(1, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)); assertEquals("Infinity: only", true, contains(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)); assertEquals("Infinity: only", true, contains(Double.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)); for (Class<?> type : NUMBERS) { Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type); Object o = null; try { if (ClassUtils.isPrimitiveWrapper(wrapper)) { o = wrapper.getField("MAX_VALUE").get(null); } else { o = INFINITY_DOUBLE.pow(2); if (BigInteger.class.equals(type)) o = ((BigDecimal) o).toBigInteger(); } assertEquals("Infinity: all: " + type.getSimpleName(), true, contains(o, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace())); } } }
From source file:jp.furplag.util.commons.NumberUtils.java
/** * {@link java.lang.Double#isInfinite()}. * * @param o the object, number or string. * @param signum return {@code n == -Infinity} if {@code signum < 0}. if {@code signum > 0}, return {@code n == Infinity}. * @return {@code == Infinity}.//from w w w. j a v a 2s . c o m */ public static boolean isInfinite(final Object o, final int signum) { Number n = valueOf(o); if (n == null) return false; if (!ObjectUtils.isAny(n, double.class, Double.class, float.class, Float.class)) return false; if (n.toString().equalsIgnoreCase(signum < 0 ? "-Infinity" : "Infinity")) return true; if (signum > 0 && Double.POSITIVE_INFINITY == Double.valueOf(n.toString())) return true; if (signum < 0 && Double.NEGATIVE_INFINITY == Double.valueOf(n.toString())) return true; if (signum == 0 && Double.valueOf(n.toString()).isInfinite()) return true; return false; }
From source file:gov.nasa.jpf.constraints.solvers.cw.CWSolver.java
static int indexOfMaxIgnoringTabu(double[] values, int[] tabuIndices) { double currentMax = Double.NEGATIVE_INFINITY; int currentMaxIndex = -1; for (int i = 0; i < values.length; ++i) { if (tabuIndices[i] > 0) { continue; }/* www . j a va2s .com*/ if (currentMax < values[i]) { currentMaxIndex = i; currentMax = values[i]; } } return currentMaxIndex; }
From source file:edu.cmu.tetrad.search.FastIca.java
private TetradMatrix icaParallel(TetradMatrix X, int numComponents, double tolerance, int function, final double alpha, int maxIterations, boolean verbose, TetradMatrix wInit) { int p = X.columns(); TetradMatrix W = wInit;//from ww w. j av a2 s . co m SingularValueDecomposition sW = new SingularValueDecomposition(W.getRealMatrix()); TetradMatrix D = new TetradMatrix(sW.getS()); for (int i = 0; i < D.rows(); i++) D.set(i, i, 1.0 / D.get(i, i)); TetradMatrix WTemp = new TetradMatrix(sW.getU()).times(D); WTemp = WTemp.times(new TetradMatrix(sW.getU()).transpose()); WTemp = WTemp.times(W); W = WTemp; TetradMatrix W1; double _tolerance = Double.POSITIVE_INFINITY; int it = 0; if (function == LOGCOSH) { if (verbose) { TetradLogger.getInstance().log("info", "Symmetric FastICA using logcosh approx. to neg-entropy function"); } while (_tolerance > tolerance && it < maxIterations) { TetradMatrix wx = W.times(X); TetradMatrix gwx = new TetradMatrix(numComponents, p); for (int i = 0; i < numComponents; i++) { for (int j = 0; j < p; j++) { gwx.set(i, j, Math.tanh(alpha * wx.get(i, j))); } } TetradMatrix v1 = gwx.times(X.transpose().copy().scalarMult(1.0 / p)); TetradMatrix g_wx = gwx.copy(); for (int i = 0; i < g_wx.rows(); i++) { for (int j = 0; j < g_wx.columns(); j++) { double v = g_wx.get(i, j); double w = alpha * (1.0 - v * v); g_wx.set(i, j, w); } } TetradVector V20 = new TetradVector(numComponents); for (int k = 0; k < numComponents; k++) { V20.set(k, mean(g_wx.getRow(k))); } TetradMatrix v2 = V20.diag(); v2 = v2.times(W); W1 = v1.minus(v2); SingularValueDecomposition sW1 = new SingularValueDecomposition(W1.getRealMatrix()); TetradMatrix U = new TetradMatrix(sW1.getU()); TetradMatrix sD = new TetradMatrix(sW1.getS()); for (int i = 0; i < sD.rows(); i++) sD.set(i, i, 1.0 / sD.get(i, i)); TetradMatrix W1Temp = U.times(sD); W1Temp = W1Temp.times(U.transpose()); W1Temp = W1Temp.times(W1); W1 = W1Temp; TetradMatrix d1 = W1.times(W.transpose()); TetradVector d = d1.diag(); _tolerance = Double.NEGATIVE_INFINITY; for (int i = 0; i < d.size(); i++) { double m = Math.abs(Math.abs(d.get(i)) - 1); if (m > _tolerance) _tolerance = m; } W = W1; if (verbose) { TetradLogger.getInstance().log("fastIcaDetails", "Iteration " + (it + 1) + " tol = " + _tolerance); } it++; } } else if (function == EXP) { if (verbose) { TetradLogger.getInstance().log("info", "Symmetric FastICA using exponential approx. to neg-entropy function"); } while (_tolerance > tolerance && it < maxIterations) { TetradMatrix wx = W.times(X); TetradMatrix gwx = new TetradMatrix(numComponents, p); for (int i = 0; i < numComponents; i++) { for (int j = 0; j < p; j++) { double v = wx.get(i, j); gwx.set(i, j, v * Math.exp(-(v * v) / 2.0)); } } TetradMatrix v1 = gwx.times(X.transpose().scalarMult(p)); TetradMatrix g_wx = wx.copy(); for (int i = 0; i < g_wx.rows(); i++) { for (int j = 0; j < g_wx.columns(); j++) { double v = g_wx.get(i, j); double w = (1.0 - v * v) * Math.exp(-(v * v) / 2.0); g_wx.set(i, j, w); } } TetradVector V20 = new TetradVector(numComponents); for (int k = 0; k < numComponents; k++) { V20.set(k, mean(g_wx.getRow(k))); } TetradMatrix v2 = V20.diag(); v2 = v2.times(W); W1 = v1.minus(v2); SingularValueDecomposition sW1 = new SingularValueDecomposition(W1.getRealMatrix()); TetradMatrix U = new TetradMatrix(sW1.getU()); TetradMatrix sD = new TetradMatrix(sW1.getS()); for (int i = 0; i < sD.rows(); i++) sD.set(i, i, 1.0 / sD.get(i, i)); TetradMatrix W1Temp = U.times(sD); W1Temp = W1Temp.times(U.transpose()); W1Temp = W1Temp.times(W1); W1 = W1Temp; TetradMatrix d1 = W1.times(W.transpose()); TetradVector d = d1.diag(); _tolerance = Double.NEGATIVE_INFINITY; for (int i = 0; i < d.size(); i++) { double m = Math.abs(Math.abs(d.get(i)) - 1); if (m > _tolerance) _tolerance = m; } W.assign(W1); if (verbose) { TetradLogger.getInstance().log("fastIcaDetails", "Iteration " + (it + 1) + " tol = " + _tolerance); } it++; } } return W; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Iterates over the items in an {@link XYDataset} to find * the range of x-values./* www .j a va 2 s . c o m*/ * * @param dataset the dataset ({@code null} not permitted). * @param includeInterval a flag that determines, for an * {@link IntervalXYDataset}, whether the x-interval or just the * x-value is used to determine the overall range. * * @return The range (possibly {@code null}). */ public static Range iterateDomainBounds(XYDataset dataset, boolean includeInterval) { Args.nullNotPermitted(dataset, "dataset"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); double lvalue, uvalue; if (includeInterval && dataset instanceof IntervalXYDataset) { IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value = intervalXYData.getXValue(series, item); lvalue = intervalXYData.getStartXValue(series, item); uvalue = intervalXYData.getEndXValue(series, item); if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); maximum = Math.max(maximum, value); } if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); maximum = Math.max(maximum, lvalue); } if (!Double.isNaN(uvalue)) { minimum = Math.min(minimum, uvalue); maximum = Math.max(maximum, uvalue); } } } } else { for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { lvalue = dataset.getXValue(series, item); uvalue = lvalue; if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); maximum = Math.max(maximum, uvalue); } } } } if (minimum > maximum) { return null; } else { return new Range(minimum, maximum); } }
From source file:gamlss.distributions.ST1.java
/** Computes the cumulative distribution * function P(X <= q) for a random variable X . * whose values are distributed according to this distribution * @param q - value of quantile/*from ww w. jav a 2 s . c o m*/ * @param mu - value of mu distribution parameter * @param sigma - value of sigma distribution parameter * @param nu - value of nu distribution parameter * @param tau - value of tau distribution parameter * @param lowerTail - logical, if TRUE (default), probabilities * are P[X <= x] otherwise, P[X > x]. * @param isLog - logical, if TRUE, probabilities p are given as log(p) * @return value of cumulative probability function values P(X <= q) */ public final double pST1(final double q, final double mu, final double sigma, final double nu, final double tau, final boolean lowerTail, final boolean isLog) { // { if (any(sigma <= 0))stop(paste("sigma must be positive",)) if (sigma <= 0) { System.err.println("sigma must be positive"); return -1.0; } //if (any(tau < 0)) stop(paste("tau must be positive", "\n", "")) if (tau < 0) { System.err.println("tau must be positive"); return -1.0; } //cdf[i] <- integrate(function(x) //dST1(x, mu = 0, sigma = 1, nu = nu[i], tau = tau[i]), //-Inf, (q[i]-mu[i])/sigma[i] )$value function.setNu(nu); function.setTau(tau); double out = integrator.integrate(Integer.MAX_VALUE, function, Double.NEGATIVE_INFINITY, (q - mu) / sigma); //if(lower.tail==TRUE) cdf <- cdf else cdf <- 1-cdf if (!lowerTail) { if (isLog) { out = FastMath.log(1 - out); } else { out = 1 - out; } } else if (isLog) { //if(log.p==FALSE) cdf <- cdf else cdf <- log(cdf) out = FastMath.log(out); } return out; }