List of usage examples for java.lang Double MAX_VALUE
double MAX_VALUE
To view the source code for java.lang Double MAX_VALUE.
Click Source Link
From source file:eu.crisis_economics.abm.algorithms.statistics.TestFloorInterpolator.java
/** * Test whether an instance of {@link FloorInterpolator} interpolates * a simple discrete input series as expected. This unit test operates * as follows:<br><br>//from ww w . j ava2 s. c om * * {@code (a)} * A short discrete subsequence of the function {@code f(T) = T**2} * is generated;<br> * {@code (b)} * An instance of {@link FloorInterpolator} is used to create a * {@link UnivariateFunction}, {@code U}, from this sequence;<br> * {@code (c)} * {@code U} is sampled repeatedly for a number of points in the domain * of the input sequence. The results of this operation are compared * to correct, expected outputs. */ @Test public void testFloorInterpolatorOutput() { final double[] x = new double[] { 2., 3., 4., 5., 6., }, y = new double[] { 4., 9., 16., 25., 36., }; final double[] expectedResults = { -Double.MAX_VALUE, 4.000000000, Double.MIN_VALUE, 4.000000000, 1.000000000, 4.000000000, 1.111111111, 4.000000000, 1.222222222, 4.000000000, 1.333333333, 4.000000000, 1.444444444, 4.000000000, 1.555555556, 4.000000000, 1.666666667, 4.000000000, 1.777777778, 4.000000000, 1.888888889, 4.000000000, 2.000000000, 4.000000000, 2.111111111, 4.000000000, 2.222222222, 4.000000000, 2.333333333, 4.000000000, 2.444444444, 4.000000000, 2.555555556, 4.000000000, 2.666666667, 4.000000000, 2.777777778, 4.000000000, 2.888888889, 4.000000000, 3.000000000, 9.000000000, 3.111111111, 9.000000000, 3.222222222, 9.000000000, 3.333333333, 9.000000000, 3.444444444, 9.000000000, 3.555555556, 9.000000000, 3.666666667, 9.000000000, 3.777777778, 9.000000000, 3.888888889, 9.000000000, 4.000000000, 16.00000000, 4.111111111, 16.00000000, 4.222222222, 16.00000000, 4.333333333, 16.00000000, 4.444444444, 16.00000000, 4.555555556, 16.00000000, 4.666666667, 16.00000000, 4.777777778, 16.00000000, 4.888888889, 16.00000000, 5.000000000, 25.00000000, 5.111111111, 25.00000000, 5.222222222, 25.00000000, 5.333333333, 25.00000000, 5.444444444, 25.00000000, 5.555555556, 25.00000000, 5.666666667, 25.00000000, 5.777777778, 25.00000000, 5.888888889, 25.00000000, 6.000000000, 36.00000000, 6.111111111, 36.00000000, 6.222222222, 36.00000000, 6.333333333, 36.00000000, 6.444444444, 36.00000000, 6.555555556, 36.00000000, 6.666666667, 36.00000000, 6.777777778, 36.00000000, 6.888888889, 36.00000000, 7.000000000, 36.00000000, 7.111111111, 36.00000000, 7.222222222, 36.00000000, 7.333333333, 36.00000000, 7.444444444, 36.00000000, 7.555555556, 36.00000000, 7.666666667, 36.00000000, 7.777777778, 36.00000000, 7.888888889, 36.00000000, 8.000000000, 36.00000000, 8.111111111, 36.00000000, 8.222222222, 36.00000000, 8.333333333, 36.00000000, 8.444444444, 36.00000000, 8.555555556, 36.00000000, 8.666666667, 36.00000000, 8.777777778, 36.00000000, 8.888888889, 36.00000000, 9.000000000, 36.00000000, 9.111111111, 36.00000000, 9.222222222, 36.00000000, 9.333333333, 36.00000000, 9.444444444, 36.00000000, 9.555555556, 36.00000000, 9.666666667, 36.00000000, 9.777777778, 36.00000000, 9.888888889, 36.00000000, 10.00000000, 36.00000000, 10.11111111, 36.00000000, 10.22222222, 36.00000000, 10.33333333, 36.00000000, 10.44444444, 36.00000000, 10.55555556, 36.00000000, 10.66666667, 36.00000000, 10.77777778, 36.00000000, 10.88888889, 36.00000000, 11.00000000, 36.00000000, 11.11111111, 36.00000000, 11.22222222, 36.00000000, 11.33333333, 36.00000000, 11.44444444, 36.00000000, 11.55555556, 36.00000000, 11.66666667, 36.00000000, 11.77777778, 36.00000000, 11.88888889, 36.00000000, 12.00000000, 36.00000000, Double.MAX_VALUE, 36.00000000 }; final UnivariateInterpolator interpolator = new FloorInterpolator(); final UnivariateFunction f = interpolator.interpolate(x, y); for (int i = 0; i < expectedResults.length; i += 2) { final double t = expectedResults[i], f_t_Observed = f.value(t), f_t_Expected = expectedResults[i + 1]; System.out.printf("t: %16.10g observed: %16.10g expected: %16.10g\n", t, f_t_Observed, f_t_Expected); Assert.assertEquals(f_t_Observed, f_t_Expected, 1.e-12); } }
From source file:com.opensymphony.xwork2.conversion.impl.StringConverterTest.java
public void testDoubleToStringConversionPL() throws Exception { // given/*from w ww.j a v a 2 s. co m*/ StringConverter converter = new StringConverter(); Map<String, Object> context = new HashMap<>(); context.put(ActionContext.LOCALE, new Locale("pl", "PL")); // when has max fraction digits Object value = converter.convertValue(context, null, null, null, Double.MIN_VALUE, null); // then does not lose fraction digits assertEquals("0," + StringUtils.repeat('0', 323) + "49", value); // when has max integer digits value = converter.convertValue(context, null, null, null, Double.MAX_VALUE, null); // then does not lose integer digits assertEquals("17976931348623157" + StringUtils.repeat('0', 292), value); // when cannot be represented exactly with a finite binary number value = converter.convertValue(context, null, null, null, 0.1d, null); // then produce the shortest decimal representation that can unambiguously identify the true value of the floating-point number assertEquals("0,1", value); }
From source file:edu.oregonstate.eecs.mcplan.ml.GaussianMixtureModel.java
/** * @param args/*from w w w .j a v a 2 s . c o m*/ */ public static void main(final String[] args) { final RandomGenerator rng = new MersenneTwister(42); final ArrayList<double[]> data = new ArrayList<double[]>(); // This data displays some problems with singular covariance estimates, // perhaps due to "multicollinearity" in the data. // for( int x = -1; x <= 1; ++x ) { // for( int y = -1; y <= 1; ++y ) { // data.add( new double[] { x, y } ); // data.add( new double[] { x + 10, y + 10} ); // data.add( new double[] { x + 20, y + 20} ); // data.add( new double[] { x + 30, y + 30} ); // } // } final int nsamples = 1000; final double[][] mu = new double[][] { new double[] { 0, 0 }, new double[] { 5, 0 }, new double[] { 0, 5 }, new double[] { 5, 5 } }; final double[][] Sigma = new double[][] { new double[] { 1, 0 }, new double[] { 0, 1 } }; final MultivariateNormalDistribution[] p = new MultivariateNormalDistribution[4]; for (int i = 0; i < 4; ++i) { p[i] = new MultivariateNormalDistribution(rng, mu[i], Sigma); } for (int i = 0; i < nsamples; ++i) { final int c = rng.nextInt(4); final double[] x = p[c].sample(); data.add(x); } // Perturb data // for( final double[] x : data ) { // for( int i = 0; i < x.length; ++i ) { // final double r = rng.nextGaussian() / 1.0; // x[i] += r; // } // } double best_bic = Double.MAX_VALUE; int best_k = 0; for (int k = 1; k <= 6; ++k) { System.out.println("*** k = " + k); final GaussianMixtureModel gmm = new GaussianMixtureModel(k, data.toArray(new double[data.size()][]), 10e-5, rng); gmm.run(); for (int i = 0; i < gmm.mu().length; ++i) { System.out.println("Center " + i + ": " + gmm.mu()[i]); } final double bic = ScoreFunctions.bic(data.size(), gmm.nparameters(), gmm.logLikelihood()); System.out.println("BIC = " + bic); System.out.println("ll = " + gmm.logLikelihood()); gmm.debug(); if (bic < best_bic) { best_bic = bic; best_k = k; } } System.out.println("Best model: k = " + best_k); }
From source file:net.openhft.smoothie.MathDecisions.java
private static void printFootprints(int min, int max, int refSize) { System.out.println("Footprints:"); for (int i = min; i <= max; i++) { System.out.println("average entries/segment: " + i + " " + " double: " + footprint(i, refSize, 1) + " quad: " + footprint(i, refSize, 2)); }// w ww . j a va 2s . c o m System.out.println("Footprint if size not specified:"); double minF = Double.MAX_VALUE, maxF = Double.MIN_VALUE; int minE = 0, maxE = 0; int maxCap = cap(max, refSize); for (int i = maxCap / 2; i <= maxCap; i++) { double f = footprint(i, refSize, 1, maxCap); if (f < minF) { minF = f; minE = i; } if (f > maxF) { maxF = f; maxE = i; } } System.out.println("Best case: " + refSize + ": " + minE + " " + minF); System.out.println("Worst case: " + refSize + ": " + maxE + " " + maxF); }
From source file:edu.cuny.qc.speech.AuToBI.core.Aggregation.java
/** * Constructs a new Aggregation/*from w w w . ja v a 2 s. c o m*/ */ public Aggregation() { this.label = ""; this.min = Double.MAX_VALUE; this.max = -Double.MAX_VALUE; this.sum = 0.0; this.ssq = 0.0; this.n = 0; }
From source file:com.opengamma.analytics.math.minimization.BrentMinimizer1D.java
/** * {@inheritDoc}//from w w w .j av a2 s .c om */ @Override public Double minimize(final Function1D<Double, Double> function, final Double startPosition) { Validate.notNull(function, "function"); final UnivariateRealFunction commonsFunction = CommonsMathWrapper.wrapUnivariate(function); try { return OPTIMIZER.optimize(commonsFunction, MINIMIZE, -Double.MAX_VALUE, Double.MAX_VALUE, startPosition); } catch (final FunctionEvaluationException e) { throw new MathException(e); } catch (final org.apache.commons.math.ConvergenceException e) { throw new MathException(e); } }
From source file:gov.va.isaac.gui.listview.operations.ParentReplace.java
@Override public void init(ObservableList<SimpleDisplayConcept> conceptList) { super.init(conceptList); root_.add(new Label("Replace: "), 0, 0); replaceOptions_ = new ComboBox<>(); replaceOptions_.setMaxWidth(Double.MAX_VALUE); replaceOptions_.setPromptText("-Populate the Concepts List-"); root_.add(ErrorMarkerUtils.setupErrorMarker(replaceOptions_, replaceOptionsInvalidString_), 1, 0); ComboBoxSetupTool.setupComboBox(replaceOptions_); root_.add(new Label("With Parent: "), 0, 1); withConcept_ = new ConceptNode(null, true); root_.add(withConcept_.getNode(), 1, 1); GridPane.setHgrow(withConcept_.getNode(), Priority.ALWAYS); FxUtils.preventColCollapse(root_, 0); initActionListeners();//from w w w. jav a2 s . c om replaceOptions_.getItems().addAll(conceptList); }
From source file:com.basetechnology.s0.agentserver.field.FloatField.java
public static Field fromJson(SymbolTable symbolTable, JSONObject fieldJson) { String type = fieldJson.optString("type"); if (type == null || !type.equals("float")) return null; String name = fieldJson.has("name") ? fieldJson.optString("name") : null; String label = fieldJson.has("label") ? fieldJson.optString("label") : null; String description = fieldJson.has("description") ? fieldJson.optString("description") : null; double defaultValue = fieldJson.has("default_value") ? fieldJson.optDouble("default_value") : 0; double minValue = fieldJson.has("min_value") ? fieldJson.optDouble("min_value") : Double.MIN_VALUE; double maxValue = fieldJson.has("max_value") ? fieldJson.optDouble("max_value") : Double.MAX_VALUE; int nominalWidth = fieldJson.has("nominal_width") ? fieldJson.optInt("nominal_width") : 0; String compute = fieldJson.has("compute") ? fieldJson.optString("compute") : null; return new FloatField(symbolTable, name, label, description, defaultValue, minValue, maxValue, nominalWidth, compute);//from ww w.j a v a 2s .c om }
From source file:edu.utexas.cs.tactex.subscriptionspredictors.LWRCustOldAppache.java
/** * @param candidateEval/* w ww. j a va2 s . c o m*/ * @param e2n * @return */ @Override public Double predictNumSubs(double candidateEval, TreeMap<Double, Double> e2n, CustomerInfo customer, int timeslot) { // tree map guarantees that keys are unique // so we are suppose to be able to run LWR // if there are at least 3 entries (even 2) // LWR, run n-fold cross validation with different bandwidth double min = e2n.firstKey(); double max = e2n.lastKey(); ArrayRealVector xVec = createNormalizedXVector(e2n.keySet(), min, max); ArrayRealVector yVec = createYVector(e2n.values()); double bestTau = Double.MAX_VALUE; double bestMSE = Double.MAX_VALUE; ArrayList<Double> candidateTaus = new ArrayList<Double>(); //candidateTaus.add(0.025 * SQUEEZE); candidateTaus.add(0.05);// * SQUEEZE); candidateTaus.add(0.1);// * SQUEEZE); candidateTaus.add(0.2);// * SQUEEZE); candidateTaus.add(0.3);// * SQUEEZE); candidateTaus.add(0.4);// * SQUEEZE); candidateTaus.add(0.5);// * SQUEEZE); candidateTaus.add(0.6);// * SQUEEZE); candidateTaus.add(0.7);// * SQUEEZE); candidateTaus.add(0.8);// * SQUEEZE); candidateTaus.add(0.9);// * SQUEEZE); candidateTaus.add(1.0);// * SQUEEZE); for (Double tau : candidateTaus) { Double mse = CrossValidationError(tau, xVec, yVec); if (null == mse) { log.error(" cp cross-validation failed, return null"); return null; } if (mse < bestMSE) { bestMSE = mse; bestTau = tau; } } log.info(" cp LWR bestTau " + bestTau); double x0 = candidateEval; Double prediction = LWRPredict(xVec, yVec, normalizeX(x0, min, max), bestTau); if (null == prediction) { log.error("LWR passed CV but cannot predict on new point. falling back to interpolateOrNN()"); log.error("e2n: " + e2n.toString()); log.error("candidateEval " + candidateEval); return null; } // cast to int, and cannot be negative return Math.max(0, (double) (int) (double) prediction); }
From source file:com.jkoolcloud.tnt4j.streams.utils.DoubleRange.java
/** * Makes range object using values parsed from {@code rangeStr}. * <p>// w w w.j av a2 s . co m * If {@code rangeStr} has missing range bound values, default ones are set: lower * {@code positive ? 0 : -Double.MAX_VALUE}, upper {@code Double.MAX_VALUE}. * <p> * Range separator symbol is '{@value com.jkoolcloud.tnt4j.streams.utils.Range#RANGE_SEPARATOR}'. * * @param rangeStr * range definition string to parse * @param positive * {@code true} means range has only positive values, {@code} - range can have negative values. * @return double range parsed from range definition string * @throws Exception * if range string can't be parsed * @see Range#parseRange(String, Pattern) */ public static DoubleRange getRange(String rangeStr, boolean positive) throws Exception { String[] rangeTokens = parseRange(rangeStr, positive ? D_PATTERN_POSITIVE : D_PATTERN); double from = NumberUtils.toDouble(rangeTokens[0], positive ? 0 : -Double.MAX_VALUE); double to = NumberUtils.toDouble(rangeTokens[1], Double.MAX_VALUE); return new DoubleRange(from, to); }