Example usage for java.lang Float POSITIVE_INFINITY

List of usage examples for java.lang Float POSITIVE_INFINITY

Introduction

In this page you can find the example usage for java.lang Float POSITIVE_INFINITY.

Prototype

float POSITIVE_INFINITY

To view the source code for java.lang Float POSITIVE_INFINITY.

Click Source Link

Document

A constant holding the positive infinity of type float .

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out.println("POSITIVE_INFINITY:" + Float.POSITIVE_INFINITY);
}

From source file:Main.java

/**
 * Returns next bigger float value considering precision of the argument.
 * /* ww  w  .  ja  v a2s .  c  o m*/
 */
public static float nextUpF(float f) {
    if (Float.isNaN(f) || f == Float.POSITIVE_INFINITY) {
        return f;
    } else {
        f += 0.0f;
        return Float.intBitsToFloat(Float.floatToRawIntBits(f) + ((f >= 0.0f) ? +1 : -1));
    }
}

From source file:Main.java

public static RectF trapToRect(float[] array) {
    RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY,
            Float.NEGATIVE_INFINITY);
    for (int i = 1; i < array.length; i += 2) {
        float x = round(array[i - 1] * 10) / 10.f;
        float y = round(array[i] * 10) / 10.f;
        r.left = (x < r.left) ? x : r.left;
        r.top = (y < r.top) ? y : r.top;
        r.right = (x > r.right) ? x : r.right;
        r.bottom = (y > r.bottom) ? y : r.bottom;
    }/*from   w  w w  . j ava  2 s . c o  m*/
    r.sort();
    return r;
}

From source file:Main.java

/**
 * Takes an array of 2D coordinates representing corners and returns the
 * smallest rectangle containing those coordinates.
 *
 * @param array array of 2D coordinates// w ww  .  ja va 2s .co m
 * @return smallest rectangle containing coordinates
 */
public static RectF trapToRect(float[] array) {
    RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY,
            Float.NEGATIVE_INFINITY);
    for (int i = 1; i < array.length; i += 2) {
        float x = array[i - 1];
        float y = array[i];
        r.left = (x < r.left) ? x : r.left;
        r.top = (y < r.top) ? y : r.top;
        r.right = (x > r.right) ? x : r.right;
        r.bottom = (y > r.bottom) ? y : r.bottom;
    }
    r.sort();
    return r;
}

From source file:com.yahoo.egads.utilities.AutoSensitivity.java

public static Float getLowDensitySensitivity(Float[] data, float sDAutoSensitivy, float amntAutoSensitivity) {
    Float toReturn = Float.POSITIVE_INFINITY;
    Arrays.sort(data, Collections.reverseOrder());
    while (data.length > 0) {

        ArrayList<Float> fData = new ArrayList<Float>();
        fData.add(data[0]);//  ww  w  .j av a  2s  .  c  om
        data = ((Float[]) ArrayUtils.remove(data, 0));

        Float centroid = (float) fData.get(0);
        Float maxDelta = (float) sDAutoSensitivy * StatsUtils.getSD(data, StatsUtils.getMean(data));

        logger.debug("AutoSensitivity: Adding: " + fData.get(0) + " SD: " + maxDelta);

        // Add points while it's in the same cluster or not part of the other cluster.
        String localDebug = null;
        while (data.length > 0 && (centroid - data[0]) <= ((float) (maxDelta))) {
            float maxDeltaInit = maxDelta;
            fData.add(data[0]);
            data = ((Float[]) ArrayUtils.remove(data, 0));
            Float[] tmp = new Float[fData.size()];
            tmp = fData.toArray(tmp);
            centroid = StatsUtils.getMean(tmp);

            if (data.length > 0) {
                Float sdOtherCluster = (float) StatsUtils.getSD(data, StatsUtils.getMean(data));
                maxDelta = sDAutoSensitivy * sdOtherCluster;
                logger.debug(
                        "AutoSensitivity: Adding: " + data[0] + " SD: " + maxDeltaInit + " SD': " + maxDelta);
            }
        }
        if (data.length > 0) {
            logger.debug("AutoSensitivity: Next Point I would have added is " + data[0]);
        }

        if (((double) fData.size() / (double) data.length) > amntAutoSensitivity) {
            // Cannot do anomaly detection.
            logger.debug("AutoSensitivity: Returning " + toReturn + " data size: " + data.length
                    + " fData.size: " + fData.size());
            return toReturn;
        }

        toReturn = fData.get(fData.size() - 1);
        logger.debug("AutoSensitivity: Updating toReturn:  " + toReturn + " SD: " + maxDelta);
        return toReturn;
    }
    return toReturn;
}

From source file:Main.java

/**
 * Parses the supplied xsd:float string and returns its value.
 * /*from   w  w w . j  av  a2  s. com*/
 * @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

private static float buildFloat(int mant, int exp) {
    if (exp < -125 || mant == 0) {
        return 0.0f;
    }/*from  ww  w .j  av  a 2  s  .c  o m*/

    if (exp >= 128) {
        return (mant > 0) ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY;
    }

    if (exp == 0) {
        return mant;
    }

    if (mant >= (1 << 26)) {
        mant++; // round up trailing bits if they will be dropped.
    }

    return (float) ((exp > 0) ? mant * pow10[exp] : mant / pow10[-exp]);
}

From source file:Main.java

/**
 * Computes a float from mantissa and exponent.
 */// w  w  w.j av  a  2  s . c om
public static float buildFloat(int mant, int exp) {
    if (exp < -125 || mant == 0) {
        return 0.0f;
    }

    if (exp >= 128) {
        return (mant > 0) ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY;
    }

    if (exp == 0) {
        return mant;
    }

    if (mant >= (1 << 26)) {
        mant++; // round up trailing bits if they will be dropped.
    }

    return (float) ((exp > 0) ? mant * pow10[exp] : mant / pow10[-exp]);
}

From source file:org.apache.mahout.text.SparseVectorsFromSequenceFiles.java

public static void main(String[] args) throws Exception {
    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option inputDirOpt = obuilder.withLongName("input").withRequired(true)
            .withArgument(abuilder.withName("input").withMinimum(1).withMaximum(1).create())
            .withDescription("input dir containing the documents in sequence file format").withShortName("i")
            .create();//from   w  w w.  java  2s.c o m

    Option outputDirOpt = obuilder.withLongName("output").withRequired(true)
            .withArgument(abuilder.withName("output").withMinimum(1).withMaximum(1).create())
            .withDescription("The output directory").withShortName("o").create();
    Option minSupportOpt = obuilder.withLongName("minSupport")
            .withArgument(abuilder.withName("minSupport").withMinimum(1).withMaximum(1).create())
            .withDescription("(Optional) Minimum Support. Default Value: 2").withShortName("s").create();

    Option analyzerNameOpt = obuilder.withLongName("analyzerName")
            .withArgument(abuilder.withName("analyzerName").withMinimum(1).withMaximum(1).create())
            .withDescription("The class name of the analyzer").withShortName("a").create();

    Option chunkSizeOpt = obuilder.withLongName("chunkSize")
            .withArgument(abuilder.withName("chunkSize").withMinimum(1).withMaximum(1).create())
            .withDescription("The chunkSize in MegaBytes. 100-10000 MB").withShortName("chunk").create();

    Option weightOpt = obuilder.withLongName("weight").withRequired(false)
            .withArgument(abuilder.withName("weight").withMinimum(1).withMaximum(1).create())
            .withDescription("The kind of weight to use. Currently TF or TFIDF").withShortName("wt").create();

    Option minDFOpt = obuilder.withLongName("minDF").withRequired(false)
            .withArgument(abuilder.withName("minDF").withMinimum(1).withMaximum(1).create())
            .withDescription("The minimum document frequency.  Default is 1").withShortName("md").create();

    Option maxDFPercentOpt = obuilder.withLongName("maxDFPercent").withRequired(false)
            .withArgument(abuilder.withName("maxDFPercent").withMinimum(1).withMaximum(1).create())
            .withDescription(
                    "The max percentage of docs for the DF.  Can be used to remove really high frequency terms."
                            + " Expressed as an integer between 0 and 100. Default is 99.")
            .withShortName("x").create();

    Option minLLROpt = obuilder.withLongName("minLLR").withRequired(false)
            .withArgument(abuilder.withName("minLLR").withMinimum(1).withMaximum(1).create())
            .withDescription("(Optional)The minimum Log Likelihood Ratio(Float)  Default is "
                    + LLRReducer.DEFAULT_MIN_LLR)
            .withShortName("ml").create();

    Option numReduceTasksOpt = obuilder.withLongName("numReducers")
            .withArgument(abuilder.withName("numReducers").withMinimum(1).withMaximum(1).create())
            .withDescription("(Optional) Number of reduce tasks. Default Value: 1").withShortName("nr")
            .create();

    Option powerOpt = obuilder.withLongName("norm").withRequired(false)
            .withArgument(abuilder.withName("norm").withMinimum(1).withMaximum(1).create())
            .withDescription(
                    "The norm to use, expressed as either a float or \"INF\" if you want to use the Infinite norm.  "
                            + "Must be greater or equal to 0.  The default is not to normalize")
            .withShortName("n").create();
    Option maxNGramSizeOpt = obuilder.withLongName("maxNGramSize").withRequired(false)
            .withArgument(abuilder.withName("ngramSize").withMinimum(1).withMaximum(1).create())
            .withDescription("(Optional) The maximum size of ngrams to create"
                    + " (2 = bigrams, 3 = trigrams, etc) Default Value:1")
            .withShortName("ng").create();
    Option sequentialAccessVectorOpt = obuilder.withLongName("sequentialAccessVector").withRequired(false)
            .withDescription(
                    "(Optional) Whether output vectors should be SequentialAccessVectors. If set true else false")
            .withShortName("seq").create();

    Option overwriteOutput = obuilder.withLongName("overwrite").withRequired(false)
            .withDescription("If set, overwrite the output directory").withShortName("ow").create();
    Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h")
            .create();

    Group group = gbuilder.withName("Options").withOption(minSupportOpt).withOption(analyzerNameOpt)
            .withOption(chunkSizeOpt).withOption(outputDirOpt).withOption(inputDirOpt).withOption(minDFOpt)
            .withOption(maxDFPercentOpt).withOption(weightOpt).withOption(powerOpt).withOption(minLLROpt)
            .withOption(numReduceTasksOpt).withOption(maxNGramSizeOpt).withOption(overwriteOutput)
            .withOption(helpOpt).withOption(sequentialAccessVectorOpt).create();
    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        CommandLine cmdLine = parser.parse(args);

        if (cmdLine.hasOption(helpOpt)) {
            CommandLineUtil.printHelp(group);
            return;
        }

        Path inputDir = new Path((String) cmdLine.getValue(inputDirOpt));
        Path outputDir = new Path((String) cmdLine.getValue(outputDirOpt));

        int chunkSize = 100;
        if (cmdLine.hasOption(chunkSizeOpt)) {
            chunkSize = Integer.parseInt((String) cmdLine.getValue(chunkSizeOpt));
        }
        int minSupport = 2;
        if (cmdLine.hasOption(minSupportOpt)) {
            String minSupportString = (String) cmdLine.getValue(minSupportOpt);
            minSupport = Integer.parseInt(minSupportString);
        }

        int maxNGramSize = 1;

        if (cmdLine.hasOption(maxNGramSizeOpt)) {
            try {
                maxNGramSize = Integer.parseInt(cmdLine.getValue(maxNGramSizeOpt).toString());
            } catch (NumberFormatException ex) {
                log.warn("Could not parse ngram size option");
            }
        }
        log.info("Maximum n-gram size is: {}", maxNGramSize);

        if (cmdLine.hasOption(overwriteOutput)) {
            HadoopUtil.overwriteOutput(outputDir);
        }

        float minLLRValue = LLRReducer.DEFAULT_MIN_LLR;
        if (cmdLine.hasOption(minLLROpt)) {
            minLLRValue = Float.parseFloat(cmdLine.getValue(minLLROpt).toString());
        }
        log.info("Minimum LLR value: {}", minLLRValue);

        int reduceTasks = 1;
        if (cmdLine.hasOption(numReduceTasksOpt)) {
            reduceTasks = Integer.parseInt(cmdLine.getValue(numReduceTasksOpt).toString());
        }
        log.info("Number of reduce tasks: {}", reduceTasks);

        Class<? extends Analyzer> analyzerClass = DefaultAnalyzer.class;
        if (cmdLine.hasOption(analyzerNameOpt)) {
            String className = cmdLine.getValue(analyzerNameOpt).toString();
            analyzerClass = (Class<? extends Analyzer>) Class.forName(className);
            // try instantiating it, b/c there isn't any point in setting it if
            // you can't instantiate it
            analyzerClass.newInstance();
        }

        boolean processIdf;

        if (cmdLine.hasOption(weightOpt)) {
            String wString = cmdLine.getValue(weightOpt).toString();
            if (wString.equalsIgnoreCase("tf")) {
                processIdf = false;
            } else if (wString.equalsIgnoreCase("tfidf")) {
                processIdf = true;
            } else {
                throw new OptionException(weightOpt);
            }
        } else {
            processIdf = true;
        }

        int minDf = 1;
        if (cmdLine.hasOption(minDFOpt)) {
            minDf = Integer.parseInt(cmdLine.getValue(minDFOpt).toString());
        }
        int maxDFPercent = 99;
        if (cmdLine.hasOption(maxDFPercentOpt)) {
            maxDFPercent = Integer.parseInt(cmdLine.getValue(maxDFPercentOpt).toString());
        }

        float norm = PartialVectorMerger.NO_NORMALIZING;
        if (cmdLine.hasOption(powerOpt)) {
            String power = cmdLine.getValue(powerOpt).toString();
            if (power.equals("INF")) {
                norm = Float.POSITIVE_INFINITY;
            } else {
                norm = Float.parseFloat(power);
            }
        }
        HadoopUtil.overwriteOutput(outputDir);
        Path tokenizedPath = new Path(outputDir, DocumentProcessor.TOKENIZED_DOCUMENT_OUTPUT_FOLDER);
        DocumentProcessor.tokenizeDocuments(inputDir, analyzerClass, tokenizedPath);

        boolean sequentialAccessOutput = false;
        if (cmdLine.hasOption(sequentialAccessVectorOpt)) {
            sequentialAccessOutput = true;
        }

        DictionaryVectorizer.createTermFrequencyVectors(tokenizedPath, outputDir, minSupport, maxNGramSize,
                minLLRValue, reduceTasks, chunkSize, sequentialAccessOutput);
        if (processIdf) {
            TFIDFConverter.processTfIdf(new Path(outputDir, DictionaryVectorizer.DOCUMENT_VECTOR_OUTPUT_FOLDER),
                    new Path(outputDir, TFIDFConverter.TFIDF_OUTPUT_FOLDER), chunkSize, minDf, maxDFPercent,
                    norm, sequentialAccessOutput, reduceTasks);
        }
    } catch (OptionException e) {
        log.error("Exception", e);
        CommandLineUtil.printHelp(group);
    }
}

From source file:org.evosuite.utils.NumberFormatter.java

/**
 * <p>/* w w  w . j  ava 2s. c o  m*/
 * getNumberString
 * </p>
 * 
 * @param value
 *            a {@link java.lang.Object} object.
 * @return a {@link java.lang.String} object.
 */
public static String getNumberString(Object value) {
    if (value == null)
        return "null";
    else if (value.getClass().equals(char.class) || value.getClass().equals(Character.class)) {
        // StringEscapeUtils fails to escape a single quote char
        if (Character.valueOf('\'').equals(value)) {
            return "'\\\''";
        } else {
            return "'" + StringEscapeUtils.escapeJava(Character.toString((Character) value)) + "'";
        }
    } else if (value.getClass().equals(String.class)) {
        return "\"" + StringEscapeUtils.escapeJava((String) value) + "\"";
    } else if (value.getClass().equals(float.class) || value.getClass().equals(Float.class)) {
        if (value.toString().equals("" + Float.NaN))
            return "Float.NaN";
        else if (value.toString().equals("" + Float.NEGATIVE_INFINITY))
            return "Float.NEGATIVE_INFINITY";
        else if (value.toString().equals("" + Float.POSITIVE_INFINITY))
            return "Float.POSITIVE_INFINITY";
        else if (((Float) value) < 0F)
            return "(" + value + "F)";
        else
            return value + "F";
    } else if (value.getClass().equals(double.class) || value.getClass().equals(Double.class)) {
        if (value.toString().equals("" + Double.NaN))
            return "Double.NaN";
        else if (value.toString().equals("" + Double.NEGATIVE_INFINITY))
            return "Double.NEGATIVE_INFINITY";
        else if (value.toString().equals("" + Double.POSITIVE_INFINITY))
            return "Double.POSITIVE_INFINITY";
        else if (((Double) value) < 0.0)
            return "(" + value + ")";
        else
            return value.toString();
    } else if (value.getClass().equals(long.class) || value.getClass().equals(Long.class)) {
        if (((Long) value) < 0)
            return "(" + value + "L)";
        else
            return value + "L";
    } else if (value.getClass().equals(byte.class) || value.getClass().equals(Byte.class)) {
        if (((Byte) value) < 0)
            return "(byte) (" + value + ")";
        else
            return "(byte)" + value;
    } else if (value.getClass().equals(short.class) || value.getClass().equals(Short.class)) {
        if (((Short) value) < 0)
            return "(short) (" + value + ")";
        else
            return "(short)" + value;
    } else if (value.getClass().equals(int.class) || value.getClass().equals(Integer.class)) {
        int val = ((Integer) value).intValue();
        if (val == Integer.MAX_VALUE)
            return "Integer.MAX_VALUE";
        else if (val == Integer.MIN_VALUE)
            return "Integer.MIN_VALUE";
        else if (((Integer) value) < 0)
            return "(" + value + ")";
        else
            return "" + val;
    } else if (value.getClass().isEnum() || value instanceof Enum) {
        // java.util.concurrent.TimeUnit is an example where the enum
        // elements are anonymous inner classes, and then isEnum does
        // not return true apparently? So we check using instanceof as well.

        Class<?> clazz = value.getClass();
        String className = clazz.getSimpleName();
        while (clazz.getEnclosingClass() != null) {
            String enclosingName = clazz.getEnclosingClass().getSimpleName();
            className = enclosingName + "." + className;
            clazz = clazz.getEnclosingClass();
        }

        // We have to do this here to avoid a double colon in the TimeUnit example
        if (!className.endsWith("."))
            className += ".";
        try {
            if (value.getClass().getField(value.toString()) != null)
                return className + value;
            else if (((Enum<?>) value).name() != null)
                return className + ((Enum<?>) value).name();
            else
                return "Enum.valueOf(" + className + "class, \"" + value + "\")";
        } catch (Exception e) {
            if (((Enum<?>) value).name() != null)
                return className + ((Enum<?>) value).name();
            else
                return "Enum.valueOf(" + className + "class /* " + e + " */, \"" + value + "\")";
            // return className + "valueOf(\"" + value + "\")";
        }
    } else if (value.getClass().equals(Boolean.class)) {
        return value.toString();
    } else {
        // This should not happen
        assert (false);
        return value.toString();
    }
}