List of usage examples for java.lang Float NaN
float NaN
To view the source code for java.lang Float NaN.
Click Source Link
From source file:Main.java
public static void main(String[] args) { System.out.println("NaN:" + Float.NaN); }
From source file:org.apache.mahout.cf.taste.example.kddcup.track1.Track1RecommenderEvaluatorRunner.java
public static void main(String... args) throws IOException, TasteException, OptionException { File dataFileDirectory = TasteOptionParser.getRatings(args); if (dataFileDirectory == null) { throw new IllegalArgumentException("No data directory"); }//from www .j ava 2 s . c o m if (!dataFileDirectory.exists() || !dataFileDirectory.isDirectory()) { throw new IllegalArgumentException("Bad data file directory: " + dataFileDirectory); } Track1RecommenderEvaluator evaluator = new Track1RecommenderEvaluator(dataFileDirectory); DataModel model = new KDDCupDataModel(KDDCupDataModel.getTrainingFile(dataFileDirectory)); double evaluation = evaluator.evaluate(new Track1RecommenderBuilder(), null, model, Float.NaN, Float.NaN); log.info(String.valueOf(evaluation)); }
From source file:org.openscience.jvxl.Jvxl.java
public static void main(String[] args) { boolean blockData = false; int fileIndex = Integer.MAX_VALUE; String inputFile = null;//from w w w . j a va2s. co m String mapFile = null; String outputFile = null; float cutoff = Float.NaN; boolean isPositiveOnly = false; P4 plane = null; boolean bicolor = false; boolean reverseColor = false; float min = Float.NaN; float max = Float.NaN; Options options = new Options(); options.addOption("h", "help", false, "give this help page"); /* * examples: * * jvxl ch3cl-density.cub --min=0.0 --max=0.2 --map ch3cl-esp.cub * jvxl ethene-HOMO.cub --bicolor --output ethene.jvxl * jvxl d_orbitals.jvxl --index 2 --phase yz * jvxl d_orbitals.jvxl --map sets * jvxl --plane xy --min=0.0 --max=0.2 --map data/ch3cl-density.cub */ // file options options.addOption("B", "blockdata", false, "multiple cube data are in blocks, not interspersed"); options.addOption("P", "progressive", false, "create JVXL+ progressive X low-to-high format"); OptionBuilder.withLongOpt("file"); OptionBuilder.withDescription("file containing surface data"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create("f")); OptionBuilder.withLongOpt("index"); OptionBuilder.withDescription("index of surface in file (starting with 1)"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create("i")); OptionBuilder.withLongOpt("plane"); OptionBuilder.withDescription("plane: x, y, z, xy, xz, yz, z2, x2-y2, or {a,b,c,d}"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create("p")); OptionBuilder.withLongOpt("map"); OptionBuilder.withDescription("file containing data to map onto the surface or \"sets\""); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create("m")); OptionBuilder.withLongOpt("output"); OptionBuilder.withDescription("JVXL output file"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create("o")); // surface options OptionBuilder.withLongOpt("cutoff"); OptionBuilder.withDescription("isosurface cutoff value"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create("c")); // color mapping options options.addOption("b", "bicolor", false, "bicolor map (orbital)"); options.addOption("r", "reversecolor", false, "reverse color"); OptionBuilder.withLongOpt("colorScheme"); OptionBuilder.withDescription("VRML color scheme: bw, wb, roygb, bgyor, rwb, bwr, low, high"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create("s")); OptionBuilder.withLongOpt("phase"); OptionBuilder.withDescription("color by phase: x, y, z, xy, xz, yz, z2, x2-y2"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create("F")); OptionBuilder.withLongOpt("min"); OptionBuilder.withDescription("color absolute minimum value"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create("n")); OptionBuilder.withLongOpt("max"); OptionBuilder.withDescription("color absolute maximum value"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create("x")); CommandLine line = null; try { CommandLineParser parser = new PosixParser(); line = parser.parse(options, args); } catch (ParseException exception) { Logger.error("Unexpected exception: " + exception.toString()); } if (line.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Jvxl", options); return; } args = line.getArgs(); if (args.length > 0) { inputFile = args[0]; } // files blockData = (line.hasOption("B")); if (line.hasOption("i")) { fileIndex = PT.parseInt(line.getOptionValue("i")); } if (line.hasOption("f")) { inputFile = line.getOptionValue("f"); } if (line.hasOption("m")) { mapFile = line.getOptionValue("m"); } if (line.hasOption("p")) { plane = getPlane(line.getOptionValue("p")); if (plane == null) { Logger.error("invalid plane"); return; } Logger.info("using plane " + plane); if (mapFile == null) mapFile = inputFile; if (inputFile == null) inputFile = mapFile; } if (line.hasOption("o")) { outputFile = line.getOptionValue("o"); } else { outputFile = inputFile; if (outputFile.indexOf(".") < 0) outputFile += "."; String sIndex = (fileIndex == Integer.MAX_VALUE ? "" : "_" + fileIndex); if (sIndex.length() == 0 && outputFile.indexOf(".jvxl") >= 0) sIndex += "_new"; outputFile = outputFile.substring(0, outputFile.lastIndexOf(".")) + sIndex + ".jvxl"; } // Process more command line arguments // these are also passed to vwr bicolor = (line.hasOption("b")); reverseColor = (line.hasOption("r")); if (bicolor && mapFile != null) { Logger.warn("--map option ignored; incompatible with --bicolor"); mapFile = null; } if (line.hasOption("c")) { String s = line.getOptionValue("c"); if (s.indexOf("+") == 0) { isPositiveOnly = true; s = s.substring(1); } cutoff = PT.parseFloat(s); } if (line.hasOption("n")) { if (bicolor) Logger.warn("--min option ignored; incompatible with --bicolor"); else min = PT.parseFloat(line.getOptionValue("n")); } if (line.hasOption("x")) { if (bicolor) Logger.warn("--max option ignored; incompatible with --bicolor"); else max = PT.parseFloat(line.getOptionValue("x")); } // if (line.hasOption("P")) { // phase = line.getOptionValue("P"); // } boolean progressive = line.hasOption("P"); // compose the surface SurfaceGenerator sg = new SurfaceGenerator(null, null, null, null); // input file sg.version = VERSION; if (blockData) sg.setProp("blockData", Boolean.TRUE, null); if (!Float.isNaN(cutoff)) sg.setProp(isPositiveOnly ? "cutoffPositive" : "cutoff", Float.valueOf(cutoff), null); if (bicolor) sg.setProp("sign", null, null); if (reverseColor) sg.setProp("reverseColor", null, null); //if (phase != null) //sg.setProp("phase", phase); if (progressive) sg.setProp("progressive", null, null); if (plane != null) sg.setProp("plane", plane, null); else { if (fileIndex != Integer.MAX_VALUE) sg.setProp("fileIndex", Integer.valueOf(fileIndex), null); Object t = FileReader.getBufferedReaderOrErrorMessageFromName(inputFile); if (t instanceof String) { Logger.error((String) t); return; } BufferedReader br = (BufferedReader) t; sg.setProp("readFile", br, null); try { br.close(); } catch (Exception e) { // } } sg.setProp("title", line.toString(), null); //color scheme is only for VMRL //if (colorScheme != null) { // ColorEncoder ce = new ColorEncoder(null); // ce.setColorScheme(colorScheme, false); // sg.setProp("colorScheme", ce); // } if (!Float.isNaN(min)) sg.setProp("red", Float.valueOf(min), null); if (!Float.isNaN(max)) sg.setProp("blue", Float.valueOf(max), null); if (mapFile != null) { Object t = FileReader.getBufferedReaderOrErrorMessageFromName(mapFile); if (t instanceof String) { Logger.error((String) t); return; } BufferedReader br2 = (BufferedReader) t; sg.setProp("mapColor", br2, null); try { br2.close(); } catch (Exception e) { // } } writeFile(outputFile, (String) sg.getProperty("jvxlFileData", 0)); Logger.info((String) sg.getProperty("jvxlFileInfo", 0)); Logger.info("\ncreated " + outputFile); }
From source file:Main.java
/** * Converts the given primative <code>double</code> array to a primitive <code>float</code> array * //from www . ja v a 2s . co m * @param in * a primative <code>double</code> array * * @return a <code>float</code> array equivalent to the specified <code>double</code> array */ public static float[] doubleArrayToFloatArray(double[] in) { float[] out = new float[in.length]; for (int i = 0; i < in.length; i++) { if (Double.isNaN(in[i])) { out[i] = Float.NaN; } else { out[i] = (float) in[i]; } } return out; }
From source file:Main.java
public static float readOptionalFloatAttribute(XMLStreamReader reader, String attributeName) { String attributeValue = reader.getAttributeValue(null, attributeName); return attributeValue != null ? Float.valueOf(attributeValue) : Float.NaN; }
From source file:Main.java
/** Helper method - gets a named attribute's value as a <I>float</I>. @param pNodeMap The <I>NamedNodeMap</I>. @param strName Name of the attribute. @return Value of the attribute.//www .j av a 2 s .co m */ public static float getAttributeFloat(NamedNodeMap pNodeMap, String strName) throws ClassCastException, NumberFormatException { double dblReturn = getAttributeDouble(pNodeMap, strName); if (Double.NaN == dblReturn) return Float.NaN; return (float) dblReturn; }
From source file:Main.java
/** Helper method - gets a named element's value as a <I>float</I>. @param pElement The parent <I>Element</I>. @param strName Name of the element./* w w w.j a v a2 s . co m*/ @return Value of the element. */ public static float getElementFloat(Element pElement, String strName) throws ClassCastException, NumberFormatException { double dblReturn = getElementDouble(pElement, strName); if (Double.NaN == dblReturn) return Float.NaN; return (float) dblReturn; }
From source file:Main.java
/** * For a float value x, this method returns +1.0F if x >= 0 and -1.0F if x < * 0. Returns <code>NaN</code> if <code>x</code> is <code>NaN</code>. * /*from w ww . j av a2s . co m*/ * @param x the value, a float * @return +1.0F or -1.0F, depending on the sign of x */ public static float indicator(final float x) { if (Float.isNaN(x)) { return Float.NaN; } return (x >= 0.0F) ? 1.0F : -1.0F; }
From source file:Main.java
/** * Parses the supplied xsd:float string and returns its value. * /*from ww w . ja v a 2 s.c o m*/ * @param s * A string representation of an xsd:float value. * @return The <tt>float</tt> value represented by the supplied string argument. * @throws NumberFormatException * If the supplied string is not a valid xsd:float value. */ public static float parseFloat(String s) { if (POSITIVE_INFINITY.equals(s)) { return Float.POSITIVE_INFINITY; } else if (NEGATIVE_INFINITY.equals(s)) { return Float.NEGATIVE_INFINITY; } else if (NaN.equals(s)) { return Float.NaN; } else { s = trimPlusSign(s); return Float.parseFloat(s); } }
From source file:Main.java
/** * Returns the <a href="http://mathworld.wolfram.com/Sign.html"> sign</a> * for float value <code>x</code>. * <p>/*from w w w. jav a2s . com*/ * For a float value x, this method returns +1.0F if x > 0, 0.0F if x = * 0.0F, and -1.0F if x < 0. Returns <code>NaN</code> if <code>x</code> * is <code>NaN</code>.</p> * * @param x the value, a float * @return +1.0F, 0.0F, or -1.0F, depending on the sign of x */ public static float sign(final float x) { if (Float.isNaN(x)) { return Float.NaN; } return (x == 0.0F) ? 0.0F : (x > 0.0F) ? 1.0F : -1.0F; }