Example usage for java.lang Double NEGATIVE_INFINITY

List of usage examples for java.lang Double NEGATIVE_INFINITY

Introduction

In this page you can find the example usage for java.lang Double NEGATIVE_INFINITY.

Prototype

double NEGATIVE_INFINITY

To view the source code for java.lang Double NEGATIVE_INFINITY.

Click Source Link

Document

A constant holding the negative infinity of type double .

Usage

From source file:Clustering.technique.KMeansPlusPlusClusterer.java

/**
 * Get a random point from the {@link Cluster} with the largest distance variance.
 *
 * @param clusters the {@link Cluster}s to search
 * @return a random point from the selected cluster
 * @throws ConvergenceException if clusters are all empty
 *//*from   w w  w  .j  a  va 2s  . c  o  m*/
private T getPointFromLargestVarianceCluster(final Collection<CentroidCluster<T>> clusters)
        throws ConvergenceException {

    double maxVariance = Double.NEGATIVE_INFINITY;
    Cluster<T> selected = null;
    for (final CentroidCluster<T> cluster : clusters) {
        if (!cluster.getPoints().isEmpty()) {

            // compute the distance variance of the current cluster
            final Clusterable center = cluster.getCenter();
            final Variance stat = new Variance();
            for (final T point : cluster.getPoints()) {
                stat.increment(distance(point, center));
            }
            final double variance = stat.getResult();

            // select the cluster with the largest variance
            if (variance > maxVariance) {
                maxVariance = variance;
                selected = cluster;
            }

        }
    }

    // did we find at least one non-empty cluster ?
    if (selected == null) {
        throw new ConvergenceException(LocalizedFormats.EMPTY_CLUSTER_IN_K_MEANS);
    }

    // extract a random point from the cluster
    final List<T> selectedPoints = selected.getPoints();
    return selectedPoints.remove(random.nextInt(selectedPoints.size()));

}

From source file:com.rapidminer.operator.generator.ExampleSetGenerator.java

@Override
public List<ParameterType> getParameterTypes() {
    List<ParameterType> types = super.getParameterTypes();
    ParameterType type = new ParameterTypeStringCategory(PARAMETER_TARGET_FUNCTION,
            "Specifies the target function of this example set", KNOWN_FUNCTION_NAMES, KNOWN_FUNCTION_NAMES[0]);
    type.setExpert(false);//from  w  w  w.  j  a v  a  2  s.  c o  m
    types.add(type);
    type = new ParameterTypeInt(PARAMETER_NUMBER_EXAMPLES, "The number of generated examples.", 1,
            Integer.MAX_VALUE, 100);
    type.setExpert(false);
    types.add(type);
    type = new ParameterTypeInt(PARAMETER_NUMBER_OF_ATTRIBUTES, "The number of attributes.", 1,
            Integer.MAX_VALUE, 5);
    type.setExpert(false);
    types.add(type);

    NonEqualStringCondition useTwoBounds = new NonEqualStringCondition(this, PARAMETER_TARGET_FUNCTION, false,
            (String[]) ArrayUtils.addAll(FUCTIONS_IGNORING_BOUND, FUNCTIONS_USING_SINGLE_BOUND));

    type = new ParameterTypeDouble(PARAMETER_ATTRIBUTES_LOWER_BOUND,
            "The minimum value for the attributes. In case of target functions using Gaussian distribution, the attribute values may exceed this value.",
            Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, -10);
    type.registerDependencyCondition(new OrParameterCondition(this, false,
            new BelowOrEqualOperatorVersionCondition(this, VERSION_TARGET_PARAMETERS_CHANGED), useTwoBounds));
    types.add(type);
    type = new ParameterTypeDouble(PARAMETER_ATTRIBUTES_UPPER_BOUND,
            "The maximum value for the attributes. In case of target functions using Gaussian distribution, the attribute values may exceed this value.",
            Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, 10);
    type.registerDependencyCondition(new OrParameterCondition(this, false,
            new BelowOrEqualOperatorVersionCondition(this, VERSION_TARGET_PARAMETERS_CHANGED), useTwoBounds));
    types.add(type);

    type = new ParameterTypeDouble(PARAMETER_ATTRIBUTES_GAUSSIAN_STDDEV,
            "Standard deviation of the Gaussian distribution used for generating attributes.", Double.MIN_VALUE,
            Double.POSITIVE_INFINITY, 10);
    type.registerDependencyCondition(
            new AboveOperatorVersionCondition(this, VERSION_TARGET_PARAMETERS_CHANGED));
    type.registerDependencyCondition(
            new EqualStringCondition(this, PARAMETER_TARGET_FUNCTION, false, FUNCTIONS_USING_GAUSSIAN_STDDEV));
    types.add(type);

    type = new ParameterTypeDouble(PARAMETER_ATTRIBUTES_LARGEST_RADIUS,
            "The radius of the outermost ring cluster.", 10.0, Double.POSITIVE_INFINITY, 10);
    type.registerDependencyCondition(
            new AboveOperatorVersionCondition(this, VERSION_TARGET_PARAMETERS_CHANGED));
    type.registerDependencyCondition(
            new EqualStringCondition(this, PARAMETER_TARGET_FUNCTION, false, FUNCTIONS_USING_LARGEST_RADIUS));
    types.add(type);

    types.addAll(RandomGenerator.getRandomGeneratorParameters(this));

    DataManagementParameterHelper.addParameterTypes(types, this);
    return types;
}

From source file:com.genericworkflownodes.knime.config.writer.CTDConfigurationWriter.java

private void addDoubleParameterRestrictions(Parameter<?> p, StringBuffer restriction) {
    DoubleParameter dp = (DoubleParameter) p;
    boolean lbSet = Double.NEGATIVE_INFINITY != dp.getLowerBound().doubleValue();
    boolean ubSet = Double.POSITIVE_INFINITY != dp.getUpperBound().doubleValue();
    if (lbSet) {/*from w w  w. j ava 2  s.  co  m*/
        restriction.append(String.format(Locale.ENGLISH, "%f", dp.getLowerBound())
                .replaceAll(REMOVE_TRAILING_0_RE, "").replaceAll(REMOVE_TRAILING_DOT_RE, ""));
    }
    if (ubSet || lbSet) {
        restriction.append(':');
    }
    if (ubSet) {
        restriction.append(String.format(Locale.ENGLISH, "%f", dp.getUpperBound())
                .replaceAll(REMOVE_TRAILING_0_RE, "").replaceAll(REMOVE_TRAILING_DOT_RE, ""));
    }
}

From source file:ffx.xray.CrystalStats.java

/**
 * print HKL statistics/completeness info
 *//*from ww  w. ja va 2  s.  c o m*/
public void printHKLStats() {
    double res[][] = new double[n][2];
    int nhkl[][] = new int[n][3];

    for (int i = 0; i < n; i++) {
        res[i][0] = Double.NEGATIVE_INFINITY;
        res[i][1] = Double.POSITIVE_INFINITY;
    }

    for (HKL ih : reflectionlist.hkllist) {
        int i = ih.index();
        int b = ih.bin();

        // ignored cases
        if (Double.isNaN(fo[i][0]) || fo[i][1] <= 0.0) {
            nhkl[b][2]++;
            continue;
        }

        // determine res limits of each bin
        double rh = Crystal.res(crystal, ih);
        if (rh > res[b][0]) {
            res[b][0] = rh;
        }
        if (rh < res[b][1]) {
            res[b][1] = rh;
        }

        // count the reflection
        if (freer[i] == refinementdata.rfreeflag) {
            nhkl[b][1]++;
        } else {
            nhkl[b][0]++;
        }
    }

    StringBuilder sb = new StringBuilder(String.format("\n %15s | %8s|%9s| %7s | %7s | %s\n", "Res. Range",
            " HKL (R)", " HKL (cv)", " Bin", " Miss", "Complete (%)"));
    for (int i = 0; i < n; i++) {
        sb.append(String.format(" %7.3f %7.3f | ", res[i][0], res[i][1]));
        sb.append(String.format("%7d | %7d | %7d | %7d | ", nhkl[i][0], nhkl[i][1], nhkl[i][0] + nhkl[i][1],
                nhkl[i][2]));
        sb.append(String.format("%6.2f\n",
                (((double) nhkl[i][0] + nhkl[i][1]) / (nhkl[i][0] + nhkl[i][1] + nhkl[i][2])) * 100.0));
    }
    sb.append(String.format(" %7.3f %7.3f | ", res[0][0], res[n - 1][1]));
    int sum1 = 0;
    int sum2 = 0;
    int sum3 = 0;
    for (int i = 0; i < n; i++) {
        sum1 += nhkl[i][0];
        sum2 += nhkl[i][1];
        sum3 += nhkl[i][2];
    }
    sb.append(String.format("%7d | %7d | %7d | %7d | ", sum1, sum2, sum1 + sum2, sum3));
    sb.append(String.format("%6.2f\n", (((double) sum1 + sum2) / (sum1 + sum2 + sum3)) * 100.0));
    sb.append(String.format(" Number of reflections if complete: %10d", refinementdata.n));

    nobshkl = sum1 + sum2;
    highnobshkl = nhkl[n - 1][0] + nhkl[n - 1][1];
    nobsrfree = sum2;
    highnobsrfree = nhkl[n - 1][1];
    completeness = (((double) sum1 + sum2) / (sum1 + sum2 + sum3)) * 100.0;
    highcompleteness = (((double) nhkl[n - 1][0] + nhkl[n - 1][1])
            / (nhkl[n - 1][0] + nhkl[n - 1][1] + nhkl[n - 1][2])) * 100.0;

    if (print) {
        logger.info(sb.toString());
    }
}

From source file:edu.pitt.csb.mgm.IndTestMultinomialAJ.java

private boolean isIndependentRegression(Node x, Node y, List<Node> z) {
    /*if (!variablesPerNode.containsKey(x)) {
    throw new IllegalArgumentException("Unrecogized node: " + x);
    }//from w w  w. j  a v a  2  s.c o m
            
    if (!variablesPerNode.containsKey(y)) {
    throw new IllegalArgumentException("Unrecogized node: " + y);
    }
            
    for (Node node : z) {
    if (!variablesPerNode.containsKey(x)) {
        throw new IllegalArgumentException("Unrecogized node: " + node);
    }
    }
            
    List<Node> regressors = new ArrayList<Node>();
    regressors.add(internalData.getVariable(y.getName()));
            
    for (Node _z : z) {
    regressors.addAll(variablesPerNode.get(_z));
    }
            
    int[] _rows = getNonMissingRows(x, y, z);
    regression.setRows(_rows);
            
    RegressionResult result;
            
    try {
    result = regression.regress(x, regressors);
    } catch (Exception e) {
    return false;
    }
            
    double p = result.getP()[1];
    this.lastP = p;
            
    boolean indep = p > alpha;
            
    if (verbose) {
    if (indep) {
        TetradLogger.getInstance().log("independencies", SearchLogUtils.independenceFactMsg(x, y, z, p));
    } else {
        TetradLogger.getInstance().log("dependencies", SearchLogUtils.dependenceFactMsg(x, y, z, p));
    }
    }
            
    return indep;*/
    if (!variablesPerNode.containsKey(x)) {
        throw new IllegalArgumentException("Unrecogized node: " + x);
    }

    if (!variablesPerNode.containsKey(y)) {
        throw new IllegalArgumentException("Unrecogized node: " + y);
    }

    for (Node node : z) {
        if (!variablesPerNode.containsKey(node)) {
            throw new IllegalArgumentException("Unrecogized node: " + node);
        }
    }

    List<Node> yzDumList = new ArrayList<>();
    List<Node> yzList = new ArrayList<>();
    yzList.add(y);
    yzList.addAll(z);
    //List<Node> zList = new ArrayList<>();

    yzDumList.addAll(variablesPerNode.get(y));
    for (Node _z : z) {
        yzDumList.addAll(variablesPerNode.get(_z));
        //zList.addAll(variablesPerNode.get(_z));
    }

    int[] _rows = getNonMissingRows(x, y, z);
    regression.setRows(_rows);

    RegressionResult result = null;

    try {
        result = regression.regress(x, yzDumList);
    } catch (Exception e) {
        e.printStackTrace();
    }

    double[] pVec = new double[yzList.size()];
    double[] pCoef = result.getP();

    //skip intercept at 0
    int coeffInd = 1;

    for (int i = 0; i < pVec.length; i++) {
        List<Node> curDummy = variablesPerNode.get(yzList.get(i));
        if (curDummy.size() == 1) {
            pVec[i] = pCoef[coeffInd];
            coeffInd++;
            continue;
        } else {
            pVec[i] = 0;
        }

        for (Node n : curDummy) {
            pVec[i] += Math.log(pCoef[coeffInd]);
            coeffInd++;
        }

        if (pVec[i] == Double.NEGATIVE_INFINITY)
            pVec[i] = 0.0;
        else
            pVec[i] = 1.0 - new ChiSquaredDistribution(2 * curDummy.size()).cumulativeProbability(-2 * pVec[i]);
    }

    double p = pVec[0];
    this.lastP = p;
    boolean indep = p > alpha;

    if (verbose) {
        if (indep) {
            TetradLogger.getInstance().log("independencies", SearchLogUtils.independenceFactMsg(x, y, z, p));
        } else {
            TetradLogger.getInstance().log("dependencies", SearchLogUtils.dependenceFactMsg(x, y, z, p));
        }
    }

    return indep;
}

From source file:eu.cassandra.utils.Utils.java

/**
 * This function is used in order to find the maximum value from an array.
 * /*from  ww  w  .  j a v  a 2 s  .c om*/
 * @param matrix
 * @return
 */
public static double findMax(double[] matrix) {

    double result = Double.NEGATIVE_INFINITY;

    for (int i = 0; i < matrix.length; i++)
        if (result < matrix[i])
            result = matrix[i];

    return result;
}

From source file:Math.java

/**
 * This method returns the log of the sum of the natural
 * exponentiated values in the specified array.  Mathematically,
 * the result is/*  w ww.j  av  a 2s .com*/
 *
 * <blockquote><pre>
 * logSumOfExponentials(xs) = log <big><big>( &Sigma;</big></big><sub>i</sub> exp(xs[i]) <big><big>)</big></big></pre></blockquote>
 *
 * But the result is not calculated directly.  Instead, the
 * calculation performed is:
 *
 * <blockquote><pre>
 * logSumOfExponentials(xs) = max(xs) + log <big><big>( &Sigma;</big></big><sub>i</sub> exp(xs[i] - max(xs)) <big><big>)</big></big></pre></blockquote>
 *
 * which produces the same result, but is much more arithmetically
 * stable, because the largest value for which <code>exp()</code>
 * is calculated is 0.0.
 *
 * <p>Values of {@code Double.NEGATIVE_INFINITY} are treated as
 * having exponentials of 0 and logs of negative infinity.
 * That is, they are ignored for the purposes of this computation.
 *
 * @param xs Array of values.
 * @return The log of the sum of the exponentiated values in the
 * array.
 */
public static double logSumOfExponentials(double[] xs) {
    if (xs.length == 1)
        return xs[0];
    double max = maximum(xs);
    double sum = 0.0;
    for (int i = 0; i < xs.length; ++i)
        if (xs[i] != Double.NEGATIVE_INFINITY)
            sum += java.lang.Math.exp(xs[i] - max);
    return max + java.lang.Math.log(sum);
}

From source file:edu.pitt.csb.mgm.IndTestMixedMultipleTTest.java

private double[] dependencePvalsLinear(Node x, Node y, List<Node> z) {
    if (!variablesPerNode.containsKey(x)) {
        throw new IllegalArgumentException("Unrecogized node: " + x);
    }/*from  w  w  w  .  jav  a 2 s  . c om*/

    if (!variablesPerNode.containsKey(y)) {
        throw new IllegalArgumentException("Unrecogized node: " + y);
    }

    for (Node node : z) {
        if (!variablesPerNode.containsKey(node)) {
            throw new IllegalArgumentException("Unrecogized node: " + node);
        }
    }

    List<Node> yzDumList = new ArrayList<>();
    List<Node> yzList = new ArrayList<>();
    yzList.add(y);
    yzList.addAll(z);
    //List<Node> zList = new ArrayList<>();

    yzDumList.addAll(variablesPerNode.get(y));
    for (Node _z : z) {
        yzDumList.addAll(variablesPerNode.get(_z));
        //zList.addAll(variablesPerNode.get(_z));
    }

    int[] _rows = getNonMissingRows(x, y, z);
    regression.setRows(_rows);

    RegressionResult result;

    try {
        result = regression.regress(x, yzDumList);
    } catch (Exception e) {
        return null;
    }

    double[] pVec = new double[yzList.size()];
    double[] pCoef = result.getP();

    //skip intercept at 0
    int coeffInd = 1;

    for (int i = 0; i < pVec.length; i++) {
        List<Node> curDummy = variablesPerNode.get(yzList.get(i));
        if (curDummy.size() == 1) {
            pVec[i] = pCoef[coeffInd];
            coeffInd++;
            continue;
        } else {
            pVec[i] = 0;
        }

        for (Node n : curDummy) {
            pVec[i] += Math.log(pCoef[coeffInd]);
            coeffInd++;
        }

        if (pVec[i] == Double.NEGATIVE_INFINITY)
            pVec[i] = 0.0;
        else
            pVec[i] = 1.0 - new ChiSquaredDistribution(2 * curDummy.size()).cumulativeProbability(-2 * pVec[i]);
    }

    return pVec;
}

From source file:com.androzic.navigation.NavigationService.java

private void calculateNavigationStatus(Location loc, float smoothspeed, float avgspeed) {
    double distance = Geo.distance(loc.getLatitude(), loc.getLongitude(), navWaypoint.latitude,
            navWaypoint.longitude);//ww w .  ja va2 s.c om
    double bearing = Geo.bearing(loc.getLatitude(), loc.getLongitude(), navWaypoint.latitude,
            navWaypoint.longitude);
    double track = loc.getBearing();

    // turn
    long turn = Math.round(bearing - track);
    if (Math.abs(turn) > 180) {
        turn = turn - (long) (Math.signum(turn)) * 360;
    }

    // vmg
    double vmg = Geo.vmg(smoothspeed, Math.abs(turn));

    // ete
    float curavvmg = (float) Geo.vmg(avgspeed, Math.abs(turn));
    if (avvmg == 0.0 || tics % 10 == 0) {
        for (int i = vmgav.length - 1; i > 0; i--) {
            avvmg += vmgav[i];
            vmgav[i] = vmgav[i - 1];
        }
        avvmg += curavvmg;
        vmgav[0] = curavvmg;
        avvmg = avvmg / vmgav.length;
    }

    int ete = Integer.MAX_VALUE;
    if (avvmg > 0)
        ete = (int) Math.round(distance / avvmg / 60);

    double xtk = Double.NEGATIVE_INFINITY;

    if (navRoute != null) {
        boolean hasNext = hasNextRouteWaypoint();
        if (distance < navProximity) {
            if (hasNext) {
                nextRouteWaypoint();
                return;
            } else {
                updateNavigationState(STATE_REACHED);
                stopNavigation();
                return;
            }
        }

        if (prevWaypoint != null) {
            double dtk = Geo.bearing(prevWaypoint.latitude, prevWaypoint.longitude, navWaypoint.latitude,
                    navWaypoint.longitude);
            xtk = Geo.xtk(distance, dtk, bearing);

            if (xtk == Double.NEGATIVE_INFINITY) {
                if (useTraverse && hasNext) {
                    double cxtk2 = Double.NEGATIVE_INFINITY;
                    MapObject nextWpt = getNextRouteWaypoint();
                    if (nextWpt != null) {
                        double dtk2 = Geo.bearing(nextWpt.latitude, nextWpt.longitude, navWaypoint.latitude,
                                navWaypoint.longitude);
                        cxtk2 = Geo.xtk(0, dtk2, bearing);
                    }

                    if (cxtk2 != Double.NEGATIVE_INFINITY) {
                        nextRouteWaypoint();
                        return;
                    }
                }
            }
        }
    }

    tics++;

    if (distance != navDistance || bearing != navBearing || turn != navTurn || vmg != navVMG || ete != navETE
            || xtk != navXTK) {
        navDistance = distance;
        navBearing = bearing;
        navTurn = turn;
        navVMG = vmg;
        navETE = ete;
        navXTK = xtk;
        updateNavigationStatus();
    }
}

From source file:org.powertac.householdcustomer.customers.Household.java

/** This function returns the dominant appliance of the household. */
public void findDominantAppliance() {
    double maxConsumption = Double.NEGATIVE_INFINITY;

    for (int i = 0; i < appliances.size(); i++) {
        if (maxConsumption < appliances.get(i).getOverallPower()) {
            maxConsumption = appliances.get(i).getOverallPower();
            dominantAppliance = i;//w ww.j  a v a  2  s .co m
        }
    }

}