List of usage examples for java.lang Double isInfinite
public static boolean isInfinite(double v)
From source file:it.unibo.alchemist.model.implementations.timedistributions.SAPEREExponentialTime.java
/** * @param rateEquation//from w w w . j a v a 2 s . c om * the rate equation * @param start * initial time * @param random * the {@link RandomGenerator} */ public SAPEREExponentialTime(final String rateEquation, final Time start, final RandomGenerator random) { super(Double.NaN, start, Objects.requireNonNull(random)); double temp = 0d; boolean numeric = true; try { temp = Double.parseDouble(Objects.requireNonNull(rateEquation)); } catch (NumberFormatException e) { numeric = false; } numericRate = numeric; staticRate = temp; if (numericRate) { if (Double.isInfinite(staticRate)) { exp = new Expression("asap"); } else { exp = new Expression(FORMAT.format(staticRate)); } } else { exp = new Expression(rateEquation); } }
From source file:org.briljantframework.complex.MutableComplex.java
public MutableComplex(double real, double imag) { this.real = real; this.imag = imag; this.isNaN = Double.isNaN(real) || Double.isNaN(imag); this.isInfinite = !isNaN && (Double.isInfinite(real) || Double.isInfinite(imag)); }
From source file:bb.mcmc.analysis.ESSConvergeStat.java
@Override protected boolean checkEachConverged(double stat, String key) { boolean isConverged = true; if (Double.isNaN(stat)) { System.err.println(STATISTIC_NAME + " could not be calculated for variable with id " + key + "(" + Double.NaN + "). Check log file for details. "); } else if (stat < essThreshold && !Double.isInfinite(stat)) {// || Double.isNaN(stat)) { isConverged = false;// w w w .j av a 2s. c o m } return isConverged; }
From source file:com.opengamma.analytics.math.interpolation.data.RadialBasisFunctionInterpolatorDataBundle.java
private double[] calculateWeights() { final List<Pair<double[], Double>> data = getData(); final int n = data.size(); double sum;//from w w w . ja v a 2 s . c om final double[][] radii = new double[n][n]; final double[] y = new double[n]; double phi; double[] x1, x2; final double zeroValue = _basisFunction.evaluate(0.0); for (int i = 0; i < n; i++) { x1 = data.get(i).getFirst(); radii[i][i] = zeroValue; for (int j = i + 1; j < n; j++) { x2 = data.get(j).getFirst(); phi = _basisFunction.evaluate(DistanceCalculator.getDistance(x1, x2)); Validate.isTrue(!Double.isNaN(phi) || !Double.isInfinite(phi), "basis function return invalide number"); radii[i][j] = phi; radii[j][i] = phi; // matrix symmetric since basis function depends on distance only } if (_useNormalized) { sum = 0.0; for (int j = 0; j < n; j++) { sum += radii[i][j]; } y[i] = sum * data.get(i).getSecond(); } else { y[i] = data.get(i).getSecond(); } } _decompRes = _decomp.evaluate(new com.opengamma.analytics.math.matrix.DoubleMatrix2D(radii)); final DoubleMatrix1D res = _decompRes.solve(new DoubleMatrix1D(y)); return res.toArray(); }
From source file:org.nd4j.linalg.api.ops.impl.transforms.Sigmoid.java
private double sigmoid(double input) { double inputf = input; double val = 1 / (1 + FastMath.exp(-inputf)); if (Nd4j.ENFORCE_NUMERICAL_STABILITY && (Double.isNaN(val) || Double.isInfinite(val))) { val = Nd4j.EPS_THRESHOLD; }//from w w w. j a va 2s. c o m return val; }
From source file:bb.mcmc.analysis.GewekeConvergeStat.java
@Override protected boolean checkEachConverged(double stat, String key) { boolean isConverged = true; if (Double.isNaN(stat)) { System.err.println(STATISTIC_NAME + " could not be calculated for variable with id " + key + "(" + Double.NaN + "). Geweke algorithm might not converged. Check log file for details. "); } else if (Math.abs(stat) > gewekeThreshold && !Double.isInfinite(stat)) { isConverged = false;/* w w w . j a v a 2 s.c o m*/ } return isConverged; }
From source file:com.opengamma.analytics.math.interpolation.MonotonicityPreservingQuinticSplineInterpolator.java
@Override public PiecewisePolynomialResult interpolate(final double[] xValues, final double[] yValues) { ArgumentChecker.notNull(xValues, "xValues"); ArgumentChecker.notNull(yValues, "yValues"); ArgumentChecker.isTrue(xValues.length == yValues.length | xValues.length + 2 == yValues.length, "(xValues length = yValues length) or (xValues length + 2 = yValues length)"); ArgumentChecker.isTrue(xValues.length > 2, "Data points should be more than 2"); final int nDataPts = xValues.length; final int yValuesLen = yValues.length; for (int i = 0; i < nDataPts; ++i) { ArgumentChecker.isFalse(Double.isNaN(xValues[i]), "xValues containing NaN"); ArgumentChecker.isFalse(Double.isInfinite(xValues[i]), "xValues containing Infinity"); }/* w w w. j av a 2s . com*/ for (int i = 0; i < yValuesLen; ++i) { ArgumentChecker.isFalse(Double.isNaN(yValues[i]), "yValues containing NaN"); ArgumentChecker.isFalse(Double.isInfinite(yValues[i]), "yValues containing Infinity"); } for (int i = 0; i < nDataPts - 1; ++i) { for (int j = i + 1; j < nDataPts; ++j) { ArgumentChecker.isFalse(xValues[i] == xValues[j], "xValues should be distinct"); } } double[] xValuesSrt = Arrays.copyOf(xValues, nDataPts); double[] yValuesSrt = new double[nDataPts]; if (nDataPts == yValuesLen) { yValuesSrt = Arrays.copyOf(yValues, nDataPts); } else { yValuesSrt = Arrays.copyOfRange(yValues, 1, nDataPts + 1); } ParallelArrayBinarySort.parallelBinarySort(xValuesSrt, yValuesSrt); final double[] intervals = _solver.intervalsCalculator(xValuesSrt); final double[] slopes = _solver.slopesCalculator(yValuesSrt, intervals); final PiecewisePolynomialResult result = _method.interpolate(xValues, yValues); ArgumentChecker.isTrue(result.getOrder() >= 3, "Primary interpolant should be degree >= 2"); final double[] initialFirst = _function.differentiate(result, xValuesSrt).getData()[0]; final double[] initialSecond = _function.differentiateTwice(result, xValuesSrt).getData()[0]; double[] first = firstDerivativeCalculator(yValuesSrt, intervals, slopes, initialFirst); boolean modFirst = false; int k; double[] aValues = aValuesCalculator(slopes, first); double[] bValues = bValuesCalculator(slopes, first); double[][] intervalsA = getIntervalsA(intervals, slopes, first, bValues); double[][] intervalsB = getIntervalsB(intervals, slopes, first, aValues); while (modFirst == false) { k = 0; for (int i = 0; i < nDataPts - 2; ++i) { if (first[i + 1] > 0.) { if (intervalsA[i + 1][1] + Math.abs(intervalsA[i + 1][1]) * ERROR < intervalsB[i][0] - Math.abs(intervalsB[i][0]) * ERROR | intervalsA[i + 1][0] - Math.abs(intervalsA[i + 1][0]) * ERROR > intervalsB[i][1] + Math.abs(intervalsB[i][1]) * ERROR) { ++k; first[i + 1] = firstDerivativesRecalculator(intervals, slopes, aValues, bValues, i + 1); } } } if (k == 0) { modFirst = true; } aValues = aValuesCalculator(slopes, first); bValues = bValuesCalculator(slopes, first); intervalsA = getIntervalsA(intervals, slopes, first, bValues); intervalsB = getIntervalsB(intervals, slopes, first, aValues); } final double[] second = secondDerivativeCalculator(initialSecond, intervalsA, intervalsB); final double[][] coefs = _solver.solve(yValuesSrt, intervals, slopes, first, second); for (int i = 0; i < nDataPts - 1; ++i) { for (int j = 0; j < 6; ++j) { ArgumentChecker.isFalse(Double.isNaN(coefs[i][j]), "Too large input"); ArgumentChecker.isFalse(Double.isInfinite(coefs[i][j]), "Too large input"); } } return new PiecewisePolynomialResult(new DoubleMatrix1D(xValuesSrt), new DoubleMatrix2D(coefs), 6, 1); }
From source file:org.kordamp.ezmorph.primitive.BooleanMorpher.java
/** * Morphs the input object into an output object of the supported type. * * @param value The input value to be morphed * @throws MorphException if conversion cannot be performed successfully */// www.j a v a2 s . c om public boolean morph(Object value) { if (value == null) { if (isUseDefault()) { return defaultValue; } else { throw new MorphException("value is null"); } } if (value instanceof Boolean) { return ((Boolean) value).booleanValue(); } else if (value instanceof Number) { if (value instanceof Double && (Double.isInfinite(((Number) value).doubleValue()) || Double.isNaN(((Number) value).doubleValue()))) { return true; } if (value instanceof Float && (Float.isInfinite(((Number) value).floatValue()) || Float.isNaN(((Number) value).floatValue()))) { return true; } long l = ((Number) value).longValue(); return l != 0; } else { String s = String.valueOf(value); if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("on")) { return true; } else if (s.equalsIgnoreCase("false") || s.equalsIgnoreCase("no") || s.equalsIgnoreCase("off")) { return false; } else if (isUseDefault()) { return defaultValue; } } throw new MorphException("Can't morph value: " + value); }
From source file:net.openhft.chronicle.timeseries.Columns.java
private static void generateBrownian(DoubleColumn col, long first, double start, double end, NormalDistribution nd, RandomGenerator rand) { double x = start; int chunkSize = (int) Math.min(col.length() - first, CHUNK_SIZE); for (int i = 0; i < chunkSize; i++) { col.set(first + i, x);//from w ww .j a va2 s. co m double p = rand.nextFloat() + 0.5 / (1 << 24); double v = nd.inverseCumulativeProbability(p); x += v; assert !Double.isInfinite(x); } double diff = end - x; double gradient = diff / chunkSize; for (int i = 0; i < chunkSize; i++) { col.add(first + i, i * gradient); } }
From source file:mase.mason.generic.systematic.SystematicStandardiser.java
@Override public void processPopulation(EvolutionState state) { // TODO: needs different mechanisms for shared and individual archives // initialization if (archives == null) { PostEvaluator[] evals = ((MetaEvaluator) state.evaluator).getPostEvaluators(); for (PostEvaluator pe : evals) { if (pe instanceof NoveltyEvaluation) { NoveltyEvaluation ne = (NoveltyEvaluation) pe; archives = ne.getArchives(); behavIndex = ne.getBehaviourIndex(); }/*from w ww . j a v a 2 s . c om*/ } } // join all behaviour results in one list // from archive ArrayList<SystematicResult> results = new ArrayList<>(2000); for (ArchiveEntry ar : archives[0]) { results.add((SystematicResult) ar.getBehaviour()); } // from the population for (Subpopulation sub : state.population.subpops) { for (Individual ind : sub.individuals) { ExpandedFitness nf = (ExpandedFitness) ind.fitness; results.add((SystematicResult) nf.getCorrespondingEvaluation(behavIndex)); } } // calculate mean and sd for each feature int size = results.get(0).getOriginalResult().length; DescriptiveStatistics[] ds = new DescriptiveStatistics[size]; for (int i = 0; i < size; i++) { ds[i] = new DescriptiveStatistics(); for (SystematicResult vbr : results) { ds[i].addValue(vbr.getOriginalResult()[i]); } } double[] means = new double[size]; double[] sds = new double[size]; for (int i = 0; i < size; i++) { means[i] = ds[i].getMean(); double sd = ds[i].getStandardDeviation(); sds[i] = sd == 0 || Double.isNaN(sd) || Double.isInfinite(sd) ? 1 : sd; } for (SystematicResult vbr : results) { for (int i = 0; i < size; i++) { double v = (vbr.getOriginalResult()[i] - means[i]) / sds[i]; vbr.getBehaviour()[i] = (float) Math.max(-BOUND, Math.min(BOUND, v)); } } }