List of usage examples for java.lang Double isInfinite
public static boolean isInfinite(double v)
From source file:ml.shifu.shifu.core.processor.ExportModelProcessor.java
private String generateNumericalWoeMapping(ColumnConfig columnConfig, List<AbstractBinInfo> numericalBinInfos, ColumnStatsCalculator.ColumnMetrics columnMetrics) { StringBuffer buffer = new StringBuffer(); buffer.append("( case \n"); buffer.append("\twhen " + columnConfig.getColumnName() + " = . then " + columnMetrics.getBinningWoe().get(columnMetrics.getBinningWoe().size() - 1) + "\n"); for (int i = 0; i < numericalBinInfos.size(); i++) { NumericalBinInfo binInfo = (NumericalBinInfo) numericalBinInfos.get(i); buffer.append("\twhen ("); if (!Double.isInfinite(binInfo.getLeftThreshold())) { buffer.append(binInfo.getLeftThreshold() + " <= "); }/*from w ww . ja va 2 s .c o m*/ buffer.append(columnConfig.getColumnName()); if (!Double.isInfinite(binInfo.getRightThreshold())) { buffer.append(" < " + binInfo.getRightThreshold()); } buffer.append(") then " + columnMetrics.getBinningWoe().get(i) + "\n"); } buffer.append(" end ) as " + columnConfig.getColumnName() + "_" + numericalBinInfos.size()); return buffer.toString(); }
From source file:org.eclipse.january.dataset.AbstractCompoundDataset.java
@Override protected void calculateSummaryStats(final boolean ignoreNaNs, final boolean ignoreInfs, final int axis) { int rank = getRank(); int[] oshape = getShape(); int alen = oshape[axis]; oshape[axis] = 1;//from w ww .j av a 2 s .c o m int[] nshape = ShapeUtils.squeezeShape(oshape, false); IntegerDataset count = new IntegerDataset(nshape); CompoundDoubleDataset sum = new CompoundDoubleDataset(isize, nshape); CompoundDoubleDataset mean = new CompoundDoubleDataset(isize, nshape); CompoundDoubleDataset var = new CompoundDoubleDataset(isize, nshape); IndexIterator qiter = count.getIterator(true); int[] qpos = qiter.getPos(); int[] spos = oshape; double[] darray = new double[isize]; while (qiter.hasNext()) { int i = 0; for (; i < axis; i++) { spos[i] = qpos[i]; } spos[i++] = 0; for (; i < rank; i++) { spos[i] = qpos[i - 1]; } final SummaryStatistics[] stats = new SummaryStatistics[isize]; for (int k = 0; k < isize; k++) { stats[k] = new SummaryStatistics(); } for (int j = 0; j < alen; j++) { spos[axis] = j; getDoubleArray(darray, spos); boolean skip = false; for (int k = 0; k < isize; k++) { double v = darray[k]; if (ignoreNaNs && Double.isNaN(v)) { skip = true; break; } if (ignoreInfs && Double.isInfinite(v)) { skip = true; break; } } if (!skip) for (int k = 0; k < isize; k++) { stats[k].addValue(darray[k]); } } count.setAbs(qiter.index, (int) stats[0].getN()); for (int k = 0; k < isize; k++) { darray[k] = stats[k].getSum(); } sum.set(darray, qpos); for (int k = 0; k < isize; k++) { darray[k] = stats[k].getMean(); } mean.set(darray, qpos); for (int k = 0; k < isize; k++) { darray[k] = stats[k].getVariance(); } var.set(darray, qpos); } setStoredValue(storeName(ignoreNaNs, ignoreInfs, STORE_COUNT + "-" + axis), count); storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_SUM + "-" + axis), sum); storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_MEAN + "-" + axis), mean); storedValues.put(storeName(ignoreNaNs, ignoreInfs, STORE_VAR + "-" + axis), var); }
From source file:jp.co.acroquest.jsonic.Formatter.java
public boolean format(final JSON json, final Context context, final Object src, final Object o, final OutputSource out) throws Exception { NumberFormat f = context.getNumberFormat(); double[] array = (double[]) o; out.append('['); for (int i = 0; i < array.length; i++) { if (Double.isNaN(array[i]) || Double.isInfinite(array[i])) { if (context.getMode() != Mode.SCRIPT) { out.append('"'); out.append(Double.toString(array[i])); out.append('"'); } else if (Double.isNaN(array[i])) { out.append("Number.NaN"); } else { out.append("Number."); out.append((array[i] > 0) ? "POSITIVE" : "NEGATIVE"); out.append("_INFINITY"); }/*from w ww .j av a2s.c o m*/ } else if (f != null) { StringFormatter.serialize(context, f.format(array[i]), out); } else { out.append(String.valueOf(array[i])); } if (i != array.length - 1) { out.append(','); if (context.isPrettyPrint()) out.append(' '); } } out.append(']'); return true; }
From source file:geogebra.common.kernel.implicit.GeoImplicitPoly.java
/** * @param ev assigns given coefficient-array to be the coefficients of this Polynomial. * @param calcPath true to update path//from w w w . j a va2 s .c o m */ public void setCoeff(ExpressionValue[][] ev, boolean calcPath) { isConstant = true; degX = -1; degY = -1; coeff = new double[ev.length][]; degX = ev.length - 1; coeffSquarefree = null; for (int i = 0; i < ev.length; i++) { coeff[i] = new double[ev[i].length]; if (ev[i].length > degY + 1) degY = ev[i].length - 1; for (int j = 0; j < ev[i].length; j++) { if (ev[i][j] == null) coeff[i][j] = 0; else coeff[i][j] = ev[i][j].evaluateDouble(); if (Double.isInfinite(coeff[i][j])) { setUndefined(); } isConstant = isConstant && (Kernel.isZero(coeff[i][j]) || (i == 0 && j == 0)); } } getFactors(); if (calcPath && this.calcPath) updatePath(); }
From source file:com.cloudera.oryx.common.math.OpenMapRealVector.java
@Override public boolean isInfinite() { boolean infiniteFound = false; OpenIntToDoubleHashMap.Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance();// www . j a v a 2s . c o m double value = iter.value(); if (Double.isNaN(value)) { return false; } if (Double.isInfinite(value)) { infiniteFound = true; } } return infiniteFound; }
From source file:com.suyonoion.mymath.Menus.fragment_page1.java
protected void hasil() { var_a = editText_a.getText().toString(); if (var_a.isEmpty()) { db_a = 1;//from w ww . j a va2s . c om } else { db_a = Double.parseDouble(var_a); } var_b = editText_b.getText().toString(); if (var_b.isEmpty()) { db_b = 1; } else { db_b = Double.parseDouble(var_b); } var_c = editText_c.getText().toString(); if (var_c.isEmpty()) { db_c = 0; txtHasil_xy.setText("Nilai tidak boleh kosong atau coba ketik = 0"); } else { db_c = Double.parseDouble(var_c); } var_d = editText_d.getText().toString(); if (var_d.isEmpty()) { db_d = 1; } else { db_d = Double.parseDouble(var_d); } var_e = editText_e.getText().toString(); if (var_e.isEmpty()) { db_e = 1; } else { db_e = Double.parseDouble(var_e); } var_f = editText_f.getText().toString(); if (var_f.isEmpty()) { db_f = 0; txtHasil_xy.setText("Nilai tidak boleh kosong atau coba ketik = 0"); } else { db_f = Double.parseDouble(var_f); } try { x = ((db_c * db_e) - (db_f * db_b)) / ((db_a * db_e) - (db_d * db_b)); y = (db_c - (db_a * x)) / db_b; if (Double.isNaN(x) || Double.isInfinite(x)) { Toast.makeText(getContext(), "Gagal", Toast.LENGTH_SHORT).show(); penyelesaianSPLDV.setVisibility(View.VISIBLE); kesalahan(); metodePenyamaanSPLDV.setVisibility(View.GONE); } else { penyelesaianSPLDV.setVisibility(View.VISIBLE); metodePenyamaanSPLDV.setVisibility(View.VISIBLE); prosesPenyamaan(); prosesPenyamaan_ii(); prosesMaka(); prosesMakaMasukkan(); String strX = fmt(x); String strY = fmt(y); txtHasil_x.setText("x = " + strX); txtHasil_y.setText("y = " + strY); txtHasil_xy.setText("HP = { ( " + strX + " , " + strY + " ) }"); Toast.makeText(getContext(), "Sukses", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { penyelesaianSPLDV.setVisibility(View.VISIBLE); kesalahan(); metodePenyamaanSPLDV.setVisibility(View.GONE); } }
From source file:de.undercouch.bson4jackson.BsonGenerator.java
@Override public void writeNumber(BigDecimal dec) throws IOException, JsonGenerationException { if (isEnabled(Feature.WRITE_BIGDECIMALS_AS_STRINGS)) { writeString(dec.toString());/* ww w.j a va2s . co m*/ return; } float f = dec.floatValue(); if (!Float.isInfinite(f)) { writeNumber(f); } else { double d = dec.doubleValue(); if (!Double.isInfinite(d)) { writeNumber(d); } else { writeString(dec.toString()); } } }
From source file:org.apache.storm.utils.Utils.java
public static double zeroIfNaNOrInf(double x) { return (Double.isNaN(x) || Double.isInfinite(x)) ? 0.0 : x; }
From source file:com.xie.javacase.json.JSONObject.java
/** * Produce a string from a double. The string "null" will be returned if * the number is not finite.//from w w w .j av a2 s .c om * @param d A double. * @return A String. */ static public String doubleToString(double d) { if (Double.isInfinite(d) || Double.isNaN(d)) { return "null"; } // Shave off trailing zeros and decimal point, if possible. String s = Double.toString(d); if (s.indexOf('.') > 0 && s.indexOf('e') < 0 && s.indexOf('E') < 0) { while (s.endsWith("0")) { s = s.substring(0, s.length() - 1); } if (s.endsWith(".")) { s = s.substring(0, s.length() - 1); } } return s; }
From source file:dbseer.gui.actions.ExplainChartAction.java
public void printPredicates() { final StatisticalPackageRunner runner = DBSeerGUI.runner; int predicateColumnCount = 5; DefaultListModel predicateListModel = panel.getControlPanel().getPredicateListModel(); predicateListModel.clear();//from w w w . ja v a2 s . co m try { Object[] predicates = (Object[]) runner.getVariableCell("predicates"); int predicateRowCount = predicates.length / predicateColumnCount; String[] predicateNames = new String[predicateRowCount]; double[] lowerBounds = new double[predicateRowCount]; double[] upperBounds = new double[predicateRowCount]; double[] relativeRatio = new double[predicateRowCount]; if (predicateRowCount == 0) { console.append("There is no valid predicate.\n"); return; } for (int r = 0; r < predicateRowCount; ++r) { predicateNames[r] = (String) predicates[r]; if (predicateNames[r].contains("numTrans_")) { Pattern p = Pattern.compile("\\d+"); Matcher m = p.matcher(predicateNames[r]); if (m.find()) { int txIndex = Integer.parseInt(m.group()); predicateNames[r] = String.format("# of '%s' transactions", DBSeerGUI.currentDataset.getTransactionTypeNames().get(txIndex - 1)); } } double[] range = (double[]) predicates[r + predicateRowCount * 1]; double[] ratio = (double[]) predicates[r + predicateRowCount * 2]; lowerBounds[r] = range[0]; upperBounds[r] = range[1]; relativeRatio[r] = ratio[0]; } // print x greater than y first. for (int r = 0; r < predicateRowCount; ++r) { if (!Double.isInfinite(lowerBounds[r]) && Double.isInfinite(upperBounds[r])) { String output = null; if (isPredicateAbsolute) output = String.format("%s > %.2f\n", predicateNames[r], lowerBounds[r]); else { String higher_lower = (relativeRatio[r] > 0) ? "HIGHER" : "LOWER"; if (relativeRatio[r] == 0) { output = String.format("%s is EQUAL in abnormal and normal regions", predicateNames[r]); } else { output = String.format("%s is %.2f%% %s than normal", predicateNames[r], Math.abs(relativeRatio[r]), higher_lower); } } predicateListModel.addElement(output); } } // print x less than y. for (int r = 0; r < predicateRowCount; ++r) { if (Double.isInfinite(lowerBounds[r]) && !Double.isInfinite(upperBounds[r])) { String output = null; if (isPredicateAbsolute) output = String.format("%s < %.2f\n", predicateNames[r], upperBounds[r]); else { String higher_lower = (relativeRatio[r] > 0) ? "HIGHER" : "LOWER"; if (relativeRatio[r] == 0) { output = String.format("%s is EQUAL in abnormal and normal regions", predicateNames[r]); } else { output = String.format("%s is %.2f%% %s than normal", predicateNames[r], Math.abs(relativeRatio[r]), higher_lower); } } predicateListModel.addElement(output); } } // print a < x < b for (int r = 0; r < predicateRowCount; ++r) { if (!Double.isInfinite(lowerBounds[r]) && !Double.isInfinite(upperBounds[r])) { String output = null; if (isPredicateAbsolute) output = String.format("%.2f < %s < %.2f\n", lowerBounds[r], predicateNames[r], upperBounds[r]); else { String higher_lower = (relativeRatio[r] > 0) ? "HIGHER" : "LOWER"; if (relativeRatio[r] == 0) { output = String.format("%s is EQUAL in abnormal and normal regions", predicateNames[r]); } else { output = String.format("%s is %.2f%% %s than normal", predicateNames[r], Math.abs(relativeRatio[r]), higher_lower); } } predicateListModel.addElement(output); } } } catch (Exception e) { DBSeerExceptionHandler.handleException(e); } }