List of usage examples for java.lang Double NaN
double NaN
To view the source code for java.lang Double NaN.
Click Source Link
From source file:com.anhth12.lambda.app.speed.ALSSpeedModelManager.java
@Override public Iterable<String> buildUpdates(JavaPairRDD<String, String> newData) throws IOException { if (model == null) { return Collections.emptyList(); }/*from w ww . j av a 2 s .c o m*/ JavaRDD<String> sortedValues = newData.values().sortBy(MLFunctions.TO_TIMESTAMP_FN, true, newData.partitions().size()); JavaPairRDD<Tuple2<String, String>, Double> tuples = sortedValues.mapToPair(TO_TUPLE_FN); JavaPairRDD<Tuple2<String, String>, Double> aggregated; if (implicit) { aggregated = tuples.groupByKey().mapValues(MLFunctions.SUM_WITH_NAN); } else { aggregated = tuples.foldByKey(Double.NaN, Functions.<Double>last()); } Collection<UserItemStrength> input = aggregated.filter(MLFunctions.<Tuple2<String, String>>notNaNValue()) .map(TO_UIS_FN).collect(); Solver XTXsolver; Solver YTYsolver; Collection<String> result = new ArrayList<>(); try { XTXsolver = model.getXTXSolver(); YTYsolver = model.getYTYSolver(); } catch (Exception e) { return Collections.emptyList(); } for (UserItemStrength uis : input) { String user = uis.getUser(); String item = uis.getItem(); double value = uis.getStrength(); float[] Xu = model.getUserVector(user); float[] Yi = model.getUserVector(user); double[] newXu = newVector(YTYsolver, value, Xu, Yi); double[] newYi = newVector(XTXsolver, value, Yi, Xu); if (newXu != null) { result.add(toUpdateJSON("X", user, newXu, item)); } if (newYi != null) { result.add(toUpdateJSON("Y", item, newYi, user)); } } return result; }
From source file:kieker.tools.opad.timeseries.forecast.AbstractRForecaster.java
protected IForecastResult createNaNForecast(final ITimeSeries<Double> timeseries, final int numForecastSteps) { final ITimeSeries<Double> tsForecast = this.prepareForecastTS(); final ITimeSeries<Double> tsLower = this.prepareForecastTS(); final ITimeSeries<Double> tsUpper = this.prepareForecastTS(); final Double fcQuality = Double.NaN; final Double[] nanArray = new Double[numForecastSteps]; Arrays.fill(nanArray, Double.NaN); tsForecast.appendAll(nanArray);//from ww w. jav a2s . c o m tsLower.appendAll(nanArray); tsUpper.appendAll(nanArray); return new ForecastResult(tsForecast, this.getTsOriginal(), this.getConfidenceLevel(), fcQuality, tsLower, tsUpper, this.strategy); }
From source file:com.cloud2bubble.services.FuzzyEngine.java
private String evaluateForTerm(Cloudlet c, Bubble b) { Double temp = Double.MIN_NORMAL; String term = null;/*from w ww. ja va 2 s . c o m*/ // load profile vars fis.setVariable(PROFILE_TEMP_COLD_MEAN, b.getProfile().get(PROFILE_TEMP_COLD_MEAN)); fis.setVariable(PROFILE_TEMP_COLD_STD, b.getProfile().get(PROFILE_TEMP_COLD_STD)); fis.setVariable(PROFILE_TEMP_WARM_MEAN, b.getProfile().get(PROFILE_TEMP_WARM_MEAN)); fis.setVariable(PROFILE_TEMP_WARM_STD, b.getProfile().get(PROFILE_TEMP_WARM_STD)); fis.setVariable(PROFILE_TEMP_HOT_MEAN, b.getProfile().get(PROFILE_TEMP_HOT_MEAN)); fis.setVariable(PROFILE_TEMP_HOT_STD, b.getProfile().get(PROFILE_TEMP_HOT_STD)); // load env vars if (c.getEnvironment().get(Environment.TEMPERATURE) != null) { fis.setVariable(Environment.TEMPERATURE.toString().toLowerCase(), Double.valueOf(c.getEnvironment().get(Environment.TEMPERATURE))); } else { fis.setVariable(Environment.TEMPERATURE.toString().toLowerCase(), Double.NaN); } fis.evaluate(); for (String functionTerm : fis.getVariable(QualityOfExperience.FUNCTION).getLinguisticTerms().keySet()) { if (fis.getVariable(QualityOfExperience.FUNCTION).getMembership(functionTerm) > temp) { term = functionTerm; temp = fis.getVariable(QualityOfExperience.FUNCTION).getMembership(functionTerm); } } return term; }
From source file:Spline2D.java
/** * Returns an interpolated value./*from www . j a v a2s . c o m*/ * @param x * @return the interpolated value */ public double getValue(double x) { if (xx.length == 0) { return Double.NaN; } if (xx.length == 1) { if (xx[0] == x) { return yy[0]; } else { return Double.NaN; } } int index = Arrays.binarySearch(xx, x); if (index > 0) { return yy[index]; } index = -(index + 1) - 1; //TODO linear interpolation or extrapolation if (index < 0) { return yy[0]; } return a[index] + b[index] * (x - xx[index]) + c[index] * Math.pow(x - xx[index], 2) + d[index] * Math.pow(x - xx[index], 3); }
From source file:delfos.group.results.groupevaluationmeasures.MAE_byGroupStdDev.java
@Override public GroupEvaluationMeasureResult getMeasureResult(GroupRecommenderSystemResult groupRecommenderSystemResult, DatasetLoader<? extends Rating> originalDatasetLoader, RelevanceCriteria relevanceCriteria, DatasetLoader<? extends Rating> trainingDatasetLoader, DatasetLoader<? extends Rating> testDatasetLoader) { TreeMap<GroupOfUsers, MeanIterative> maeGroups = new TreeMap<>(); for (GroupOfUsers groupOfUsers : groupRecommenderSystemResult.getGroupsOfUsers()) { Collection<Recommendation> groupRecommendations = groupRecommenderSystemResult .getGroupOutput(groupOfUsers).getRecommendations().getRecommendations(); if (groupRecommendations.isEmpty()) { continue; }// ww w . j a va2 s . c om MeanIterative maeGroup = new MeanIterative(); Map<Integer, Map<Integer, ? extends Rating>> groupTrueRatings = new TreeMap<>(); groupOfUsers.getIdMembers().stream().forEach((idUser) -> { try { groupTrueRatings.put(idUser, testDatasetLoader.getRatingsDataset().getUserRatingsRated(idUser)); } catch (UserNotFound ex) { ERROR_CODES.USER_NOT_FOUND.exit(ex); } }); for (Recommendation recommendation : groupRecommendations) { if (Double.isNaN(recommendation.getPreference().doubleValue())) { continue; } int idItem = recommendation.getItem().getId(); for (int idUser : groupOfUsers.getIdMembers()) { if (groupTrueRatings.get(idUser).containsKey(idItem)) { double trueRating = groupTrueRatings.get(idUser).get(idItem).getRatingValue().doubleValue(); double predicted = recommendation.getPreference().doubleValue(); double absoluteError = Math.abs(predicted - trueRating); maeGroup.addValue(absoluteError); } } } maeGroups.put(groupOfUsers, maeGroup); } double[] maesByGroup = maeGroups.values().parallelStream().mapToDouble(maeGroup -> maeGroup.getMean()) .filter(value -> !Double.isNaN(value)).toArray(); double maeByGroupStdDev = new StandardDeviation().evaluate(maesByGroup); if (maesByGroup.length == 0) { return new GroupEvaluationMeasureResult(this, Double.NaN); } else { return new GroupEvaluationMeasureResult(this, maeByGroupStdDev); } }
From source file:com.rapidminer.operator.preprocessing.filter.Real2Integer.java
@Override public ExampleSet applyOnFiltered(ExampleSet exampleSet) throws OperatorException { boolean round = getParameterAsBoolean(PARAMETER_ROUND); List<Attribute> newAttributes = new LinkedList<Attribute>(); Iterator<Attribute> a = exampleSet.getAttributes().iterator(); while (a.hasNext()) { Attribute attribute = a.next(); if ((Ontology.ATTRIBUTE_VALUE_TYPE.isA(attribute.getValueType(), Ontology.NUMERICAL)) && (!Ontology.ATTRIBUTE_VALUE_TYPE.isA(attribute.getValueType(), Ontology.INTEGER))) { Attribute newAttribute = AttributeFactory.createAttribute(attribute.getName(), Ontology.INTEGER); newAttributes.add(newAttribute); exampleSet.getExampleTable().addAttribute(newAttribute); for (Example example : exampleSet) { double originalValue = example.getValue(attribute); if (Double.isNaN(originalValue)) { example.setValue(newAttribute, Double.NaN); } else { long newValue = round ? Math.round(originalValue) : (long) originalValue; example.setValue(newAttribute, newValue); }//w ww . ja v a 2s . c o m } a.remove(); } } for (Attribute attribute : newAttributes) { exampleSet.getAttributes().addRegular(attribute); } return exampleSet; }
From source file:beast.math.distributions.NormalDistribution.java
/** * A more accurate and faster implementation of the cdf (taken from function pnorm in the R statistical language) * This implementation has discrepancies depending on the programming language and system architecture * In Java, returned values become zero once z reaches -37.5193 exactly on the machine tested * In the other implementation, the returned value 0 at about z = -8 * In C, this 0 value is reached approximately z = -37.51938 * <p/>//from ww w.j a v a 2s. c o m * Will later need to be optimised for BEAST * * @param x argument * @param mu mean * @param sigma standard deviation * @param log_p is p logged * @return cdf at x */ public static double cdf(double x, double mu, double sigma, boolean log_p) { if (Double.isNaN(x) || Double.isNaN(mu) || Double.isNaN(sigma)) { return Double.NaN; } if (Double.isInfinite(x) && mu == x) { /* x-mu is NaN */ return Double.NaN; } if (sigma <= 0) { if (sigma < 0) { return Double.NaN; } return (x < mu) ? 0.0 : 1.0; } double p = (x - mu) / sigma; if (Double.isInfinite(p)) { return (x < mu) ? 0.0 : 1.0; } return standardCDF(p, log_p); }
From source file:geogebra.common.kernel.algos.AlgoSimpleRootsPolynomial.java
protected void doCalc(PolynomialFunction rootsPoly, double min, double max) { double roots[] = rootsPoly.getCoefficients(); int nrRealRoots = 0; if (roots.length > 1) nrRealRoots = getRoots(roots, eqnSolver); for (int i = 0; i < nrRealRoots; ++i) { if (Kernel.isGreater(roots[i], max, Kernel.STANDARD_PRECISION) || Kernel.isGreater(min, roots[i], Kernel.STANDARD_PRECISION)) roots[i] = Double.NaN; }//from w w w .ja v a 2 s . c om makePoints(roots, nrRealRoots); }
From source file:com.itemanalysis.psychometrics.polycor.Covariance.java
public double correlationPvalue() { double se = correlationStandardError(); if (se == 0.0) return Double.NaN; double r = correlation(true); double tval = r / se; double df = N - 2.0; TDistribution t = new TDistribution(df); double pvalue = 1 - t.cumulativeProbability(tval); double twoSidedPvalue = 2.0 * Math.min(pvalue, 1 - pvalue);//from R function cor.test() return twoSidedPvalue; }
From source file:io.coala.log.CoalaLog4jLogger.java
/** * @return/*from ww w . j a v a2 s. c o m*/ */ protected String getTimePrefix() { if (this.clock == null) { // System.err.println("2. clock was null for " + getName()); return EMPTY_PREFIX_FORMAT; } final Instant<?> time = this.clock.getTime(); if (time == null) { // System.err.println("2. time was null for " + getName()); return EMPTY_PREFIX_FORMAT; } if (time.getValue() instanceof Double) { final double t = time.doubleValue(); if (t == Double.NaN) { // System.err.println("2. time is NaN for " + getName()); return String.format(NAN_TIME_PREFIX_FORMAT, time.getUnit().toString()); } if (t == Double.NEGATIVE_INFINITY) { // System.err.println("2. time is pos inf for " + getName()); return String.format(NEG_INF_TIME_PREFIX_FORMAT, time.getUnit().toString()); } if (t == Double.NEGATIVE_INFINITY) { // System.err.println("2. time is neg inf for " + getName()); return String.format(POS_INF_TIME_PREFIX_FORMAT, time.getUnit().toString()); } } // System.err.println("2. time is " + time + " for " + getName()); try { if (time instanceof SimTime) return String.format(SIMTIME_PREFIX_FORMAT, time.doubleValue(), time.getUnit().toString(), SIMTIME_DATE_FORMAT.format(((SimTime) time).getIsoTime())); return String.format(TIME_PREFIX_FORMAT, time.doubleValue(), time.getUnit().toString()); } catch (final Throwable t) { t.printStackTrace(); return time.toString(); } }