List of usage examples for java.lang Double POSITIVE_INFINITY
double POSITIVE_INFINITY
To view the source code for java.lang Double POSITIVE_INFINITY.
Click Source Link
From source file:com.cloudera.oryx.common.random.RandomUtils.java
/** * @param dimensions dimensionality of resulting vector * @param farFrom vectors that the chosen vector should be "far from" -- not in the same direction as * @param random random number generator to use * @return a vector of length 1 over the given number of dimensions, whose direction is chosen uniformly * at random (that is: a point chosen uniformly at random on the unit hypersphere), but preferring * those not in the same direction as a set of existing vectors *//*from ww w.ja va 2 s . c o m*/ public static float[] randomUnitVectorFarFrom(int dimensions, List<float[]> farFrom, RandomGenerator random) { int size = farFrom.size(); int numSamples = FastMath.min(100, size); float[] vector = new float[dimensions]; boolean accepted = false; while (!accepted) { doRandomUnitVector(vector, random); double smallestDistSquared = Double.POSITIVE_INFINITY; for (int sample = 0; sample < numSamples; sample++) { float[] other = farFrom.get(size == numSamples ? sample : random.nextInt(size)); // dot is the cosine here since both are unit vectors double distSquared = 2.0 - 2.0 * SimpleVectorMath.dot(vector, other); if (Doubles.isFinite(distSquared) && distSquared < smallestDistSquared) { smallestDistSquared = distSquared; } } // Second condition covers 1-D case, where there are only 2 distinct unit vectors. If both have // been generated, keep accepting either of them. if (Doubles.isFinite(smallestDistSquared) && !(dimensions == 1 && smallestDistSquared == 0.0)) { // Choose with probability proportional to squared distance, a la kmeans++ centroid selection double acceptProbability = smallestDistSquared / 4.0; // dist squared is in [0,4] accepted = random.nextDouble() < acceptProbability; } else { // kind of a default accepted = true; } } return vector; }
From source file:dr.inference.distribution.InverseGammaDistributionModel.java
/** * Construct a constant mutation rate model. *///from ww w. ja v a2s.co m public InverseGammaDistributionModel(Variable<Double> shape) { super(INVERSE_GAMMA_DISTRIBUTION_MODEL); this.shape = shape; addVariable(shape); shape.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1)); }
From source file:edu.oregonstate.eecs.mcplan.op.PolicyRollout.java
public PolicyRollout(final RandomGenerator rng, final TrajectorySimulator<S, A> sim, final ActionSpace<S, A> action_space, final FiniteBandit<Policy<S, A>> bandit, final ArrayList<Policy<S, A>> Pi, final int depth_limit) { this(rng, sim, action_space, bandit, Pi, depth_limit, Double.POSITIVE_INFINITY); }
From source file:com.clust4j.algo.preprocess.MinMaxScaler.java
@Override public MinMaxScaler fit(RealMatrix X) { synchronized (fitLock) { final int m = X.getRowDimension(); final int n = X.getColumnDimension(); this.mins = new double[n]; this.maxes = new double[n]; double[][] data = X.getData(); for (int col = 0; col < n; col++) { double mn = Double.POSITIVE_INFINITY, mx = Double.NEGATIVE_INFINITY; for (int row = 0; row < m; row++) { mn = FastMath.min(mn, data[row][col]); mx = FastMath.max(mx, data[row][col]); }// w w w .j a v a 2 s.c o m this.mins[col] = mn; this.maxes[col] = mx; } return this; } }
From source file:com.analog.lyric.dimple.factorfunctions.Binomial.java
@Override public final double evalEnergy(Value[] arguments) { int index = 0; if (!_NParameterConstant) { _N = arguments[index++].getInt(); // First argument is N parameter if (_N < 0) return Double.POSITIVE_INFINITY; _negativeLogFactorialN = -org.apache.commons.math3.special.Gamma.logGamma(_N + 1); }//from w ww . ja v a 2 s . c o m final double p = arguments[index++].getDouble(); // Next argument is the probability parameter if (p < 0 || p > 1) return Double.POSITIVE_INFINITY; final int numOnes = arguments[index++].getInt(); // Next argument is the one-count if (numOnes < 0 || numOnes > _N) return Double.POSITIVE_INFINITY; int numZeros = _N - numOnes; if (p == 0) if (numOnes > 0) return Double.POSITIVE_INFINITY; else return 0; else if (p == 1) if (numZeros > 0) return Double.POSITIVE_INFINITY; else return 0; else return -(numOnes * Math.log(p) + numZeros * Math.log(1 - p)) + _negativeLogFactorialN + org.apache.commons.math3.special.Gamma.logGamma(numOnes + 1) + org.apache.commons.math3.special.Gamma.logGamma(numZeros + 1); }
From source file:io.sidecar.notification.NotificationRule.java
public NotificationRule(UUID ruleId, String name, String description, UUID appId, UUID userId, String stream, String key, double min, double max) { this.ruleId = checkNotNull(ruleId); checkArgument(StringUtils.isNotBlank(name) && name.length() <= 100); this.name = name.trim(); checkArgument(StringUtils.isBlank(description) || description.length() <= 140); this.description = (description == null) ? "" : description.trim(); this.appId = checkNotNull(appId); this.userId = checkNotNull(userId); Preconditions.checkArgument(ModelUtils.isValidStreamId(stream)); this.stream = checkNotNull(stream); checkArgument(ModelUtils.isValidReadingKey(key)); this.key = key; this.min = (min == Double.NEGATIVE_INFINITY || min == Double.NaN) ? Double.MIN_VALUE : min; this.max = (max == Double.POSITIVE_INFINITY || max == Double.NaN) ? Double.MAX_VALUE : max; }
From source file:com.rapidminer.operator.preprocessing.weighting.EqualLabelWeighting.java
@Override protected Range getWeightAttributeRange() { try {/* w w w. ja va2s . c om*/ return new Range(0, getParameterAsDouble(PARAMETER_TOTAL_WEIGHT)); } catch (UndefinedParameterError e) { return new Range(0, Double.POSITIVE_INFINITY); } }
From source file:com.opengamma.analytics.financial.model.volatility.BlackScholesFormulaRepository.java
/** * The <b>spot</b> price// w w w. j av a 2 s.c o m * @param spot The spot value of the underlying * @param strike The Strike * @param timeToExpiry The time-to-expiry * @param lognormalVol The log-normal volatility * @param interestRate The interest rate * @param costOfCarry The cost-of-carry rate * @param isCall True for calls, false for puts * @return The <b>spot</b> price */ @ExternalFunction public static double price(final double spot, final double strike, final double timeToExpiry, final double lognormalVol, final double interestRate, final double costOfCarry, final boolean isCall) { ArgumentChecker.isTrue(spot >= 0.0, "negative/NaN spot; have {}", spot); ArgumentChecker.isTrue(strike >= 0.0, "negative/NaN strike; have {}", strike); ArgumentChecker.isTrue(timeToExpiry >= 0.0, "negative/NaN timeToExpiry; have {}", timeToExpiry); ArgumentChecker.isTrue(lognormalVol >= 0.0, "negative/NaN lognormalVol; have {}", lognormalVol); ArgumentChecker.isFalse(Double.isNaN(interestRate), "interestRate is NaN"); ArgumentChecker.isFalse(Double.isNaN(costOfCarry), "costOfCarry is NaN"); if (interestRate > LARGE) { return 0.; } if (-interestRate > LARGE) { return Double.POSITIVE_INFINITY; } double discount = Math.abs(interestRate) < SMALL ? 1. : Math.exp(-interestRate * timeToExpiry); if (costOfCarry > LARGE) { return isCall ? Double.POSITIVE_INFINITY : 0.; } if (-costOfCarry > LARGE) { final double res = isCall ? 0. : (discount > SMALL ? strike * discount : 0.); return Double.isNaN(res) ? discount : res; } double factor = Math.exp(costOfCarry * timeToExpiry); if (spot > LARGE * strike) { final double tmp = Math.exp((costOfCarry - interestRate) * timeToExpiry); return isCall ? (tmp > SMALL ? spot * tmp : 0.) : 0.; } if (LARGE * spot < strike) { return (isCall || discount < SMALL) ? 0. : strike * discount; } if (spot > LARGE && strike > LARGE) { final double tmp = Math.exp((costOfCarry - interestRate) * timeToExpiry); return isCall ? (tmp > SMALL ? spot * tmp : 0.) : (discount > SMALL ? strike * discount : 0.); } final double rootT = Math.sqrt(timeToExpiry); double sigmaRootT = lognormalVol * rootT; if (Double.isNaN(sigmaRootT)) { sigmaRootT = 1.; //ref value is returned } final int sign = isCall ? 1 : -1; final double rescaledSpot = factor * spot; if (sigmaRootT < SMALL) { final double res = isCall ? (rescaledSpot > strike ? discount * (rescaledSpot - strike) : 0.) : (rescaledSpot < strike ? discount * (strike - rescaledSpot) : 0.); return Double.isNaN(res) ? sign * (spot - discount * strike) : res; } double d1 = 0.; double d2 = 0.; if (Math.abs(spot - strike) < SMALL || sigmaRootT > LARGE) { final double coefD1 = (costOfCarry / lognormalVol + 0.5 * lognormalVol); final double coefD2 = (costOfCarry / lognormalVol - 0.5 * lognormalVol); final double tmpD1 = coefD1 * rootT; final double tmpD2 = coefD2 * rootT; d1 = Double.isNaN(tmpD1) ? 0. : tmpD1; d2 = Double.isNaN(tmpD2) ? 0. : tmpD2; } else { final double tmp = costOfCarry * rootT / lognormalVol; final double sig = (costOfCarry >= 0.) ? 1. : -1.; final double scnd = Double.isNaN(tmp) ? ((lognormalVol < LARGE && lognormalVol > SMALL) ? sig / lognormalVol : sig * rootT) : tmp; d1 = Math.log(spot / strike) / sigmaRootT + scnd + 0.5 * sigmaRootT; d2 = d1 - sigmaRootT; } // if (Double.isNaN(d1) || Double.isNaN(d2)) { // throw new IllegalArgumentException("NaN found"); // } final double res = sign * discount * (rescaledSpot * NORMAL.getCDF(sign * d1) - strike * NORMAL.getCDF(sign * d2)); return Double.isNaN(res) ? 0. : Math.max(res, 0.); }
From source file:edu.oregonstate.eecs.mcplan.op.PolicySwitching.java
public PolicySwitching(final RandomGenerator rng, final TrajectorySimulator<S, A> sim, final FiniteBandit<Policy<S, A>> bandit, final ArrayList<Policy<S, A>> Pi, final int depth_limit) { this(rng, sim, bandit, Pi, depth_limit, Double.POSITIVE_INFINITY); }
From source file:org.spf4j.perf.impl.chart.QuantizedXYZDatasetImpl.java
public QuantizedXYZDatasetImpl(final String[] dataSources, final double[][] pdata, final long startTimeMillis, final long step) { this.data = pdata.clone(); this.startTimeMillis = startTimeMillis; this.stepMillis = step; quantas = new ArrayList<ComparablePair<Quanta, Integer>>(dataSources.length); for (int i = 0; i < dataSources.length; i++) { String ds = dataSources[i]; if (ds.startsWith("Q")) { Quanta quanta = new Quanta(ds); quantas.add(ComparablePair.of(quanta, i)); }/*from ww w .j a va 2 s .c om*/ } Collections.sort(quantas); final int nrQuantas = quantas.size(); int seriesSize = nrQuantas * data.length; x = new double[seriesSize]; y = new double[seriesSize]; z = new double[seriesSize]; double lMinValue = Double.POSITIVE_INFINITY; double lMaxValue = Double.NEGATIVE_INFINITY; int k = 0; for (int j = 0; j < nrQuantas; j++) { ComparablePair<Quanta, Integer> pair = quantas.get(j); double[] values = Arrays.getColumn(data, pair.getSecond()); for (int i = 0; i < values.length; i++) { x[k] = i; //timestamps[i]*1000; y[k] = j; //(double) pair.getFirst().getClosestToZero(); double zval = values[i]; z[k] = zval; if (zval > lMaxValue) { lMaxValue = zval; } if (zval < lMinValue) { lMinValue = zval; } k++; } } this.minValue = lMinValue; this.maxValue = lMaxValue; }