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:de.unijena.bioinf.FragmentationTreeConstruction.computation.FragmentationPatternAnalysis.java
protected FGraph scoreGraph(FGraph graph) { // score graph final Iterator<Loss> edges = graph.lossIterator(); final ProcessedInput input = graph.getAnnotationOrThrow(ProcessedInput.class); final Scoring scoring = input.getAnnotationOrThrow(Scoring.class); final double[] peakScores = scoring.getPeakScores(); final double[][] peakPairScores = scoring.getPeakPairScores(); final LossScorer[] lossScorers = this.lossScorers.toArray(new LossScorer[this.lossScorers.size()]); final Object[] precomputeds = new Object[lossScorers.length]; final ScoredFormulaMap map = graph.getAnnotationOrThrow(ScoredFormulaMap.class); final FragmentAnnotation<ProcessedPeak> peakAno = graph.getFragmentAnnotationOrThrow(ProcessedPeak.class); for (int i = 0; i < precomputeds.length; ++i) precomputeds[i] = lossScorers[i].prepare(input); while (edges.hasNext()) { final Loss loss = edges.next(); final Fragment u = loss.getSource(); final Fragment v = loss.getTarget(); // take score of molecular formula double score = map.get(v.getFormula()); assert !Double.isInfinite(score); // add it to score of the peak score += peakScores[peakAno.get(v).getIndex()]; assert !Double.isInfinite(score); // add it to the score of the peak pairs if (!u.isRoot()) score += peakPairScores[peakAno.get(u).getIndex()][peakAno.get(v).getIndex()]; // TODO: Umdrehen! assert !Double.isInfinite(score); // add the score of the loss if (!u.isRoot()) for (int i = 0; i < lossScorers.length; ++i) score += lossScorers[i].score(loss, input, precomputeds[i]); assert !Double.isInfinite(score); loss.setWeight(score);/*from w ww . ja va 2s . c o m*/ } if (reduction != null) reduction.reduce(graph, Double.NEGATIVE_INFINITY); // TODO: implement lowerbound //assert false; return graph; }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the range of z-values in the specified dataset for the * data items belonging to the visible series and with x-values in the * given range./*w w w . j a va 2s .co m*/ * * @param dataset the dataset ({@code null} not permitted). * @param visibleSeriesKeys the visible series keys ({@code null} not * permitted). * @param xRange the x-range ({@code null} not permitted). * @param includeInterval a flag that determines whether or not the * z-interval for the dataset is included (this only applies if the * dataset has an interval, which is currently not supported). * * @return The y-range (possibly {@code null}). */ public static Range iterateToFindZBounds(XYZDataset dataset, List visibleSeriesKeys, Range xRange, boolean includeInterval) { Args.nullNotPermitted(dataset, "dataset"); Args.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys"); Args.nullNotPermitted(xRange, "xRange"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = dataset.getXValue(series, item); double z = dataset.getZValue(series, item); if (xRange.contains(x)) { if (!Double.isNaN(z)) { minimum = Math.min(minimum, z); maximum = Math.max(maximum, z); } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } }
From source file:com.opengamma.analytics.financial.model.volatility.BlackScholesFormulaRepository.java
/** * The rho, the derivative of the option value with respect to the risk free interest rate * Note that costOfCarry = interestRate - dividend, which the derivative also acts on * @param spot The spot value of the underlying * @param strike The strike//from w w w . jav a 2 s .c o m * @param timeToExpiry The time to expiry * @param lognormalVol The log-normal volatility * @param interestRate The interest rate * @param costOfCarry The cost of carry * @param isCall True for call * @return The rho */ @ExternalFunction public static double rho(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"); double discount = 0.; if (-interestRate > LARGE) { return isCall ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY; } if (interestRate > LARGE) { return 0.; } discount = (Math.abs(interestRate) < SMALL && timeToExpiry > LARGE) ? 1. : Math.exp(-interestRate * timeToExpiry); if (LARGE * spot < strike || timeToExpiry > LARGE) { final double res = isCall ? 0. : -discount * strike * timeToExpiry; return Double.isNaN(res) ? -discount : res; } if (spot > LARGE * strike || timeToExpiry < SMALL) { final double res = isCall ? discount * strike * timeToExpiry : 0.; return Double.isNaN(res) ? discount : res; } final int sign = isCall ? 1 : -1; final double rootT = Math.sqrt(timeToExpiry); double sigmaRootT = lognormalVol * rootT; double factor = Math.exp(costOfCarry * timeToExpiry); double rescaledSpot = spot * factor; double d2 = 0.; if (Math.abs(spot - strike) < SMALL || sigmaRootT > LARGE || (spot > LARGE && strike > LARGE)) { final double coefD1 = (costOfCarry / lognormalVol - 0.5 * lognormalVol); final double tmp = coefD1 * rootT; d2 = Double.isNaN(tmp) ? 0. : tmp; } else { if (sigmaRootT < SMALL) { return isCall ? (rescaledSpot > strike ? discount * strike * timeToExpiry : 0.) : (rescaledSpot < strike ? -discount * strike * timeToExpiry : 0.); } 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; d2 = Math.log(spot / strike) / sigmaRootT + scnd - 0.5 * sigmaRootT; } // if (Double.isNaN(d2)) { // throw new IllegalArgumentException("NaN found"); // } final double norm = NORMAL.getCDF(sign * d2); final double result = norm < SMALL ? 0. : sign * discount * strike * timeToExpiry * norm; return Double.isNaN(result) ? sign * discount : result; }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the range of z-values in the specified dataset for the * data items belonging to the visible series and with x-values in the * given range./*from w w w. j a v a2 s .co m*/ * * @param dataset the dataset (<code>null</code> not permitted). * @param visibleSeriesKeys the visible series keys (<code>null</code> not * permitted). * @param xRange the x-range (<code>null</code> not permitted). * @param includeInterval a flag that determines whether or not the * z-interval for the dataset is included (this only applies if the * dataset has an interval, which is currently not supported). * * @return The y-range (possibly <code>null</code>). */ public static Range iterateToFindZBounds(XYZDataset dataset, List visibleSeriesKeys, Range xRange, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys"); ParamChecks.nullNotPermitted(xRange, "xRange"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = dataset.getXValue(series, item); double z = dataset.getZValue(series, item); if (xRange.contains(x)) { if (!Double.isNaN(z)) { minimum = Math.min(minimum, z); maximum = Math.max(maximum, z); } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the maximum domain value for the specified dataset. This is * easy if the dataset implements the {@link DomainInfo} interface (a good * idea if there is an efficient way to determine the maximum value). * Otherwise, it involves iterating over the entire data-set. Returns * {@code null} if all the data values in the dataset are * {@code null}.//ww w. j a v a 2 s . c o m * * @param dataset the dataset ({@code null} not permitted). * * @return The maximum value (possibly {@code null}). */ public static Number findMaximumDomainValue(XYDataset dataset) { Args.nullNotPermitted(dataset, "dataset"); Number result; // if the dataset implements DomainInfo, life is easy if (dataset instanceof DomainInfo) { DomainInfo info = (DomainInfo) dataset; return new Double(info.getDomainUpperBound(true)); } // hasn't implemented DomainInfo, so iterate... else { double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value; if (dataset instanceof IntervalXYDataset) { IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; value = intervalXYData.getEndXValue(series, item); } else { value = dataset.getXValue(series, item); } if (!Double.isNaN(value)) { maximum = Math.max(maximum, value); } } } if (maximum == Double.NEGATIVE_INFINITY) { result = null; } else { result = new Double(maximum); } } return result; }
From source file:com.opengamma.analytics.financial.model.volatility.BlackScholesFormulaRepository.java
/** * The carry rho, the derivative of the option value with respect to the cost of carry * Note that costOfCarry = interestRate - dividend, which the derivative also acts on * @param spot The spot value of the underlying * @param strike The strike// w ww . j av a2s . c o m * @param timeToExpiry The time to expiry * @param lognormalVol The log-normal volatility * @param interestRate The interest rate * @param costOfCarry The cost of carry * @param isCall True for call * @return The carry rho */ @ExternalFunction public static double carryRho(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"); double coef = 0.; if ((interestRate > LARGE && costOfCarry > LARGE) || (-interestRate > LARGE && -costOfCarry > LARGE) || Math.abs(costOfCarry - interestRate) < SMALL) { coef = 1.; //ref value is returned } else { final double rate = costOfCarry - interestRate; if (rate > LARGE) { return isCall ? Double.POSITIVE_INFINITY : (costOfCarry > LARGE ? 0. : Double.NEGATIVE_INFINITY); } if (-rate > LARGE) { return 0.; } coef = Math.exp(rate * timeToExpiry); } if (spot > LARGE * strike || timeToExpiry > LARGE) { final double res = isCall ? coef * spot * timeToExpiry : 0.; return Double.isNaN(res) ? coef : res; } if (LARGE * spot < strike || timeToExpiry < SMALL) { final double res = isCall ? 0. : -coef * spot * timeToExpiry; return Double.isNaN(res) ? -coef : res; } final int sign = isCall ? 1 : -1; final double rootT = Math.sqrt(timeToExpiry); double sigmaRootT = lognormalVol * rootT; double factor = Math.exp(costOfCarry * timeToExpiry); double rescaledSpot = spot * factor; double d1 = 0.; if (Math.abs(spot - strike) < SMALL || sigmaRootT > LARGE || (spot > LARGE && strike > LARGE)) { final double coefD1 = (costOfCarry / lognormalVol + 0.5 * lognormalVol); final double tmp = coefD1 * rootT; d1 = Double.isNaN(tmp) ? 0. : tmp; } else { if (sigmaRootT < SMALL) { return isCall ? (rescaledSpot > strike ? coef * timeToExpiry * spot : 0.) : (rescaledSpot < strike ? -coef * timeToExpiry * spot : 0.); } 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; } // if (Double.isNaN(d1)) { // throw new IllegalArgumentException("NaN found"); // } final double norm = NORMAL.getCDF(sign * d1); final double result = norm < SMALL ? 0. : sign * coef * timeToExpiry * spot * norm; return Double.isNaN(result) ? sign * coef : result; }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the maximum domain value for the specified dataset. This is * easy if the dataset implements the {@link DomainInfo} interface (a good * idea if there is an efficient way to determine the maximum value). * Otherwise, it involves iterating over the entire data-set. Returns * <code>null</code> if all the data values in the dataset are * <code>null</code>./*from w w w. ja va2 s .c o m*/ * * @param dataset the dataset (<code>null</code> not permitted). * * @return The maximum value (possibly <code>null</code>). */ public static Number findMaximumDomainValue(XYDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); Number result; // if the dataset implements DomainInfo, life is easy if (dataset instanceof DomainInfo) { DomainInfo info = (DomainInfo) dataset; return new Double(info.getDomainUpperBound(true)); } // hasn't implemented DomainInfo, so iterate... else { double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value; if (dataset instanceof IntervalXYDataset) { IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; value = intervalXYData.getEndXValue(series, item); } else { value = dataset.getXValue(series, item); } if (!Double.isNaN(value)) { maximum = Math.max(maximum, value); } } } if (maximum == Double.NEGATIVE_INFINITY) { result = null; } else { result = new Double(maximum); } } return result; }
From source file:edu.cmu.tetrad.search.Lofs2.java
private double max(double[] x) { double max = Double.NEGATIVE_INFINITY; for (double _x : x) { if (_x > max) max = _x;// ww w . java2s.c o m } return max; }
From source file:gdsc.smlm.ij.plugins.CreateData.java
/** * Create a PSF model from the image that contains all the z-slices needed to draw the given localisations * /*from w w w .j ava2 s. co m*/ * @param localisationSets * @return */ private ImagePSFModel createImagePSF(List<LocalisationModelSet> localisationSets) { ImagePlus imp = WindowManager.getImage(settings.psfImageName); if (imp == null) { IJ.error(TITLE, "Unable to create the PSF model from image: " + settings.psfImageName); return null; } try { Object o = XmlUtils.fromXML(imp.getProperty("Info").toString()); if (!(o != null && o instanceof PSFSettings)) throw new RuntimeException("Unknown PSF settings for image: " + imp.getTitle()); PSFSettings psfSettings = (PSFSettings) o; // Check all the settings have values if (psfSettings.nmPerPixel <= 0) throw new RuntimeException("Missing nmPerPixel calibration settings for image: " + imp.getTitle()); if (psfSettings.nmPerSlice <= 0) throw new RuntimeException("Missing nmPerSlice calibration settings for image: " + imp.getTitle()); if (psfSettings.zCentre <= 0) throw new RuntimeException("Missing zCentre calibration settings for image: " + imp.getTitle()); if (psfSettings.fwhm <= 0) throw new RuntimeException("Missing FWHM calibration settings for image: " + imp.getTitle()); // To save memory construct the Image PSF using only the slices that are within // the depth of field of the simulation double minZ = Double.POSITIVE_INFINITY, maxZ = Double.NEGATIVE_INFINITY; for (LocalisationModelSet l : localisationSets) { for (LocalisationModel m : l.getLocalisations()) { final double z = m.getZ(); if (minZ > z) minZ = z; if (maxZ < z) maxZ = z; } } int nSlices = imp.getStackSize(); // z-centre should be an index and not the ImageJ slice number so subtract 1 int zCentre = psfSettings.zCentre - 1; // Calculate the start/end slices to cover the depth of field // This logic must match the ImagePSFModel. final double unitsPerSlice = psfSettings.nmPerSlice / settings.pixelPitch; // We assume the PSF was imaged axially with increasing z-stage position (moving the stage // closer to the objective). Thus we invert the z-coordinate to find the appropriate slice. int upper = (int) Math.round(-minZ / unitsPerSlice) + zCentre; int lower = (int) Math.round(-maxZ / unitsPerSlice) + zCentre; upper = (upper < 0) ? 0 : (upper >= nSlices) ? nSlices - 1 : upper; lower = (lower < 0) ? 0 : (lower >= nSlices) ? nSlices - 1 : lower; // We cannot just extract the correct slices since the // Image PSF requires the z-centre for normalisation if (!(lower <= zCentre && upper >= zCentre)) { // Ensure we include the zCentre lower = Math.min(lower, zCentre); upper = Math.max(upper, zCentre); } return new ImagePSFModel(extractImageStack(imp, lower, upper), zCentre - lower, psfSettings.nmPerPixel / settings.pixelPitch, unitsPerSlice, psfSettings.fwhm); } catch (Exception e) { IJ.error(TITLE, "Unable to create the image PSF model:\n" + e.getMessage()); return null; } }
From source file:jp.furplag.util.commons.NumberUtilsTest.java
/** * {@link jp.furplag.util.commons.NumberUtils#valueOf(java.lang.Object)}. *//*from w w w . j a va 2s . c om*/ @SuppressWarnings("unchecked") @Test public void testValueOfObject() { try { for (Class<?> type : NUMBERS) { Object o = null; Object expected = null; Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type); assertEquals("null", expected, valueOf(null)); o = Float.NaN; expected = o; assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected, valueOf(o)); o = Double.NaN; expected = o; assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected, valueOf(o)); if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) { o = wrapper.getMethod("valueOf", String.class).invoke(null, "123.456"); } else if (ClassUtils.isPrimitiveWrapper(wrapper)) { o = wrapper.getMethod("valueOf", String.class).invoke(null, "123"); } else { Constructor<?> c = type.getDeclaredConstructor(String.class); o = c.newInstance(BigInteger.class.equals(type) ? "123" : "123.456"); } expected = o; assertEquals(o + "(" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), expected, valueOf(o)); o = INFINITY_DOUBLE.pow(2); expected = o; assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), o, valueOf(o)); o = INFINITY_DOUBLE.pow(2).negate(); expected = o; assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), o, valueOf(o)); o = INFINITY_DOUBLE.pow(2).toBigInteger(); expected = o; assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), o, valueOf(o)); o = INFINITY_DOUBLE.pow(2).toBigInteger().negate(); expected = o; assertEquals("Huge: (" + o.getClass().getSimpleName() + "): " + type.getSimpleName(), o, valueOf(o)); o = ""; expected = null; assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o)); o = "not a number."; assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o)); o = new Object[] { 1, 2, 3 }; assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o)); o = "NaN"; expected = Double.NaN; assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o)); o = "Infinity"; expected = Double.POSITIVE_INFINITY; assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o)); o = "-Infinity"; expected = Double.NEGATIVE_INFINITY; assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o)); o = "123.456f"; expected = (Float) 123.456f; assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o)); o = "123.456d"; expected = (Double) 123.456d; assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o)); o = "1.23456E2d"; expected = (Double) 123.456d; assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o)); o = "1.23456E+2d"; expected = (Double) 123.456d; assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o)); o = "1000000000000"; expected = 1000000000000L; assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o)); o = "1E12"; expected = (Float) 1000000000000f; assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o)); o = "1E600"; expected = new BigDecimal("1E600"); assertEquals("\"" + o + "\": " + type.getSimpleName(), expected, valueOf(o)); } } catch (Exception e) { e.printStackTrace(); fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace())); } }