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:dr.evomodel.speciation.BirthDeathGernhard08Model.java
public BirthDeathGernhard08Model(String modelName, Parameter birthDiffRateParameter, Parameter relativeDeathRateParameter, Parameter sampleProbability, TreeType type, Type units, boolean conditionalOnRoot) { super(modelName, units); this.birthDiffRateParameter = birthDiffRateParameter; addVariable(birthDiffRateParameter); birthDiffRateParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1)); this.relativeDeathRateParameter = relativeDeathRateParameter; if (relativeDeathRateParameter != null) { addVariable(relativeDeathRateParameter); relativeDeathRateParameter.addBounds(new Parameter.DefaultBounds(1.0, 0.0, 1)); }// www. j a va2 s .com this.sampleProbability = sampleProbability; if (sampleProbability != null) { addVariable(sampleProbability); sampleProbability.addBounds(new Parameter.DefaultBounds(1.0, 0.0, 1)); } this.conditionalOnRoot = conditionalOnRoot; if (conditionalOnRoot && sampleProbability != null) { throw new IllegalArgumentException( "Not supported: birth death prior conditional on root with sampling probability."); } this.type = type; }
From source file:beast.evolution.sitemodel.SiteModel.java
@Override public void initAndValidate() { useBeast1StyleGamma = true; //useBeast1StyleGammaInput.get(); muParameter = muParameterInput.get(); if (muParameter == null) { muParameter = new RealParameter("1.0"); }// ww w .ja va2 s .co m shapeParameter = shapeParameterInput.get(); invarParameter = invarParameterInput.get(); if (invarParameter == null) { invarParameter = new RealParameter("0.0"); invarParameter.setBounds(Math.max(0.0, invarParameter.getLower()), Math.min(1.0, invarParameter.getUpper())); } //if (muParameter != null) { muParameter.setBounds(Math.max(muParameter.getLower(), 0.0), Math.min(muParameter.getUpper(), Double.POSITIVE_INFINITY)); //} if (shapeParameter != null) { // The quantile calculator fails when the shape parameter goes much below // 1E-3 so we have put a hard lower bound on it. If this is not there then // the category rates can go to 0 and cause a -Inf likelihood (whilst this // is not a problem as the state will be rejected, it could mask other issues // and this seems the better approach. shapeParameter.setBounds(Math.max(shapeParameter.getLower(), 1.0E-3), Math.min(shapeParameter.getUpper(), 1.0E3)); } if (/*invarParameter != null && */(invarParameter.getValue() < 0 || invarParameter.getValue() > 1)) { throw new IllegalArgumentException("proportion invariant should be between 0 and 1"); } refresh(); addCondition(muParameterInput); addCondition(invarParameterInput); addCondition(shapeParameterInput); }
From source file:com.analog.lyric.dimple.factorfunctions.MultinomialUnnormalizedParameters.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); }//w ww . j ava 2 s. com for (int i = 0; i < _dimension; i++) { final double a = arguments[index++].getDouble(); // Next _dimension arguments are vector of Alpha parameters if (a < 0) return Double.POSITIVE_INFINITY; _alpha[i] = a; } if (arguments.length - index != _dimension) throw new DimpleException( "Number of count variables must equal the dimension of the parameter vector."); int countSum = 0; double parameterSum = 0; double sum = _negativeLogFactorialN; for (int i = 0; i < _dimension; i++) { final double alphai = _alpha[i]; if (alphai < 0) return Double.POSITIVE_INFINITY; parameterSum += alphai; final int x = arguments[index++].getInt(); // Remaining arguments are discrete count variables if (x < 0) return Double.POSITIVE_INFINITY; countSum += x; double negativeXLogAlphai; if (alphai == 0 && x == 0) negativeXLogAlphai = 0; else negativeXLogAlphai = -x * Math.log(alphai); sum += negativeXLogAlphai + org.apache.commons.math3.special.Gamma.logGamma(x + 1); } if (countSum != _N) return Double.POSITIVE_INFINITY; final double energy = sum + _N * Math.log(parameterSum); if (energy != energy) // Faster isNaN return Double.POSITIVE_INFINITY; return energy; }
From source file:com.analog.lyric.dimple.factorfunctions.Beta.java
@Override public final double evalEnergy(Value[] arguments) { int index = 0; if (!_parametersConstant) { _alpha = arguments[index++].getDouble(); // First input is alpha parameter (must be // non-negative) _beta = arguments[index++].getDouble(); // Second input is beta parameter (must be // non-negative) _alphaMinusOne = _alpha - 1;//from ww w . j a v a 2 s . co m _betaMinusOne = _beta - 1; _logBetaAlphaBeta = org.apache.commons.math3.special.Beta.logBeta(_alpha, _beta); if (_alpha < 0) return Double.POSITIVE_INFINITY; if (_beta < 0) return Double.POSITIVE_INFINITY; } final int length = arguments.length; final int N = length - index; // Number of non-parameter variables double sum = 0; if (_alpha == 1 && _beta == 1) { for (; index < length; index++) { final double x = arguments[index].getDouble(); // Remaining inputs are Beta // variables if (x < 0 || x > 1) return Double.POSITIVE_INFINITY; } return 0; // Uniform within 0 <= x <= 1 } else if (_alpha == 1) { for (; index < length; index++) { final double x = arguments[index].getDouble(); // Remaining inputs are Beta // variables if (x < 0 || x > 1) return Double.POSITIVE_INFINITY; sum += Math.log(1 - x); } return N * _logBetaAlphaBeta - sum * _betaMinusOne; } else if (_beta == 1) { for (; index < length; index++) { final double x = arguments[index].getDouble(); // Remaining inputs are Beta // variables if (x < 0 || x > 1) return Double.POSITIVE_INFINITY; sum += Math.log(x); } return N * _logBetaAlphaBeta - sum * _alphaMinusOne; } else { for (; index < length; index++) { final double x = arguments[index].getDouble(); // Remaining inputs are Beta // variables if (x < 0 || x > 1) return Double.POSITIVE_INFINITY; sum += _alphaMinusOne * Math.log(x) + _betaMinusOne * Math.log(1 - x); } return N * _logBetaAlphaBeta - sum; } }
From source file:hivemall.knn.similarity.DIMSUMMapperUDTF.java
@Override protected CommandLine processOptions(@Nonnull ObjectInspector[] argOIs) throws UDFArgumentException { double threshold = 0.5d; double gamma = Double.POSITIVE_INFINITY; boolean symmetricOutput = true; boolean parseFeatureAsInt = false; CommandLine cl = null;/*from w ww. jav a 2 s . c o m*/ if (argOIs.length >= 3) { String rawArgs = HiveUtils.getConstString(argOIs[2]); cl = parseOptions(rawArgs); threshold = Primitives.parseDouble(cl.getOptionValue("threshold"), threshold); if (threshold < 0.f || threshold >= 1.f) { throw new UDFArgumentException("`threshold` MUST be in range [0,1): " + threshold); } gamma = Primitives.parseDouble(cl.getOptionValue("gamma"), gamma); if (gamma <= 1.d) { throw new UDFArgumentException("`gamma` MUST be greater than 1: " + gamma); } symmetricOutput = !cl.hasOption("disable_symmetric_output"); parseFeatureAsInt = cl.hasOption("feature_as_integer"); } this.threshold = threshold; this.sqrtGamma = Math.sqrt(gamma); this.symmetricOutput = symmetricOutput; this.parseFeatureAsInt = parseFeatureAsInt; return cl; }
From source file:com.cognitect.transit.TransitTest.java
public void testReadSpecialNumbers() throws IOException { assertEquals(Double.NaN, reader("\"~zNaN\"").read()); assertEquals(Double.POSITIVE_INFINITY, reader("\"~zINF\"").read()); assertEquals(Double.NEGATIVE_INFINITY, reader("\"~z-INF\"").read()); }
From source file:com.analog.lyric.dimple.solvers.gibbs.samplers.generic.CDFSampler.java
@Override public void nextSample(DiscreteValue sampleValue, double[] energy, double minEnergy, IDiscreteSamplerClient samplerClient) { final RandomGenerator rand = activeRandom(); final int length = sampleValue.getDomain().size(); //energy may be longer than domain size int sampleIndex; // Special-case lengths 2, 3, and 4 for speed switch (length) { case 2: {//from www . j a va2 s. c o m sampleIndex = (rand.nextDouble() * (1 + Math.exp(energy[1] - energy[0])) > 1) ? 0 : 1; break; } case 3: { final double cumulative1 = Math.exp(minEnergy - energy[0]); final double cumulative2 = cumulative1 + Math.exp(minEnergy - energy[1]); final double sum = cumulative2 + Math.exp(minEnergy - energy[2]); final double randomValue = sum * rand.nextDouble(); sampleIndex = (randomValue > cumulative2) ? 2 : (randomValue > cumulative1) ? 1 : 0; break; } case 4: { final double cumulative1 = Math.exp(minEnergy - energy[0]); final double cumulative2 = cumulative1 + Math.exp(minEnergy - energy[1]); final double cumulative3 = cumulative2 + Math.exp(minEnergy - energy[2]); final double sum = cumulative3 + Math.exp(minEnergy - energy[3]); final double randomValue = sum * rand.nextDouble(); sampleIndex = (randomValue > cumulative2) ? ((randomValue > cumulative3) ? 3 : 2) : ((randomValue > cumulative1) ? 1 : 0); break; } default: // For all other lengths { // Calculate cumulative conditional probability (unnormalized) double sum = 0; final double[] samplerScratch = _samplerScratch; samplerScratch[0] = 0; for (int m = 1; m < length; m++) { sum += expApprox(minEnergy - energy[m - 1]); samplerScratch[m] = sum; } sum += expApprox(minEnergy - energy[length - 1]); for (int m = length; m < _lengthRoundedUp; m++) samplerScratch[m] = Double.POSITIVE_INFINITY; final int half = _lengthRoundedUp >> 1; while (true) { // Sample from the distribution using a binary search. final double randomValue = sum * rand.nextDouble(); sampleIndex = 0; for (int bitValue = half; bitValue > 0; bitValue >>= 1) { final int testIndex = sampleIndex | bitValue; if (randomValue > samplerScratch[testIndex]) sampleIndex = testIndex; } // Rejection sampling, since the approximation of the exponential function is so coarse final double logp = minEnergy - energy[sampleIndex]; if (Double.isNaN(logp)) throw new DimpleException( "The energy for all values of this variable is infinite. This may indicate a state inconsistent with the model."); if (rand.nextDouble() * expApprox(logp) <= Math.exp(logp)) break; } } } samplerClient.setNextSampleIndex(sampleIndex); }
From source file:com.joptimizer.optimizers.LPStandardConverterTest.java
/** * Standardization of a problem on the form: * min(c) s.t.//from w w w . j av a2 s.c om * G.x < h * A.x = b * lb <= x <= ub */ public void testCGhAbLbUb1() throws Exception { log.debug("testCGhAbLbUb1"); String problemId = "1"; double[] c = Utils.loadDoubleArrayFromFile( "lp" + File.separator + "standardization" + File.separator + "c" + problemId + ".txt"); double[][] G = Utils.loadDoubleMatrixFromFile( "lp" + File.separator + "standardization" + File.separator + "G" + problemId + ".csv", ",".charAt(0)); double[] h = Utils.loadDoubleArrayFromFile( "lp" + File.separator + "standardization" + File.separator + "h" + problemId + ".txt"); ; double[][] A = Utils.loadDoubleMatrixFromFile( "lp" + File.separator + "standardization" + File.separator + "A" + problemId + ".csv", ",".charAt(0)); double[] b = Utils.loadDoubleArrayFromFile( "lp" + File.separator + "standardization" + File.separator + "b" + problemId + ".txt"); double[] lb = Utils.loadDoubleArrayFromFile( "lp" + File.separator + "standardization" + File.separator + "lb" + problemId + ".txt"); double[] ub = Utils.loadDoubleArrayFromFile( "lp" + File.separator + "standardization" + File.separator + "ub" + problemId + ".txt"); double[] expectedSol = Utils.loadDoubleArrayFromFile( "lp" + File.separator + "standardization" + File.separator + "sol" + problemId + ".txt"); double expectedValue = Utils.loadDoubleArrayFromFile( "lp" + File.separator + "standardization" + File.separator + "value" + problemId + ".txt")[0]; //double expectedTolerance = Utils.loadDoubleArrayFromFile("lp"+File.separator+"standardization"+File.separator+"tolerance"+problemId+".txt")[0]; double expectedTolerance = MatrixUtils.createRealMatrix(A) .operate(MatrixUtils.createRealVector(expectedSol)).subtract(MatrixUtils.createRealVector(b)) .getNorm(); //standard form conversion double unboundedLBValue = Double.NEGATIVE_INFINITY;//this is because in the file the unbounded lb are -Infinity values (not the default value) double unboundedUBValue = Double.POSITIVE_INFINITY;//this is because in the file the unbounded ub are +Infinity values LPStandardConverter lpConverter = new LPStandardConverter(unboundedLBValue, unboundedUBValue); lpConverter.toStandardForm(c, G, h, A, b, lb, ub); int n = lpConverter.getStandardN(); int s = lpConverter.getStandardS(); c = lpConverter.getStandardC().toArray(); A = lpConverter.getStandardA().toArray(); b = lpConverter.getStandardB().toArray(); lb = lpConverter.getStandardLB().toArray(); ub = lpConverter.getStandardUB().toArray(); log.debug("n : " + n); log.debug("s : " + s); log.debug("c : " + ArrayUtils.toString(c)); log.debug("A : " + ArrayUtils.toString(A)); log.debug("b : " + ArrayUtils.toString(b)); log.debug("lb : " + ArrayUtils.toString(lb)); log.debug("ub : " + ArrayUtils.toString(ub)); //check consistency assertEquals(G.length, s); assertEquals(s + lpConverter.getOriginalN(), n); assertEquals(lb.length, n); assertEquals(ub.length, n); //check constraints RealMatrix GOrig = new Array2DRowRealMatrix(G); RealVector hOrig = new ArrayRealVector(h); RealMatrix AStandard = new Array2DRowRealMatrix(A); RealVector bStandard = new ArrayRealVector(b); RealVector expectedSolVector = new ArrayRealVector(expectedSol); RealVector Gxh = GOrig.operate(expectedSolVector).subtract(hOrig);//G.x - h RealVector slackVariables = new ArrayRealVector(s); for (int i = 0; i < s; i++) { slackVariables.setEntry(i, 0. - Gxh.getEntry(i));//the difference from 0 assertTrue(slackVariables.getEntry(i) >= 0.); } RealVector sol = slackVariables.append(expectedSolVector); RealVector Axmb = AStandard.operate(sol).subtract(bStandard); assertEquals(0., Axmb.getNorm(), expectedTolerance); // Utils.writeDoubleArrayToFile(new double[]{s}, "target" + File.separator + "standardS"+problemId+".txt"); // Utils.writeDoubleArrayToFile(c, "target" + File.separator + "standardC"+problemId+".txt"); // Utils.writeDoubleMatrixToFile(A, "target" + File.separator + "standardA"+problemId+".txt"); // Utils.writeDoubleArrayToFile(b, "target" + File.separator + "standardB"+problemId+".txt"); // Utils.writeDoubleArrayToFile(lb, "target" + File.separator + "standardLB"+problemId+".txt"); // Utils.writeDoubleArrayToFile(ub, "target" + File.separator + "standardUB"+problemId+".txt"); }
From source file:org.jax.maanova.plot.PlotUtil.java
/** * Get the index of the data point nearest to graphX, graphY. * @param xyData//from www .j av a 2 s. com * the data points to search through * @param graphX * the reference X point * @param graphY * the reference Y point * @return * the index of the nearest point or -1 if there is no such point */ public static int getNearestDataIndex(double[][] xyData, double graphX, double graphY) { int nearestIndex = -1; final double[] xData = xyData[0]; final double[] yData = xyData[1]; double nearestDistSq = Double.POSITIVE_INFINITY; for (int i = 0; i < xData.length; i++) { double currDistSq = Point2D.distanceSq(graphX, graphY, xData[i], yData[i]); if (currDistSq < nearestDistSq) { nearestDistSq = currDistSq; nearestIndex = i; } } return nearestIndex; }
From source file:com.analog.lyric.dimple.factorfunctions.Dirichlet.java
@Override public final double evalEnergy(Value[] arguments) { int index = 0; if (!_parametersConstant) { final double[] alpha = arguments[index++].getDoubleArray(); // First variable is array of parameter values _dimension = alpha.length;//from w w w.j a v a 2s . c o m _alphaMinusOne = new double[_dimension]; for (int i = 0; i < _dimension; i++) { final double alphai = alpha[i]; if (alphai <= 0) return Double.POSITIVE_INFINITY; _alphaMinusOne[i] = alphai - 1; } _logBetaAlpha = logBeta(alpha); } double sum = 0; final int length = arguments.length; final int N = length - index; // Number of non-parameter variables for (; index < length; index++) { final double[] x = arguments[index].getDoubleArray(); // Remaining inputs are Dirichlet distributed random variable vectors if (x.length != _dimension) throw new DimpleException( "Dimension of variable does not equal to the dimension of the parameter vector."); double xSum = 0; for (int i = 0; i < _dimension; i++) { final double xi = x[i]; if (xi <= 0) return Double.POSITIVE_INFINITY; else sum -= (_alphaMinusOne[i]) * Math.log(xi); // -log(x_i ^ (a_i-1)) xSum += xi; } if (!almostEqual(xSum, 1, SIMPLEX_THRESHOLD * _dimension)) // Values must be on the probability simplex return Double.POSITIVE_INFINITY; } return sum + N * _logBetaAlpha; }