List of usage examples for java.lang Double isInfinite
public static boolean isInfinite(double v)
From source file:com.stewel.dataflow.assocrules.AlgoAgrawalFaster94.java
/** * The ApGenRules as described in p.14 of the paper by Agrawal. * (see the Agrawal paper for more details). * * @param k the size of the first itemset used to generate rules * @param m the recursive depth of the call to this method (first time 1, then 2...) * @param lk the itemset that is used to generate rules * @param Hm a set of itemsets that can be used with lk to generate rules * @throws IOException exception if error while writing output file *//*from www .j a v a 2s.c om*/ private void apGenrules(int k, int m, Itemset lk, List<int[]> Hm) throws IOException { // if the itemset "lk" that is used to generate rules is larger than the size of itemsets in "Hm" if (k > m + 1) { // Create a list that we will be used to store itemsets for the recursive call List<int[]> Hm_plus_1_for_recursion = new ArrayList<int[]>(); // generate candidates using Hm List<int[]> Hm_plus_1 = itemsetsCandidateGenerator.generateCandidateSizeK(Hm); // for each such candidates for (int[] hm_P_1 : Hm_plus_1) { // We subtract the candidate from the itemset "lk" int[] itemset_Lk_minus_hm_P_1 = Itemset.cloneItemSetMinusAnItemset(lk.getItems(), hm_P_1); // We will now calculate the support of the rule Lk/(hm_P_1) ==> hm_P_1 // we need it to calculate the confidence long support = itemsetSupportCalculator.calculateSupport(itemset_Lk_minus_hm_P_1); double supportAsDouble = (double) support; // calculate the confidence of the rule Lk/(hm_P_1) ==> hm_P_1 double conf = lk.getAbsoluteSupport() / supportAsDouble; // if the confidence is not enough than we don't need to consider // the rule Lk/(hm_P_1) ==> hm_P_1 anymore so we continue if (conf < minimumConfidence || Double.isInfinite(conf)) { continue; } double lift = 0; long supportHm_P_1 = 0; // if the user is using the minimumLift threshold, then we will need to calculate the lift of the // rule as well and check if the lift is higher or equal to minimumLift. if (usingLift) { // if we want to calculate the lift, we need the support of Hm+1 supportHm_P_1 = itemsetSupportCalculator.calculateSupport(hm_P_1); // calculate the lift of the rule: Lk/(hm_P_1) ==> hm_P_1 double term1 = ((double) lk.getAbsoluteSupport()) / databaseSize; double term2 = (supportAsDouble) / databaseSize; lift = term1 / (term2 * ((double) supportHm_P_1 / databaseSize)); // if the lift is not enough if (lift < minimumLift) { continue; } } // The rule has passed the confidence and lift threshold requirements, // so we can output it associationRuleWriter.write(ImmutableAssociationRule.builder().antecedent(itemset_Lk_minus_hm_P_1) .consequent(hm_P_1).coverage(support).transactionCount(lk.getAbsoluteSupport()) .confidence(conf).lift(lift).build()); // if k == m+1, then we cannot explore further rules using Lk since Lk will be too small. if (k != m + 1) { Hm_plus_1_for_recursion.add(hm_P_1); } } // recursive call to apGenRules to find more rules using "lk" apGenrules(k, m + 1, lk, Hm_plus_1_for_recursion); } }
From source file:de.Keyle.MyPet.entity.MyPet.java
public void setSaturation(double value) { if (!Double.isNaN(value) && !Double.isInfinite(value)) { saturation = Math.max(1, Math.min(100, value)); hungerTime = Configuration.HungerSystem.HUNGER_SYSTEM_TIME; } else {/*from w w w.j a va 2 s . c o m*/ MyPetApi.getLogger().warning("Saturation was set to an invalid number!\n" + Util.stackTraceToString()); } }
From source file:edu.jhuapl.bsp.detector.OpenMath.java
public static double std(double[] in) { if (in != null && in.length > 1) { double sum = 0; double avg = OpenMath.mean(in); for (int i = 0; i < in.length; i++) { sum += ((in[i] - avg) * (in[i] - avg)); }// w w w .ja va2s . c om double stddev = Math.sqrt(sum / (in.length - 1)); if (Double.isNaN(stddev) || Double.isInfinite(stddev)) { return 0; } else { return stddev; } } return 0.0; }
From source file:juicebox.tools.utils.original.NormalizationCalculations.java
private static double[] computeKRNormVector(SparseSymmetricMatrix A, double tol, double[] x0, double delta) { int n = x0.length; double[] e = new double[n]; for (int i = 0; i < e.length; i++) e[i] = 1;//from w ww .j ava 2 s . co m double g = 0.9; double etamax = 0.1; double eta = etamax; double[] x = x0; double rt = Math.pow(tol, 2); double[] v = A.multiply(x); double[] rk = new double[v.length]; for (int i = 0; i < v.length; i++) { v[i] = v[i] * x[i]; rk[i] = 1 - v[i]; } double rho_km1 = 0; for (double aRk : rk) { rho_km1 += aRk * aRk; } double rout = rho_km1; double rold = rout; int MVP = 0; // We'll count matrix vector products. int not_changing = 0; while (rout > rt && not_changing < 100) { // Outer iteration int k = 0; double[] y = new double[e.length]; double[] ynew = new double[e.length]; double[] Z = new double[e.length]; double[] p = new double[e.length]; double[] w = new double[e.length]; double alpha; double beta; double gamma; double rho_km2 = rho_km1; System.arraycopy(e, 0, y, 0, y.length); double innertol = Math.max(Math.pow(eta, 2) * rout, rt); while (rho_km1 > innertol) { // Inner iteration by CG k++; if (k == 1) { rho_km1 = 0; for (int i = 0; i < Z.length; i++) { Z[i] = rk[i] / v[i]; p[i] = Z[i]; rho_km1 += rk[i] * Z[i]; } } else { beta = rho_km1 / rho_km2; for (int i = 0; i < p.length; i++) { p[i] = Z[i] + beta * p[i]; } } double[] tmp = new double[e.length]; for (int i = 0; i < tmp.length; i++) { tmp[i] = x[i] * p[i]; } tmp = A.multiply(tmp); alpha = 0; // Update search direction efficiently. for (int i = 0; i < tmp.length; i++) { w[i] = x[i] * tmp[i] + v[i] * p[i]; alpha += p[i] * w[i]; } alpha = rho_km1 / alpha; double minynew = Double.MAX_VALUE; // Test distance to boundary of cone. for (int i = 0; i < p.length; i++) { ynew[i] = y[i] + alpha * p[i]; if (ynew[i] < minynew) minynew = ynew[i]; } if (minynew <= delta) { if (delta == 0) break; // break out of inner loop? gamma = Double.MAX_VALUE; for (int i = 0; i < ynew.length; i++) { if (alpha * p[i] < 0) { if ((delta - y[i]) / (alpha * p[i]) < gamma) { gamma = (delta - y[i]) / (alpha * p[i]); } } } for (int i = 0; i < y.length; i++) y[i] = y[i] + gamma * alpha * p[i]; break; // break out of inner loop? } rho_km2 = rho_km1; rho_km1 = 0; for (int i = 0; i < y.length; i++) { y[i] = ynew[i]; rk[i] = rk[i] - alpha * w[i]; Z[i] = rk[i] / v[i]; rho_km1 += rk[i] * Z[i]; } } // end inner loop for (int i = 0; i < x.length; i++) { x[i] = x[i] * y[i]; } v = A.multiply(x); rho_km1 = 0; for (int i = 0; i < v.length; i++) { v[i] = v[i] * x[i]; rk[i] = 1 - v[i]; rho_km1 += rk[i] * rk[i]; } if (Math.abs(rho_km1 - rout) < 0.000001 || Double.isInfinite(rho_km1)) { not_changing++; } rout = rho_km1; MVP = MVP + k + 1; // Update inner iteration stopping criterion. double rat = rout / rold; rold = rout; double r_norm = Math.sqrt(rout); double eta_o = eta; eta = g * rat; if (g * Math.pow(eta_o, 2) > 0.1) { eta = Math.max(eta, g * Math.pow(eta_o, 2)); } eta = Math.max(Math.min(eta, etamax), 0.5 * tol / r_norm); } if (not_changing >= 100) { return null; } return x; }
From source file:org.jfree.data.xy.IntervalXYDelegate.java
/** * Returns the interval width. This method will return either the * auto calculated interval width or the manually specified interval * width, depending on the {@link #isAutoWidth()} result. * * @return The interval width to use.// ww w. ja v a2 s.c o m */ public double getIntervalWidth() { if (isAutoWidth() && !Double.isInfinite(this.autoIntervalWidth)) { // everything is fine: autoWidth is on, and an autoIntervalWidth // was set. return this.autoIntervalWidth; } else { // either autoWidth is off or autoIntervalWidth was not set. return this.fixedIntervalWidth; } }
From source file:dr.evomodel.arg.coalescent.ARGUniformPrior.java
public double calculateLogLikelihood() { double treeHeight = arg.getNodeHeight(arg.getRoot()); int internalNodes = arg.getInternalNodeCount() - 1; double logLike = logFactorial(internalNodes) - (double) internalNodes * Math.log(treeHeight) - getLogARGNumber(arg.getReassortmentNodeCount()); assert !Double.isInfinite(logLike) && !Double.isNaN(logLike); return logLike; }
From source file:com.opengamma.analytics.math.interpolation.MonotoneConvexSplineInterpolator.java
@Override public DoubleMatrix2D interpolate(final double[] xValues, final double[] yValues, final double[][] xMatrix) { ArgumentChecker.notNull(xMatrix, "xMatrix"); final int keyLength = xMatrix[0].length; final int keyDim = xMatrix.length; double[][] res = new double[keyDim][keyLength]; final PiecewisePolynomialResult result = interpolate(xValues, yValues); final DoubleMatrix2D coefsMatrixIntegrate = result.getCoefMatrix(); final int nKnots = coefsMatrixIntegrate.getNumberOfRows() + 1; final double[] knots = result.getKnots().getData(); for (int j = 0; j < keyDim; ++j) { for (int k = 0; k < keyLength; ++k) { int indicator = 0; if (xMatrix[j][k] <= knots[1]) { indicator = 0;// www.j a va 2 s.co m } else { for (int i = 1; i < nKnots - 1; ++i) { if (knots[i] < xMatrix[j][k]) { indicator = i; } } } final double[] coefs = coefsMatrixIntegrate.getRowVector(indicator).getData(); res[j][k] = getValue(coefs, xMatrix[j][k], knots[indicator]); ArgumentChecker.isFalse(Double.isInfinite(res[j][k]), "Too large input"); ArgumentChecker.isFalse(Double.isNaN(res[j][k]), "Too large input"); } } return new DoubleMatrix2D(res); }
From source file:org.kalypso.model.wspm.tuhh.core.profile.LengthSectionCreator.java
protected static Double getMaxValueFor(final IProfile profil, final int indexHeight, final String component, final double precision) { final Double[] values = ProfileUtil.getInterpolatedValues(profil, component); final IRecord[] points = profil.getPoints(); double maxValue = Double.NEGATIVE_INFINITY; for (int i = 0; i < values.length; i++) { final IRecord point = points[i]; final Double value = values[i]; final Object height = point.getValue(indexHeight); if (value != null && height instanceof Number) { final double doubleHeight = ((Number) height).doubleValue(); /* Only consider points that are NOT same as height */ if (Math.abs(value - doubleHeight) > precision) { maxValue = Math.max(maxValue, value); }/*from ww w . j a va 2s . com*/ } } if (Double.isInfinite(maxValue)) return Double.NaN; return maxValue; }
From source file:org.locationtech.udig.tools.internal.CursorPosition.java
private static String getString(double value) { if (Double.isNaN(value)) { return Messages.CursorPosition_not_a_number; }//from www . j av a2s . c om if (Double.isInfinite(value)) { return Messages.CursorPosition_infinity; } DecimalFormat format = (DecimalFormat) NumberFormat.getNumberInstance(Locale.getDefault()); format.setMaximumFractionDigits(4); format.setMinimumIntegerDigits(1); format.setGroupingUsed(false); String string = format.format(value); String[] parts = string.split("\\."); if (parts.length > 3) { string = parts[0]; } return string; }
From source file:beast.structuredCoalescent.distribution.ExactStructuredCoalescent.java
public double calculateLogP() { // Calculate the tree intervals (time between events, which nodes participate at a event etc.) treeIntervalsInput.get().calculateIntervals(); treeIntervalsInput.get().swap();//from w ww. j av a 2s.co m // Set up for lineage state probabilities activeLineages = new ArrayList<Integer>(); lineStateProbs = new ArrayList<Double>(); // Compute likelihood at each integration time and tree event starting at final sampling time and moving backwards logP = 0; // Initialize the line state probabilities // total number of intervals final int intervalCount = treeIntervalsInput.get().getIntervalCount(); // counts in which interval we are in int t = 0; nr_lineages = 0; // Captures the probabilities of lineages being in a state double[] p; // Initialize the migration rates matrix int c = 0; for (int k = 0; k < states; k++) { for (int l = 0; l < states; l++) { if (k != l) { migration_rates[c] = migrationRatesInput.get().getArrayValue(c); migration_map[k][l] = c; c++; } else { coalescent_rates[k] = coalescentRatesInput.get().getArrayValue(k) / 2; } } } boolean first = true; // integrate until there are no more tree intervals do { double nextIntervalTime = treeIntervalsInput.get().getInterval(t); // Length of the current interval final double duration = nextIntervalTime;// - currTime; // if the current interval has a length greater than 0, integrate if (duration > 0) { p = new double[jointStateProbabilities.size()]; // Captures the probabilities of lineages being in a state // convert the array list to double[] for (int i = 0; i < jointStateProbabilities.size(); i++) p[i] = jointStateProbabilities.get(i); double[] p_for_ode = new double[p.length]; double ts = timeStep; if (duration < timeStep) ts = duration / 2; // initialize integrator FirstOrderIntegrator integrator = new ClassicalRungeKuttaIntegrator(ts); // set the odes FirstOrderDifferentialEquations ode = new ode_integrator(migration_rates, coalescent_rates, nr_lineages, states, connectivity, sums); // integrate integrator.integrate(ode, 0, p, duration, p_for_ode); // if the dimension is equal to the max integer, this means that a calculation // of a probability of a configuration resulted in a value below 0 and the // run will be stopped if (ode.getDimension() == Integer.MAX_VALUE) { System.out.println("lalalallal"); return Double.NEGATIVE_INFINITY; } // set the probabilities of the system being in a configuration again for (int i = 0; i < p_for_ode.length; i++) jointStateProbabilities.set(i, p_for_ode[i]); } /* * compute contribution of event to likelihood */ if (treeIntervalsInput.get().getIntervalType(t) == IntervalType.COALESCENT) { nr_lineages--; logP += coalesce(t); } /* * add new lineage */ if (treeIntervalsInput.get().getIntervalType(t) == IntervalType.SAMPLE) { nr_lineages++; addLineages(t, first); first = false; } t++; } while (t < intervalCount); //Compute likelihood of remaining tree intervals (coal events occuring before origin) if (Double.isInfinite(logP)) logP = Double.NEGATIVE_INFINITY; if (max_posterior < logP && logP < 0) { max_posterior = logP; max_mig = new double[states * (states - 1)]; max_coal = new double[states]; for (int i = 0; i < 1; i++) max_mig[i] = migrationRatesInput.get().getArrayValue(i); for (int i = 0; i < 1; i++) max_coal[i] = coalescentRatesInput.get().getArrayValue(i); } return logP; }