Example usage for java.lang Double NaN

List of usage examples for java.lang Double NaN

Introduction

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

Prototype

double NaN

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

Click Source Link

Document

A constant holding a Not-a-Number (NaN) value of type double .

Usage

From source file:com.itemanalysis.psychometrics.polycor.PolyserialPlugin.java

/**
* Correct pearson correlation for spuriousness due to including the studied
 * item score Y in the computation of X values. This method is used for the
 * polyserial correlation in an item analysis.
*
* @return correlation corrected for spuriousness
*///  ww  w  . j  a v a 2 s.com
public double spuriousCorrectedPearsonCorrelation() {
    double testSd = sdX.getResult();
    double itemSd = sdY.getResult();
    double rOld = r.value();
    double denom = Math.sqrt(itemSd * itemSd + testSd * testSd - 2 * rOld * itemSd * testSd);
    if (denom == 0.0)
        return Double.NaN;
    return (rOld * testSd - itemSd) / denom;
}

From source file:com.espertech.esper.regression.resultset.TestGroupByMedianAndDeviation.java

public void testSumOneView() {
    String viewExpr = "select irstream symbol," + "median(all price) as myMedian,"
            + "median(distinct price) as myDistMedian," + "stddev(all price) as myStdev,"
            + "avedev(all price) as myAvedev " + "from " + SupportMarketDataBean.class.getName()
            + ".win:length(5) " + "where symbol='DELL' or symbol='IBM' or symbol='GE' " + "group by symbol";

    EPStatement selectTestView = epService.getEPAdministrator().createEPL(viewExpr);
    selectTestView.addListener(testListener);

    runAssertion(selectTestView);//  w  w  w .jav a2s . c  om

    // Test NaN sensitivity
    selectTestView.destroy();
    selectTestView = epService.getEPAdministrator().createEPL(
            "select stddev(price) as val from " + SupportMarketDataBean.class.getName() + ".win:length(3)");
    selectTestView.addListener(testListener);

    sendEvent("A", Double.NaN);
    sendEvent("B", Double.NaN);
    sendEvent("C", Double.NaN);
    sendEvent("D", 1d);
    sendEvent("E", 2d);
    testListener.reset();
    sendEvent("F", 3d);
    Double result = (Double) testListener.assertOneGetNewAndReset().get("val");
    assertTrue(result.isNaN());
}

From source file:com.ironiacorp.statistics.r.type.GenericAnovaResult.java

/**
 * @param factorsName e.g. f,g//from   w  ww . ja v  a 2 s .  c  om
 * @return
 */
public Double getInteractionEffectP(String... factorNames) {
    InteractionFactor interactionFactor = new InteractionFactor(factorNames);
    if (!interactionEffects.containsKey(interactionFactor)) {
        return Double.NaN;
    }
    return interactionEffects.get(interactionFactor).getPValue();
}

From source file:de.thkwalter.jsf.converter.CSVConverter.java

/**
 * Diese Methode konvertiert eine Zeichenketten im CSV-Format in ein Feld von {@link Vector2D}-Objekten. Zwei Datenstze 
 * der Zeichenkette sind jeweils durch einen Zeilenumbruch getrennt. Jeder Datensatz besteht aus zwei Datenfeldern, die 
 * durch ein Komma getrennt sind. Jedes Datenfeld besteht aus einem double-Wert.
 *  /*from  w  w w. j a  v a 2 s  .c  o m*/
 * @param facesContext Das Kontext-Objekt
 * @param uiComponent Die UI-Komponente, welche die Quelle der Zeichenkette ist.
 * @param eingabe Die Zeichenkette, die konvertiert werden soll.
 * 
 * @return Ein Feld von {@link Vector2D}-Objekten.
 *  
 * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext, javax.faces.component.UIComponent, 
 * java.lang.String)
 */
@Override
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String eingabe) {
    // Das Feld, das die Vektoren speichern soll, wird deklariert.
    Vector2D[] vektoren = null;

    try {
        // Die Zeichenkette wird in Zeilen zerlegt.
        String[] zeilen = eingabe.trim().split("\n");

        // Das Feld, das die Vektoren speichern soll, wird erzeugt.
        vektoren = new Vector2D[zeilen.length];

        // Einige Variablen und Referenzen werden deklariert.
        String[] datenfelder = null;
        double x = Double.NaN;
        double y = Double.NaN;

        // In dieser Schleife werden die einzelnen Zeilen in Vektoren umgewandelt.
        for (int i = 0; i < zeilen.length; i++) {
            // Die einzelnen Zeilen werden in Datenfelder zerlegt.
            datenfelder = zeilen[i].split(",");

            // Die Zeichenketten der Datenfelder werden in double-Werte umgewandelt.
            x = Double.parseDouble(datenfelder[0].trim());
            y = Double.parseDouble(datenfelder[1].trim());

            // Ein Vektor wird erzeugt und dem Feld der Vektoren hinzugefgt.
            vektoren[i] = new Vector2D(x, y);

            // Der Vektor wird protokolliert.
            CSVConverter.logger.fine(vektoren[i].toString());
        }
    }

    // Falls eine Ausnahme geworfen worden ist, wird diese behandelt.
    catch (Exception exception) {
        // Die Fehlermeldung fr den Entwickler wird erzeugt und protokolliert.
        String fehlermeldung = "Die eingegebene Zeichenkette (" + eingabe
                + ") besitzt nicht das richtige Format!";
        CSVConverter.logger.log(Level.SEVERE, fehlermeldung);

        // Die Meldung fr die Oberflche und eine Ausnahme werden erzeugt und mit der Fehlermeldung fr den Benutzer
        // initialisiert.
        String jsfMeldung = "Die Messpunkte wurden nicht im korrekten Format eingegeben! "
                + "Korrigieren Sie bitte das Format ihrer Eingabe.";
        facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, jsfMeldung, ""));
        ConverterException converterException = new ConverterException(jsfMeldung);

        // Die ConverterException wird geworfen.
        throw converterException;
    }

    // Das Feld, das die Vektoren speichert, wird zurckgegeben.
    return vektoren;
}

From source file:com.clust4j.algo.preprocess.StandardScaler.java

@Override
public StandardScaler fit(RealMatrix data) {
    synchronized (fitLock) {
        final int m = data.getRowDimension();
        final int n = data.getColumnDimension();

        if (m < 2)
            throw new IllegalArgumentException(
                    "cannot " + "meaningfully compute standard deviation " + "on fewer than two observations");

        // need to mean center...
        this.means = new double[n];
        this.stdevs = new double[n];

        final double[][] X = data.getData();

        for (int col = 0; col < n; col++) {
            double var, std, mn;
            double sumSq = 0.0;
            double sum = 0.0;

            for (int row = 0; row < m; row++) {
                sumSq += X[row][col] * X[row][col];
                sum += X[row][col];/* w  w  w  . jav a2  s. co  m*/
            }

            /*
             * A naive algorithm to calculate the estimated variance (1M):
             * 
             * Let n = 0, Sum = 0, SumSq = 0 
             * For each datum x: 
             *   n = n + 1 
             *   Sum = Sum + x 
             *   SumSq = SumSq + x * x 
             * Var = (SumSq - (Sum * Sum) / n) / (n - 1)
             * 
             * @see https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
             */
            var = (sumSq - (sum * sum) / (double) m) / ((double) m - 1.0);
            std = m < 2 ? Double.NaN : FastMath.sqrt(var);
            mn = sum / (double) m;

            means[col] = mn;
            stdevs[col] = std;
        }

        return this;
    }
}

From source file:com.joptimizer.optimizers.NewtonLEConstrainedFSP.java

@Override
public int optimize() throws Exception {
    Log.d(MainActivity.JOPTIMIZER_LOGTAG, "optimize");
    OptimizationResponse response = new OptimizationResponse();

    //checking responsibility
    if (getFi() != null) {
        // forward to the chain
        return forwardOptimizationRequest();
    }/*from w ww  .j  a v  a 2  s. com*/

    long tStart = System.currentTimeMillis();

    //initial point must be feasible (i.e., satisfy x in domF and Ax = b).
    DoubleMatrix1D X0 = getInitialPoint();
    double rPriX0Norm = (X0 != null) ? Math.sqrt(ALG.norm2(rPri(X0))) : 0d;
    //if (X0 == null   || (getA()!=null && Double.compare(ALG.norm2(getA().zMult(X0, getB().copy(), 1., -1., false)), 0d) != 0)) {
    //if (X0 == null   || rPriX0Norm > Utils.getDoubleMachineEpsilon()) {   
    if (X0 == null || rPriX0Norm > getTolerance()) {
        // infeasible starting point, forward to the chain
        return forwardOptimizationRequest();
    }

    if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) {
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "X0:  " + ArrayUtils.toString(X0.toArray()));
    }
    DoubleMatrix1D X = X0;
    double F0X;
    //double previousF0X = Double.NaN;
    double previousLambda = Double.NaN;
    int iteration = 0;
    while (true) {
        iteration++;
        F0X = getF0(X);
        if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) {
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "iteration " + iteration);
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "X=" + ArrayUtils.toString(X.toArray()));
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "f(X)=" + F0X);
        }

        //         if(!Double.isNaN(previousF0X)){
        //            if (previousF0X < F0X) {
        //               throw new Exception("critical minimization problem");
        //            }
        //         }
        //         previousF0X = F0X;

        // custom exit condition
        if (checkCustomExitConditions(X)) {
            response.setReturnCode(OptimizationResponse.SUCCESS);
            break;
        }

        DoubleMatrix1D gradX = getGradF0(X);
        DoubleMatrix2D hessX = getHessF0(X);

        double gradXNorm = Math.sqrt(ALG.norm2(gradX));
        if (gradXNorm < Utils.getDoubleMachineEpsilon()) {
            response.setReturnCode(OptimizationResponse.SUCCESS);
            break;
        }

        // Newton step and decrement
        if (this.kktSolver == null) {
            this.kktSolver = new BasicKKTSolver();
        }
        if (isCheckKKTSolutionAccuracy()) {
            kktSolver.setCheckKKTSolutionAccuracy(isCheckKKTSolutionAccuracy());
            kktSolver.setToleranceKKT(getToleranceKKT());
        }
        kktSolver.setHMatrix(hessX.toArray());
        kktSolver.setGVector(gradX.toArray());
        if (getA() != null) {
            kktSolver.setAMatrix(getA().toArray());
            kktSolver.setATMatrix(getAT().toArray());
        }
        double[][] sol = kktSolver.solve();
        DoubleMatrix1D step = F1.make(sol[0]);
        DoubleMatrix1D w = (sol[1] != null) ? F1.make(sol[1]) : F1.make(0);
        if (Log.isLoggable(MainActivity.JOPTIMIZER_LOGTAG, Log.DEBUG)) {
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "stepX: " + ArrayUtils.toString(step.toArray()));
            Log.d(MainActivity.JOPTIMIZER_LOGTAG, "w    : " + ArrayUtils.toString(w.toArray()));
        }

        // exit condition: check the Newton decrement
        double lambda = Math.sqrt(ALG.mult(step, ALG.mult(hessX, step)));
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "lambda: " + lambda);
        if (lambda / 2. <= getTolerance()) {
            response.setReturnCode(OptimizationResponse.SUCCESS);
            break;
        }

        // iteration limit condition
        if (iteration == getMaxIteration()) {
            response.setReturnCode(OptimizationResponse.WARN);
            Log.w(MainActivity.JOPTIMIZER_LOGTAG, "Max iterations limit reached");
            break;
        }

        // progress conditions
        if (isCheckProgressConditions()) {
            if (!Double.isNaN(previousLambda) && previousLambda <= lambda) {
                Log.w(MainActivity.JOPTIMIZER_LOGTAG,
                        "No progress achieved, exit iterations loop without desired accuracy");
                response.setReturnCode(OptimizationResponse.WARN);
                break;
            }
        }
        previousLambda = lambda;

        // backtracking line search
        double s = 1d;
        DoubleMatrix1D X1 = null;
        int cnt = 0;
        while (cnt < 250) {
            cnt++;
            // @TODO: can we use simplification 9.7.1 ??
            X1 = X.copy().assign(step.copy().assign(Mult.mult(s)), Functions.plus);// x + t*step
            //Log.d(MainActivity.JOPTIMIZER_LOGTAG,"X1: "+ArrayUtils.toString(X1.toArray()));

            if (isInDomainF0(X1)) {
                double condSX = getF0(X1);
                //NB: this will also check !Double.isNaN(getF0(X1))
                double condDX = F0X + getAlpha() * s * ALG.mult(gradX, step);
                //Log.d(MainActivity.JOPTIMIZER_LOGTAG,"condSX: "+condSX);
                //Log.d(MainActivity.JOPTIMIZER_LOGTAG,"condDX: "+condDX);
                if (condSX <= condDX) {
                    break;
                }
            }
            s = getBeta() * s;
        }
        Log.d(MainActivity.JOPTIMIZER_LOGTAG, "s: " + s);

        // update
        X = X1;
    }

    long tStop = System.currentTimeMillis();
    Log.d(MainActivity.JOPTIMIZER_LOGTAG, "time: " + (tStop - tStart));
    response.setSolution(X.toArray());
    setOptimizationResponse(response);
    return response.getReturnCode();
}

From source file:jasima.core.statistics.SummaryStat.java

/**
 * Resets this object./*www.  j a  v  a 2s  .co  m*/
 */
public void clear() {
    meanEst = 0.0;
    varEst = 0.0d;
    numObs = 0;
    weightSum = 0.0d;
    min = Double.POSITIVE_INFINITY;
    max = Double.NEGATIVE_INFINITY;
    lastValue = Double.NaN;
    lastWeight = Double.NaN;
}

From source file:eu.amidst.core.utils.Utils.java

/**
 * Sets a missing value as a Double.NaN.
 * @return a Double.NaN.
 */
public static double missingValue() {
    return Double.NaN;
}

From source file:com.itemanalysis.psychometrics.polycor.Covariance.java

public Double varX(boolean unbiased) {
    if (N < 1)
        return Double.NaN;
    if (unbiased) {
        return varNumeratorX / (N - 1.0);
    } else {//w w w .  j  a v  a 2  s . c om
        return varNumeratorX / N;
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.BubbleRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2             the graphics device.
 * @param state          the renderer state.
 * @param dataArea       the area within which the data is being drawn.
 * @param info           collects information about the drawing.
 * @param plot           the plot (can be used to obtain standard color information etc).
 * @param domainAxis     the domain (horizontal) axis.
 * @param rangeAxis      the range (vertical) axis.
 * @param dataset        the dataset (an {@link XYZDataset} is expected).
 * @param series         the series index (zero-based).
 * @param item           the item index (zero-based).
 * @param crosshairState crosshair information for the plot (<code>null</code> permitted).
 * @param pass           the pass index.
 *///  w w w .  j  a  va 2  s .c om
public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea,
        final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis,
        final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState,
        final int pass) {

    final PlotOrientation orientation = plot.getOrientation();

    // get the data point...
    final double x = dataset.getXValue(series, item);
    final double y = dataset.getYValue(series, item);
    double z = Double.NaN;
    if (dataset instanceof XYZDataset) {
        final XYZDataset xyzData = (XYZDataset) dataset;
        z = xyzData.getZValue(series, item);
    }
    if (!Double.isNaN(z)) {
        final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
        final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
        final double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
        final double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);

        double circleSize;

        circleSize = maxSize * (z / maxZ);

        circleSize = Math.abs(circleSize);

        Ellipse2D circle = null;
        if (orientation == PlotOrientation.VERTICAL) {
            circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize,
                    circleSize);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize,
                    circleSize);
        }
        g2.setPaint(getItemPaint(series, item));
        g2.fill(circle);
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(circle);

        if (isItemLabelVisible(series, item)) {
            if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
            } else if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
            }
        }

        // setup for collecting optional entity info...
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }

        // add an entity for the item...
        if (entities != null) {
            String tip = null;
            final XYToolTipGenerator generator = getToolTipGenerator(series, item);
            if (generator != null) {
                tip = generator.generateToolTip(dataset, series, item);
            }
            String url = null;
            if (getURLGenerator() != null) {
                url = getURLGenerator().generateURL(dataset, series, item);
            }
            final XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url);
            entities.add(entity);
        }

        final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                orientation);
    }

}