Example usage for java.lang Double compare

List of usage examples for java.lang Double compare

Introduction

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

Prototype

public static int compare(double d1, double d2) 

Source Link

Document

Compares the two specified double values.

Usage

From source file:de.bund.bfr.knime.pmm.common.chart.Plotable.java

public double[][] getPoints(String paramX, String paramY, String unitX, String unitY, String transformX,
        String transformY, Map<String, Integer> choice) throws ConvertException {
    List<Double> xList = valueLists.get(paramX);
    List<Double> yList = valueLists.get(paramY);

    if (xList == null || yList == null) {
        return null;
    }// w w w.  j a  va  2 s. c o  m

    List<Boolean> usedPoints = new ArrayList<>(Collections.nCopies(xList.size(), true));

    if (type == BOTH_STRICT || type == DATASET_STRICT) {
        for (String arg : functionArguments.keySet()) {
            if (!arg.equals(paramX) && valueLists.containsKey(arg)) {
                Double fixedValue = functionArguments.get(arg).get(choice.get(arg));
                List<Double> values = valueLists.get(arg);

                for (int i = 0; i < values.size(); i++) {
                    if (!fixedValue.equals(values.get(i))) {
                        usedPoints.set(i, false);
                    }
                }
            }
        }

        if (!usedPoints.contains(true)) {
            return null;
        }
    }

    List<Point2D.Double> points = new ArrayList<>(xList.size());

    for (int i = 0; i < xList.size(); i++) {
        Double x = xList.get(i);
        Double y = yList.get(i);

        if (x != null) {
            x = convertToUnit(paramX, x, unitX);
            x = transform(x, transformX);
        }

        if (y != null) {
            y = convertToUnit(paramY, y, unitY);
            y = transform(y, transformY);
        }

        if (usedPoints.get(i) && isValidValue(x) && isValidValue(y)) {
            points.add(new Point2D.Double(x, y));
        }
    }

    Collections.sort(points, new Comparator<Point2D.Double>() {

        @Override
        public int compare(Point2D.Double p1, Point2D.Double p2) {
            return Double.compare(p1.x, p2.x);
        }
    });

    double[][] pointsArray = new double[2][points.size()];

    for (int i = 0; i < points.size(); i++) {
        pointsArray[0][i] = points.get(i).x;
        pointsArray[1][i] = points.get(i).y;
    }

    return pointsArray;
}

From source file:ch.ralscha.extdirectspring.controller.RouterControllerFormLoadTest.java

private static void checkFormLoadResult(ExtDirectResponse resp, double back, int tid) {
    assertThat(resp.getAction()).isEqualTo("remoteProviderFormLoad");
    assertThat(resp.getMethod()).isEqualTo("method1");
    assertThat(resp.getTid()).isEqualTo(tid);
    assertThat(resp.getType()).isEqualTo("rpc");
    assertThat(resp.getWhere()).isNull();
    assertThat(resp.getMessage()).isNull();
    assertThat(resp.getResult()).isNotNull();

    ExtDirectFormLoadResult wrapper = ControllerUtil.convertValue(resp.getResult(),
            ExtDirectFormLoadResult.class);
    assertThat(wrapper.isSuccess()).isTrue();
    assertThat(wrapper.getData()).isNotNull();

    FormInfo info = ControllerUtil.convertValue(wrapper.getData(), FormInfo.class);

    assertThat(Double.compare(back, info.getBack()) == 0).isTrue();
    assertThat(info.isAdmin()).isEqualTo(true);
    assertThat(info.getAge()).isEqualTo(31);
    assertThat(info.getName()).isEqualTo("Bob");
    assertThat(info.getSalary()).isEqualTo(new BigDecimal("10000.55"));
    assertThat(info.getBirthday()).isEqualTo(new GregorianCalendar(1980, Calendar.JANUARY, 15).getTime());
}

From source file:azkaban.project.FlowLoaderUtils.java

/**
 * Check if azkaban flow version is 2.0.
 *
 * @param azkabanFlowVersion the azkaban flow version
 * @return the boolean/*from w  w  w .  ja  v  a  2s .c  o  m*/
 */
public static boolean isAzkabanFlowVersion20(final double azkabanFlowVersion) {
    return Double.compare(azkabanFlowVersion, Constants.AZKABAN_FLOW_VERSION_2_0) == 0;
}

From source file:org.sleuthkit.autopsy.timeline.ui.AbstractVisualizationPane.java

/**
 * iterate through the list of tick-marks building a two level structure of
 * replacement tick marl labels. (Visually) upper level has most
 * detailed/highest frequency part of date/time. Second level has rest of
 * date/time grouped by unchanging part. eg:
 *
 *
 * october-30_october-31_september-01_september-02_september-03
 *
 * becomes// www .j a  v  a  2 s . c o m
 *
 * _________30_________31___________01___________02___________03
 *
 * _________october___________|_____________september___________
 *
 *
 * NOTE: This method should only be invoked on the JFX thread
 */
public synchronized void layoutDateLabels() {

    //clear old labels
    branchPane.getChildren().clear();
    leafPane.getChildren().clear();
    //since the tickmarks aren't necessarily in value/position order,
    //make a clone of the list sorted by position along axis
    ObservableList<Axis.TickMark<X>> tickMarks = FXCollections.observableArrayList(getXAxis().getTickMarks());
    tickMarks.sort(
            (Axis.TickMark<X> t, Axis.TickMark<X> t1) -> Double.compare(t.getPosition(), t1.getPosition()));

    if (tickMarks.isEmpty() == false) {
        //get the spacing between ticks in the underlying axis
        double spacing = getTickSpacing();

        //initialize values from first tick
        TwoPartDateTime dateTime = new TwoPartDateTime(getTickMarkLabel(tickMarks.get(0).getValue()));
        String lastSeenBranchLabel = dateTime.branch;
        //cumulative width of the current branch label

        //x-positions (pixels) of the current branch and leaf labels
        double leafLabelX = 0;

        if (dateTime.branch.isEmpty()) {
            //if there is only one part to the date (ie only year), just add a label for each tick
            for (Axis.TickMark<X> t : tickMarks) {
                assignLeafLabel(new TwoPartDateTime(getTickMarkLabel(t.getValue())).leaf, spacing, leafLabelX,
                        isTickBold(t.getValue()));

                leafLabelX += spacing; //increment x
            }
        } else {
            //there are two parts so ...
            //initialize additional state
            double branchLabelX = 0;
            double branchLabelWidth = 0;

            for (Axis.TickMark<X> t : tickMarks) { //for each tick

                //split the label into a TwoPartDateTime
                dateTime = new TwoPartDateTime(getTickMarkLabel(t.getValue()));

                //if we are still on the same branch
                if (lastSeenBranchLabel.equals(dateTime.branch)) {
                    //increment branch width
                    branchLabelWidth += spacing;
                } else {// we are on to a new branch, so ...
                    assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX);
                    //and then update label, x-pos, and width
                    lastSeenBranchLabel = dateTime.branch;
                    branchLabelX += branchLabelWidth;
                    branchLabelWidth = spacing;
                }
                //add the label for the leaf (highest frequency part)
                assignLeafLabel(dateTime.leaf, spacing, leafLabelX, isTickBold(t.getValue()));

                //increment leaf position
                leafLabelX += spacing;
            }
            //we have reached end so add branch label for current branch
            assignBranchLabel(lastSeenBranchLabel, branchLabelWidth, branchLabelX);
        }
    }
    //request layout since we have modified scene graph structure
    requestParentLayout();
}

From source file:de.tudarmstadt.ukp.dkpro.core.mallet.lda.MalletLdaTopicModelInferencer.java

/**
 * Assign topics according to the following formula:
 * <p>/*w w  w . j  a  v a2s  .c o m*/
 * Topic proportion must be at least the maximum topic's proportion divided by the maximum
 * number of topics to be assigned. In addition, the topic proportion must not lie under the
 * minTopicProb. If more topics comply with these criteria, only retain the n
 * (maxTopicAssignments) largest values.
 *
 * @param topicDistribution a double array containing the document's topic proportions
 * @return an array of integers pointing to the topics assigned to the document
 * @deprecated this method should be removed at some point because assignment / topic tagging
 * should be done in a dedicated step (module).
 */
// TODO: should return a boolean[] of the same size as topicDistribution
// TODO: should probably be moved to a dedicated module because assignments (topic tagging)
// should not be done at inference level
@Deprecated
private int[] assignTopics(final double[] topicDistribution) {
    /*
     * threshold is the largest value divided by the maximum number of topics or the fixed
     * number set as minTopicProb parameter.
     */
    double threshold = Math
            .max(Collections.max(Arrays.asList(ArrayUtils.toObject(topicDistribution))).doubleValue()
                    / maxTopicAssignments, minTopicProb);

    /*
     * assign indexes for values that are above threshold
     */
    List<Integer> indexes = new ArrayList<>(topicDistribution.length);
    for (int i = 0; i < topicDistribution.length; i++) {
        if (topicDistribution[i] >= threshold) {
            indexes.add(i);
        }
    }

    /*
     * Reduce assignments to maximum number of allowed assignments.
     */
    if (indexes.size() > maxTopicAssignments) {

        /* sort index list by corresponding values */
        Collections.sort(indexes, (aO1, aO2) -> Double.compare(topicDistribution[aO1], topicDistribution[aO2]));

        while (indexes.size() > maxTopicAssignments) {
            indexes.remove(0);
        }
    }

    return ArrayUtils.toPrimitive(indexes.toArray(new Integer[indexes.size()]));
}

From source file:us.levk.math.linear.HugeRealMatrix.java

@Override
public RealMatrix copy() {
    HugeRealMatrix result = createMatrix(rowDimension, columnDimension);
    for (int row = rowDimension; --row >= 0;)
        for (int column = columnDimension; --column >= 0;) {
            double value = getEntry(row, column);
            if (Double.compare(value, 0.0) != 0)
                result.setEntry(row, column, value);
        }/*from  w  ww  . ja  va  2  s  .co m*/
    return result;
}

From source file:org.phenotips.remote.common.internal.api.DefaultPatientToJSONConverter.java

private static JSONArray genes(Patient patient, int includedTopGenes, Logger logger) {
    PatientGenotype genotype = new PatientGenotype(patient);

    JSONArray genes = new JSONArray();
    try {/*from w ww . j av a2 s  . c  om*/
        Collection<String> candidateGeneNames;
        //Collection<String> candidateGeneNames = getPatientCandidateGeneNames(patient);
        if (includedTopGenes <= 0) {
            candidateGeneNames = genotype.getCandidateGenes();
        } else {
            final Map<String, Double> genesWithScore = new HashMap<String, Double>();
            Collection<String> allGenes = genotype.getGenes();
            for (String gene : allGenes) {
                genesWithScore.put(gene, genotype.getGeneScore(gene));
            }
            Set<String> set = genesWithScore.keySet();
            List<String> keys = new ArrayList<String>(set);
            Collections.sort(keys, new Comparator<String>() {
                public int compare(String s1, String s2) {
                    // Sort by score, descending
                    return Double.compare(genesWithScore.get(s2), genesWithScore.get(s1));
                }
            });
            List<String> topGenes = keys.subList(0, Math.min(keys.size(), includedTopGenes));
            candidateGeneNames = new HashSet<String>();
            for (String topGene : topGenes) {
                candidateGeneNames.add(topGene);
            }
        }

        for (String geneName : candidateGeneNames) {
            JSONObject nextGene = new JSONObject();
            nextGene.put(ApiConfiguration.JSON_GENES_GENENAME, geneName);
            nextGene.put(ApiConfiguration.JSON_GENES_ASSEMBLY, "GRCh37"); // TODO: pull from candidate genes/patient/vcf?
            genes.add(nextGene);
        }
    } catch (Exception ex) {
        logger.error("Error getting candidate genes for patient [{}]: [{}]", patient.getId(), ex);
        return new JSONArray();
    }
    return genes;
}

From source file:org.earthtime.UPb_Redux.dateInterpretation.WeightedMeanGraphPanel.java

/**
 *
 * @param g2d//from   w w w .  ja v  a2  s .  com
 */
public void paint(Graphics2D g2d) {

    // setup painting parameters
    String fractionSortOrder = "name"; //random, weight, date
    if (getWeightedMeanOptions().containsKey("fractionSortOrder")) {
        fractionSortOrder = getWeightedMeanOptions().get("fractionSortOrder");
    }

    double rangeX = (getMaxX_Display() - getMinX_Display());
    double rangeY = (getMaxY_Display() - getMinY_Display());

    g2d.setClip(getLeftMargin(), getTopMargin(), getGraphWidth(), getGraphHeight());
    RenderingHints rh = g2d.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHints(rh);

    // walk the sampleDateInterpretations and produce graphs
    g2d.setPaint(Color.BLACK);
    g2d.setStroke(new BasicStroke(2.0f));
    g2d.setFont(new Font("SansSerif", Font.BOLD, 10));

    double barWidth = 15.0;
    double barGap = 10.0;
    double startSamX = 10.0;
    double saveStartSamX = 0.0;
    double samSpace = 3.0;

    for (int i = 0; i < selectedSampleDateModels.length; i++) {
        for (int j = 1; j < 9; j++) {
            if (selectedSampleDateModels[i][j] instanceof SampleDateModel) {

                final SampleDateModel SAM = ((SampleDateModel) selectedSampleDateModels[i][j]);
                double wMean = SAM.getValue().movePointLeft(6).doubleValue();
                double wMeanOneSigma = SAM.getOneSigmaAbs().movePointLeft(6).doubleValue();

                Path2D mean = new Path2D.Double(Path2D.WIND_NON_ZERO);

                // july 2008
                // modified to show de-selected fractions as gray
                // this means a new special list of fractionIDs is created fromall non-rejected fractions
                // and each instance is tested for being included
                // should eventually refactor
                Vector<String> allFIDs = new Vector<String>();
                for (String f : ((UPbReduxAliquot) SAM.getAliquot()).getAliquotFractionIDs()) {
                    // test added for Sample-based wm
                    if (SAM.fractionDateIsPositive(//
                            ((UPbReduxAliquot) SAM.getAliquot()).getAliquotFractionByName(f))) {
                        allFIDs.add(f);
                    }
                }

                final int iFinal = i;
                if (fractionSortOrder.equalsIgnoreCase("weight")) {
                    Collections.sort(allFIDs, new Comparator<String>() {

                        public int compare(String fID1, String fID2) {
                            double invertOneSigmaF1 = //
                                    1.0 //
                                            / ((UPbReduxAliquot) selectedSampleDateModels[iFinal][0])//
                                                    .getAliquotFractionByName(fID1)//
                                                    .getRadiogenicIsotopeDateByName(SAM.getDateName())//
                                                    .getOneSigmaAbs().movePointLeft(6).doubleValue();
                            double invertOneSigmaF2 = //
                                    1.0 //
                                            / ((UPbReduxAliquot) selectedSampleDateModels[iFinal][0])//
                                                    .getAliquotFractionByName(fID2)//
                                                    .getRadiogenicIsotopeDateByName(SAM.getDateName())//
                                                    .getOneSigmaAbs().movePointLeft(6).doubleValue();

                            return Double.compare(invertOneSigmaF2, invertOneSigmaF1);
                        }
                    });
                } else if (fractionSortOrder.equalsIgnoreCase("date")) {
                    Collections.sort(allFIDs, new Comparator<String>() {

                        public int compare(String fID1, String fID2) {
                            double dateF1 = //
                                    ((UPbReduxAliquot) selectedSampleDateModels[iFinal][0])//
                                            .getAliquotFractionByName(fID1)//
                                            .getRadiogenicIsotopeDateByName(SAM.getDateName())//
                                            .getValue().doubleValue();
                            double dateF2 = //
                                    ((UPbReduxAliquot) selectedSampleDateModels[iFinal][0])//
                                            .getAliquotFractionByName(fID2)//
                                            .getRadiogenicIsotopeDateByName(SAM.getDateName())//
                                            .getValue().doubleValue();

                            return Double.compare(dateF1, dateF2);
                        }
                    });
                } else if ( /* ! isInRandomMode() &&*/fractionSortOrder.equalsIgnoreCase("random")) {
                    Collections.shuffle(allFIDs, new Random());
                } else if (fractionSortOrder.equalsIgnoreCase("name")) {
                    // default to alphabetic by name
                    //Collections.sort(allFIDs);
                    // april 2010 give same lexigraphic ordering that UPbFractions get
                    Collections.sort(allFIDs, new IntuitiveStringComparator<String>());
                } else {
                    // do nothing
                }

                double actualWidthX = (allFIDs.size()) * (barWidth + barGap);//; + barGap;

                // plot 2-sigma of mean
                mean.moveTo((float) mapX(startSamX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(wMean + 2.0 * wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight));
                mean.lineTo((float) mapX(startSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(wMean + 2.0 * wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight));
                mean.lineTo((float) mapX(startSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(wMean - 2.0 * wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight));
                mean.lineTo((float) mapX(startSamX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(wMean - 2.0 * wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight));
                mean.closePath();

                g2d.setColor(ReduxConstants.mySampleYellowColor);
                g2d.fill(mean);
                g2d.setPaint(Color.BLACK);

                // plot 1-sigma of mean
                mean.reset();
                mean.moveTo((float) mapX(startSamX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(wMean + wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight));
                mean.lineTo((float) mapX(startSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(wMean + wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight));
                mean.lineTo((float) mapX(startSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(wMean - wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight));
                mean.lineTo((float) mapX(startSamX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(wMean - wMeanOneSigma, getMaxY_Display(), rangeY, graphHeight));
                mean.closePath();

                g2d.setColor(ReduxConstants.ColorOfRedux);
                g2d.fill(mean);
                g2d.setPaint(Color.BLACK);

                // plot mean
                mean.reset();
                mean.moveTo((float) mapX(startSamX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(wMean, getMaxY_Display(), rangeY, graphHeight));
                mean.lineTo((float) mapX(startSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(wMean, getMaxY_Display(), rangeY, graphHeight));
                g2d.setStroke(new BasicStroke(1.0f));
                g2d.draw(mean);
                g2d.setStroke(new BasicStroke(2.0f));

                saveStartSamX = startSamX;

                // plot fraction bars
                double minPoint = 5000.0;
                double maxWeight = 0.0;
                double totalWeight = 0.0;

                int barNum = 0;

                for (String fID : allFIDs) {
                    // the dateModel has an associated aliquot, but in sample mode, it is a
                    // standin aliquot for the sample.  to get the aliquot number for
                    // use in coloring fractions, we need to query the fraction itself
                    String aliquotName = sample.getAliquotNameByFractionID(fID);

                    Color includedFillColor = new Color(0, 0, 0);
                    if (sample.getSampleDateInterpretationGUISettings().getAliquotOptions().get(aliquotName)
                            .containsKey("includedFillColor")) {
                        String[] temp = //
                                sample.getSampleDateInterpretationGUISettings().getAliquotOptions()
                                        .get(aliquotName).get("includedFillColor").split(",");
                        includedFillColor = buildRGBColor(temp);
                    }

                    Fraction f = ((UPbReduxAliquot) selectedSampleDateModels[i][0])
                            .getAliquotFractionByName(fID);

                    double date = f.//((UPbReduxAliquot) selectedSampleDateModels[i][0]).getAliquotFractionByName(fID).//
                            getRadiogenicIsotopeDateByName(SAM.getDateName()).getValue().movePointLeft(6)
                            .doubleValue();
                    double twoSigma = f.//((UPbReduxAliquot) selectedSampleDateModels[i][0]).getAliquotFractionByName(fID).//
                            getRadiogenicIsotopeDateByName(SAM.getDateName()).getTwoSigmaAbs().movePointLeft(6)
                            .doubleValue();

                    if ((date - twoSigma) < minPoint) {
                        minPoint = (date - twoSigma);
                    }

                    double invertedOneSigma = //
                            1.0 //
                                    / f.//((UPbReduxAliquot) selectedSampleDateModels[i][0]).getAliquotFractionByName(fID).//
                                            getRadiogenicIsotopeDateByName(SAM.getDateName()).getOneSigmaAbs()
                                            .movePointLeft(6).doubleValue();

                    if (invertedOneSigma > maxWeight) {
                        maxWeight = invertedOneSigma;
                    }

                    Path2D bar = new Path2D.Double(Path2D.WIND_NON_ZERO);
                    bar.moveTo(
                            (float) mapX(saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)),
                                    getMinX_Display(), rangeX, graphWidth),
                            (float) mapY(date + twoSigma, getMaxY_Display(), rangeY, graphHeight));
                    bar.lineTo(
                            (float) mapX(
                                    saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)) + barWidth,
                                    getMinX_Display(), rangeX, graphWidth),
                            (float) mapY(date + twoSigma, getMaxY_Display(), rangeY, graphHeight));
                    bar.lineTo(
                            (float) mapX(
                                    saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)) + barWidth,
                                    getMinX_Display(), rangeX, graphWidth),
                            (float) mapY(date - twoSigma, getMaxY_Display(), rangeY, graphHeight));
                    bar.lineTo(
                            (float) mapX(saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)),
                                    getMinX_Display(), rangeX, graphWidth),
                            (float) mapY(date - twoSigma, getMaxY_Display(), rangeY, graphHeight));
                    bar.closePath();

                    Composite originalComposite = g2d.getComposite();

                    if (SAM.getIncludedFractionIDsVector().contains(fID)) {
                        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
                        totalWeight += Math.pow(invertedOneSigma, 2.0);

                        // april 2014 experiment
                        if (f.getRgbColor() != 0) {
                            includedFillColor = new Color(f.getRgbColor());
                        }

                    } else {
                        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f));
                    }

                    g2d.setPaint(includedFillColor);

                    g2d.draw(bar);
                    //restore composite
                    g2d.setComposite(originalComposite);

                    g2d.setColor(Color.black);

                    // label fraction at top
                    g2d.rotate(-Math.PI / 4.0,
                            (float) mapX(saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)),
                                    getMinX_Display(), rangeX, graphWidth),
                            (float) mapY(date + twoSigma, getMaxY_Display(), rangeY, graphHeight));

                    g2d.drawString(
                            ((UPbReduxAliquot) selectedSampleDateModels[i][0]).getAliquotFractionByName(fID)
                                    .getFractionID(),
                            (float) mapX(saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)),
                                    getMinX_Display(), rangeX, graphWidth) + 15,
                            (float) mapY(date + twoSigma, getMaxY_Display(), rangeY, graphHeight));

                    g2d.rotate(Math.PI / 4.0,
                            (float) mapX(saveStartSamX + ((barGap / 2.0) + barNum * (barWidth + barGap)),
                                    getMinX_Display(), rangeX, graphWidth),
                            (float) mapY(date + twoSigma, getMaxY_Display(), rangeY, graphHeight));

                    barNum++;
                    // startSamX += 2 * barWidth;
                    startSamX += barWidth + barGap;
                }

                // display three info boxes below weighted means
                // each tic is the height of one calculated y-axis tic
                // determine the y axis tic
                double minYtic = Math.ceil(getMinY_Display() * 100) / 100;
                double maxYtic = Math.floor(getMaxY_Display() * 100) / 100;
                double deltay = Math.rint((maxYtic - minYtic) * 10 + 0.5);
                double yTic = deltay / 100;

                double yTopSummary = minPoint - yTic / 2.0;// wMeanOneSigma;
                //double specialYTic = yTic;
                double yTopWeights = yTopSummary - yTic * 1.1;
                double yTopMSWD_PDF = yTopWeights - yTic * 1.1;

                // summary box
                Path2D box = new Path2D.Double(Path2D.WIND_NON_ZERO);
                box.moveTo((float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(yTopSummary, getMaxY_Display(), rangeY, graphHeight));
                box.lineTo((float) mapX(saveStartSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(yTopSummary, getMaxY_Display(), rangeY, graphHeight));
                box.lineTo((float) mapX(saveStartSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(yTopSummary - yTic, getMaxY_Display(), rangeY, graphHeight));
                box.lineTo((float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(yTopSummary - yTic, getMaxY_Display(), rangeY, graphHeight));
                box.closePath();

                g2d.setStroke(new BasicStroke(1.5f));
                g2d.draw(box);

                // Info Box
                g2d.drawString(//
                        SAM.getAliquot().getAliquotName(),
                        (float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth) + 4f,
                        (float) mapY(yTopSummary, getMaxY_Display(), rangeY, graphHeight) + 13f);
                g2d.drawString(//
                        SAM.getName(), (float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth) + 4f,
                        (float) mapY(yTopSummary, getMaxY_Display(), rangeY, graphHeight) + 25f);
                g2d.drawString(//
                        SAM.FormatValueAndTwoSigmaABSThreeWaysForPublication(6, 2),
                        (float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth) + 4f,
                        (float) mapY(yTopSummary, getMaxY_Display(), rangeY, graphHeight) + 36f);
                g2d.drawString(//
                        SAM.ShowCustomMSWDwithN(),
                        (float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth) + 4f,
                        (float) mapY(yTopSummary, getMaxY_Display(), rangeY, graphHeight) + 48f);

                // weights box
                box.reset();
                box.moveTo((float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(yTopWeights, getMaxY_Display(), rangeY, graphHeight));
                box.lineTo((float) mapX(saveStartSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(yTopWeights, getMaxY_Display(), rangeY, graphHeight));
                box.lineTo((float) mapX(saveStartSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(yTopWeights - yTic, getMaxY_Display(), rangeY, graphHeight));
                box.lineTo((float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(yTopWeights - yTic, getMaxY_Display(), rangeY, graphHeight));
                box.closePath();

                g2d.setStroke(new BasicStroke(1.5f));
                g2d.draw(box);

                // plot fraction weights
                double artificialXRange = allFIDs.size();
                double count = 0;
                //double weightWidth = Math.min(3.0 * barWidth, (yTic / rangeY * graphHeight)) - 15;//yTic;//barWidth * 2.0;
                double weightWidth = (barWidth + barGap) * 0.9;

                for (String fID : allFIDs) {
                    // the dateModel has an associated aliquot, but in sample mode, it is a
                    // standin aliquot for the sample.  to get the aliquot number for
                    // use in coloring fractions, we need to query the fraction itself
                    String aliquotName = sample.getAliquotNameByFractionID(fID);

                    Fraction f = ((UPbReduxAliquot) selectedSampleDateModels[i][0])
                            .getAliquotFractionByName(fID);

                    Color includedFillColor = new Color(0, 0, 0);
                    if (sample.getSampleDateInterpretationGUISettings().getAliquotOptions().get(aliquotName)
                            .containsKey("includedFillColor")) {
                        String[] temp = //
                                sample.getSampleDateInterpretationGUISettings().getAliquotOptions()
                                        .get(aliquotName).get("includedFillColor").split(",");
                        includedFillColor = buildRGBColor(temp);
                    }

                    double invertOneSigma = //
                            1.0 //
                                    / ((UPbReduxAliquot) selectedSampleDateModels[i][0])
                                            .getAliquotFractionByName(fID)//
                                            .getRadiogenicIsotopeDateByName(SAM.getDateName()).getOneSigmaAbs()
                                            .movePointLeft(6).doubleValue();

                    Path2D weight = new Path2D.Double(Path2D.WIND_NON_ZERO);
                    weight.moveTo(
                            (float) mapX(saveStartSamX + (count + 0.5) / artificialXRange * actualWidthX,
                                    getMinX_Display(), rangeX, graphWidth) //
                                    - (float) (invertOneSigma / maxWeight / 2.0 * weightWidth),
                            (float) mapY(yTopWeights - (yTic / 2.0), getMaxY_Display(), rangeY, graphHeight) //
                                    + (float) (invertOneSigma / maxWeight / 2.0 * weightWidth) - 5f);

                    weight.lineTo(
                            (float) mapX(saveStartSamX + (count + 0.5) / artificialXRange * actualWidthX,
                                    getMinX_Display(), rangeX, graphWidth) //
                                    + (float) (invertOneSigma / maxWeight / 2.0 * weightWidth),
                            (float) mapY(yTopWeights - (yTic / 2.0), getMaxY_Display(), rangeY, graphHeight) //
                                    + (float) (invertOneSigma / maxWeight / 2.0 * weightWidth) - 5f);

                    weight.lineTo(
                            (float) mapX(saveStartSamX + (count + 0.5) / artificialXRange * actualWidthX,
                                    getMinX_Display(), rangeX, graphWidth) //
                                    + (float) (invertOneSigma / maxWeight / 2.0 * weightWidth),
                            (float) mapY(yTopWeights - (yTic / 2.0), getMaxY_Display(), rangeY, graphHeight) //
                                    - (float) (invertOneSigma / maxWeight / 2.0 * weightWidth) - 5f);

                    weight.lineTo(
                            (float) mapX(saveStartSamX + (count + 0.5) / artificialXRange * actualWidthX,
                                    getMinX_Display(), rangeX, graphWidth) //
                                    - (float) (invertOneSigma / maxWeight / 2.0 * weightWidth),
                            (float) mapY(yTopWeights - (yTic / 2.0), getMaxY_Display(), rangeY, graphHeight) //
                                    - (float) (invertOneSigma / maxWeight / 2.0 * weightWidth) - 5f);

                    weight.closePath();

                    g2d.setStroke(new BasicStroke(2.5f));

                    // test for included or not == black or gray
                    String weightPerCent = "   0";//0.0%";

                    //                        g2d.setPaint(includedFillColor);
                    Composite originalComposite = g2d.getComposite();

                    if (SAM.getIncludedFractionIDsVector().contains(fID)) {
                        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
                        weightPerCent = formatter1DecPlace
                                .format(Math.pow(invertOneSigma, 2.0) / totalWeight * 100.0);// + "%";

                        // april 2014 experiment
                        if (f.getRgbColor() != 0) {
                            includedFillColor = new Color(f.getRgbColor());
                        }
                    } else {
                        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f));
                    }

                    g2d.setPaint(includedFillColor);

                    g2d.fill(weight);
                    //restore composite
                    g2d.setComposite(originalComposite);

                    // write percent of total weight
                    g2d.drawString(weightPerCent,
                            (float) mapX(saveStartSamX + (count + 0.5) / artificialXRange * actualWidthX,
                                    getMinX_Display(), rangeX, graphWidth) //
                                    - (float) (invertOneSigma / maxWeight / 2.0 * weightWidth),
                            (float) mapY(yTopWeights - yTic, getMaxY_Display(), rangeY, graphHeight) - 5f);
                    g2d.setColor(Color.black);

                    count += 1.0;

                }

                // double box height for graph
                yTic *= 2.0;

                // plot MSWD_PDF
                // store  function x,y values
                Vector<Double> xVals = new Vector<Double>();
                Vector<Double> yVals = new Vector<Double>();

                double f = SAM.getIncludedFractionIDsVector().size() - 1;
                if (f > 1.0) {
                    g2d.setStroke(new BasicStroke(1.0f));

                    double yRange = MSWDCoordinates.valuesByPointCount[(int) f][5] * 1.03; // alitle air at the top of curve
                    double xStart = MSWDCoordinates.valuesByPointCount[(int) f][1];
                    double xRange = MSWDCoordinates.valuesByPointCount[(int) f][4] - xStart;
                    double xStep = 0.005;

                    Path2D MSWD_PDF = new Path2D.Double(Path2D.WIND_NON_ZERO);
                    Path2D MSWD_right = new Path2D.Double(Path2D.WIND_NON_ZERO);

                    // start at lower left corner of box  (may or may not be 0,0 )
                    MSWD_PDF.moveTo(//
                            (float) mapX((double) saveStartSamX, getMinX_Display(), rangeX, graphWidth),
                            (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight));

                    // setup MSWD to paint last
                    Path2D MSWD = null;

                    // calculate function values
                    for (double x = xStart; x < xRange; x += xStep) {
                        xVals.add((((x - xStart) / xRange) * actualWidthX) + (double) saveStartSamX);

                        double y = //
                                Math.pow(2, -1.0 * f / 2.0)//
                                        * Math.exp(-1.0 * f * x / 2.0)//
                                        * Math.pow(f, f / 2.0)//
                                        * Math.pow(x, (-1.0 + f / 2.0))//
                                        / Math.exp(Gamma.logGamma(f / 2.0));

                        yVals.add(((y / yRange) * yTic) + yTopMSWD_PDF - yTic);

                        MSWD_PDF.lineTo(//
                                (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth),
                                (float) mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight));

                        // test for location of left RED zone
                        if ((MSWDCoordinates.valuesByPointCount[(int) f][2] >= x)
                                && (MSWDCoordinates.valuesByPointCount[(int) f][2] < (x + xStep))) {

                            double leftX = MSWDCoordinates.valuesByPointCount[(int) f][2];
                            xVals.add((((leftX - xStart) / xRange) * actualWidthX) + (double) saveStartSamX);

                            double leftY = //
                                    Math.pow(2, -1.0 * f / 2.0)//
                                            * Math.exp(-1.0 * f * leftX / 2.0)//
                                            * Math.pow(f, f / 2.0)//
                                            * Math.pow(leftX, (-1.0 + f / 2.0))//
                                            / Math.exp(Gamma.logGamma(f / 2.0));
                            yVals.add(((leftY / yRange) * yTic) + yTopMSWD_PDF - yTic);

                            MSWD_PDF.lineTo(//
                                    (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth),
                                    (float) mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight));

                            Path2D ciLower = new Path2D.Double(Path2D.WIND_NON_ZERO);
                            ciLower.append(MSWD_PDF.getPathIterator(new AffineTransform()), true);

                            ciLower.lineTo(//
                                    (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth),
                                    (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight));
                            ciLower.closePath();
                            g2d.setColor(Color.RED);
                            g2d.fill(ciLower);

                            // draw right hand border line to compensate for a bug in the filler
                            Line2D right = new Line2D.Double(//
                                    mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth),
                                    mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight),
                                    mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth),
                                    mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight));
                            g2d.setStroke(new BasicStroke(0.5f));
                            g2d.draw(right);
                            g2d.setStroke(new BasicStroke(1.0f));

                            g2d.setColor(Color.BLACK);

                            System.out.println("Left Red = (" + leftX + ", " + leftY + ")");
                        }

                        // test for location of right RED zone
                        if ((MSWDCoordinates.valuesByPointCount[(int) f][3] >= x)
                                && (MSWDCoordinates.valuesByPointCount[(int) f][3] < (x + xStep))) {

                            double rightX = MSWDCoordinates.valuesByPointCount[(int) f][3];
                            xVals.add((((rightX - xStart) / xRange) * actualWidthX) + (double) saveStartSamX);

                            double rightY = //
                                    Math.pow(2, -1.0 * f / 2.0)//
                                            * Math.exp(-1.0 * f * rightX / 2.0)//
                                            * Math.pow(f, f / 2.0)//
                                            * Math.pow(rightX, (-1.0 + f / 2.0))//
                                            / Math.exp(Gamma.logGamma(f / 2.0));
                            yVals.add(((rightY / yRange) * yTic) + yTopMSWD_PDF - yTic);

                            MSWD_PDF.lineTo(//
                                    (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth),
                                    (float) mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight));

                            // here the strategy is to draw the curve and then reset it to record the remainder
                            g2d.setStroke(new BasicStroke(1.0f));
                            g2d.draw(MSWD_PDF);
                            MSWD_PDF = new Path2D.Double(Path2D.WIND_NON_ZERO);
                            MSWD_PDF.moveTo(//
                                    (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth),
                                    (float) mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight));

                            MSWD_right.moveTo(//
                                    (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth),
                                    (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight));
                            MSWD_right.lineTo(//
                                    (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth),
                                    (float) mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight));

                            System.out.println("Right Red = (" + rightX + ", " + rightY + ")");

                        }

                        // test for location of MSWD AND paint last
                        if ((SAM.getMeanSquaredWeightedDeviation().doubleValue() >= x)
                                && (SAM.getMeanSquaredWeightedDeviation().doubleValue() < (x + xStep))) {
                            MSWD = new Path2D.Double(Path2D.WIND_NON_ZERO);
                            MSWD.moveTo(//
                                    (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth),
                                    (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight));
                            MSWD.lineTo(//
                                    (float) mapX(xVals.lastElement(), getMinX_Display(), rangeX, graphWidth),
                                    (float) mapY(yVals.lastElement(), getMaxY_Display(), rangeY, graphHeight));

                        }
                    }
                    g2d.setStroke(new BasicStroke(1.0f));
                    // merge with border of right RED and fill
                    MSWD_right.append(MSWD_PDF.getPathIterator(new AffineTransform()), true);
                    g2d.setColor(Color.RED);
                    g2d.fill(MSWD_right);
                    g2d.setColor(Color.BLACK);
                    // draw the remaining curves
                    g2d.draw(MSWD_PDF);
                    // MSWD may be off the graph and hence not exist
                    try {
                        g2d.draw(MSWD);
                    } catch (Exception e) {
                    }

                    // label 95% conf interval and MSWD
                    g2d.drawString(//
                            "95% CI: ("
                                    + formatter2DecPlaces.format(MSWDCoordinates.valuesByPointCount[(int) f][2])
                                    + ", "
                                    + formatter2DecPlaces.format(MSWDCoordinates.valuesByPointCount[(int) f][3])
                                    + ")",
                            (float) mapX(saveStartSamX + (actualWidthX / 2.0), getMinX_Display(), rangeX,
                                    graphWidth) - 30f,
                            (float) mapY(yTopMSWD_PDF, getMaxY_Display(), rangeY, graphHeight) + 15f);

                    // determine if MSWD is out of range
                    String mswdAlert = "";
                    if (SAM.getMeanSquaredWeightedDeviation()
                            .doubleValue() > MSWDCoordinates.valuesByPointCount[(int) f][4]) {
                        mswdAlert = "\n !Out of Range!";
                    }
                    g2d.drawString(//
                            "MSWD = "
                                    + formatter2DecPlaces
                                            .format(SAM.getMeanSquaredWeightedDeviation().doubleValue())
                                    + ", n = " + (int) (f + 1) + mswdAlert,
                            (float) mapX(saveStartSamX + (actualWidthX / 2.0), getMinX_Display(), rangeX,
                                    graphWidth) - 15f,
                            (float) mapY(yTopMSWD_PDF, getMaxY_Display(), rangeY, graphHeight) + 30f);

                } else {
                    g2d.drawString("need more data...",
                            (float) mapX((double) saveStartSamX, getMinX_Display(), rangeX, graphWidth) + 4f,
                            (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight) - 10f);
                }

                // MSWD_PDF box
                box.reset();
                box.moveTo((float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(yTopMSWD_PDF, getMaxY_Display(), rangeY, graphHeight));
                box.lineTo((float) mapX(saveStartSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(yTopMSWD_PDF, getMaxY_Display(), rangeY, graphHeight));
                box.lineTo((float) mapX(saveStartSamX + actualWidthX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight));
                box.lineTo((float) mapX(saveStartSamX, getMinX_Display(), rangeX, graphWidth),
                        (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight));
                box.closePath();

                g2d.setStroke(new BasicStroke(1.5f));
                g2d.draw(box);

                // MSWD_PDF x-axis tics
                if (f > 1.0) {
                    g2d.setStroke(new BasicStroke(1.0f));
                    double xStart = (MSWDCoordinates.valuesByPointCount[(int) f][1] <= 0.5) ? 0.5 : 1.0;
                    double xRange = MSWDCoordinates.valuesByPointCount[(int) f][4]
                            - MSWDCoordinates.valuesByPointCount[(int) f][1];
                    double xStep = 0.5;

                    for (double x = xStart; x < xRange; x += xStep) {
                        double xPlot = (((x - MSWDCoordinates.valuesByPointCount[(int) f][1]) / xRange)
                                * actualWidthX) + (double) saveStartSamX;
                        Line2D line = new Line2D.Double(mapX(xPlot, getMinX_Display(), rangeX, graphWidth),
                                mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight),
                                mapX(xPlot, getMinX_Display(), rangeX, graphWidth),
                                mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight) + 7);
                        g2d.draw(line);

                        g2d.rotate(-Math.PI / 2.0, (float) mapX(xPlot, getMinX_Display(), rangeX, graphWidth),
                                (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight));
                        g2d.drawString(formatter1DecPlace.format(x),
                                (float) mapX(xPlot, getMinX_Display(), rangeX, graphWidth) - 30f,
                                (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight) + 5f);
                        g2d.rotate(Math.PI / 2.0, (float) mapX(xPlot, getMinX_Display(), rangeX, graphWidth),
                                (float) mapY(yTopMSWD_PDF - yTic, getMaxY_Display(), rangeY, graphHeight));
                    }
                }

                // set counters
                barNum += samSpace;
                startSamX += 2 * samSpace * barWidth;
            }
        }
    }
    //        // prevents re-randomization
    //        setInRandomMode( true );

    drawAxesAndTicks(g2d, rangeX, rangeY);

    // draw zoom box if in use
    if ((Math.abs(zoomMaxX - zoomMinX) * Math.abs(zoomMinY - zoomMaxY)) > 0.0) {
        g2d.setStroke(new BasicStroke(2.0f));
        g2d.setColor(Color.red);
        g2d.drawRect(//
                Math.min(zoomMinX, zoomMaxX), Math.min(zoomMaxY, zoomMinY), Math.abs(zoomMaxX - zoomMinX),
                Math.abs(zoomMinY - zoomMaxY));
    }
}

From source file:cc.redberry.core.number.Numeric.java

/**
 * @see Double#compare(double, double)//  w  w w  .j  a  v  a 2 s.  c  o  m
 */
@Override
public int compareTo(Real o) {
    checkNotNull(o);
    return Double.compare(value, o.doubleValue());
}

From source file:ml.shifu.shifu.core.dtrain.nn.NNParquetWorker.java

@Override
public void load(GuaguaWritableAdapter<LongWritable> currentKey, GuaguaWritableAdapter<Tuple> currentValue,
        WorkerContext<NNParams, NNParams> workerContext) {
    // init field list for later read
    this.initFieldList();

    LOG.info("subFeatureSet size: {} ; subFeatureSet: {}", subFeatureSet.size(), subFeatureSet);

    super.count += 1;
    if ((super.count) % 5000 == 0) {
        LOG.info("Read {} records.", super.count);
    }//from  w w w  .j  av  a  2s. c o  m

    float[] inputs = new float[super.featureInputsCnt];
    float[] ideal = new float[super.outputNodeCount];

    if (super.isDry) {
        // dry train, use empty data.
        addDataPairToDataSet(0,
                new BasicFloatMLDataPair(new BasicFloatMLData(inputs), new BasicFloatMLData(ideal)));
        return;
    }

    long hashcode = 0;
    float significance = 1f;
    // use guava Splitter to iterate only once
    // use NNConstants.NN_DEFAULT_COLUMN_SEPARATOR to replace getModelConfig().getDataSetDelimiter(), super follows
    // the function in akka mode.
    int index = 0, inputsIndex = 0, outputIndex = 0;

    Tuple tuple = currentValue.getWritable();

    // back from foreach to for loop because of in earlier version, tuple cannot be iterable.
    for (int i = 0; i < tuple.size(); i++) {
        Object element = null;
        try {
            element = tuple.get(i);
        } catch (ExecException e) {
            throw new GuaguaRuntimeException(e);
        }
        float floatValue = 0f;
        if (element != null) {
            if (element instanceof Float) {
                floatValue = (Float) element;
            } else {
                // check here to avoid bad performance in failed NumberFormatUtils.getFloat(input, 0f)
                floatValue = element.toString().length() == 0 ? 0f
                        : NumberFormatUtils.getFloat(element.toString(), 0f);
            }
        }
        // no idea about why NaN in input data, we should process it as missing value TODO , according to norm type
        floatValue = (Float.isNaN(floatValue) || Double.isNaN(floatValue)) ? 0f : floatValue;

        if (index == (super.inputNodeCount + super.outputNodeCount)) {
            // do we need to check if not weighted directly set to 1f; if such logic non-weight at first, then
            // weight, how to process???
            if (StringUtils.isBlank(modelConfig.getWeightColumnName())) {
                significance = 1f;
                // break here if we reach weight column which is last column
                break;
            }

            assert element != null;
            if (element != null && element instanceof Float) {
                significance = (Float) element;
            } else {
                // check here to avoid bad performance in failed NumberFormatUtils.getFloat(input, 0f)
                significance = element.toString().length() == 0 ? 1f
                        : NumberFormatUtils.getFloat(element.toString(), 1f);
            }
            // if invalid weight, set it to 1f and warning in log
            if (Float.compare(significance, 0f) < 0) {
                LOG.warn(
                        "The {} record in current worker weight {} is less than 0f, it is invalid, set it to 1.",
                        count, significance);
                significance = 1f;
            }
            // break here if we reach weight column which is last column
            break;
        } else {
            int columnIndex = requiredFieldList.getFields().get(index).getIndex();
            if (columnIndex >= super.columnConfigList.size()) {
                assert element != null;
                if (element != null && element instanceof Float) {
                    significance = (Float) element;
                } else {
                    // check here to avoid bad performance in failed NumberFormatUtils.getFloat(input, 0f)
                    significance = element.toString().length() == 0 ? 1f
                            : NumberFormatUtils.getFloat(element.toString(), 1f);
                }
                break;
            } else {
                ColumnConfig columnConfig = super.columnConfigList.get(columnIndex);
                if (columnConfig != null && columnConfig.isTarget()) {
                    if (modelConfig.isRegression()) {
                        ideal[outputIndex++] = floatValue;
                    } else {
                        if (modelConfig.getTrain().isOneVsAll()) {
                            // if one vs all, set correlated idea value according to trainerId which means in
                            // trainer with id 0, target 0 is treated with 1, other are 0. Such target value are set
                            // to index of tags like [0, 1, 2, 3] compared with ["a", "b", "c", "d"]
                            ideal[outputIndex++] = Float.compare(floatValue, trainerId) == 0 ? 1f : 0f;
                        } else {
                            if (modelConfig.getTags().size() == 2) {
                                // if only 2 classes, output node is 1 node. if target = 0 means 0 is the index for
                                // positive prediction, set positive to 1 and negative to 0
                                int ideaIndex = (int) floatValue;
                                ideal[0] = ideaIndex == 0 ? 1f : 0f;
                            } else {
                                // for multiple classification
                                int ideaIndex = (int) floatValue;
                                ideal[ideaIndex] = 1f;
                            }
                        }
                    }
                } else {
                    if (subFeatureSet.contains(columnIndex)) {
                        inputs[inputsIndex++] = floatValue;
                        hashcode = hashcode * 31 + Double.valueOf(floatValue).hashCode();
                    }
                }
            }
        }
        index += 1;
    }

    // output delimiter in norm can be set by user now and if user set a special one later changed, this exception
    // is helped to quick find such issue.
    if (inputsIndex != inputs.length) {
        String delimiter = workerContext.getProps().getProperty(Constants.SHIFU_OUTPUT_DATA_DELIMITER,
                Constants.DEFAULT_DELIMITER);
        throw new RuntimeException("Input length is inconsistent with parsing size. Input original size: "
                + inputs.length + ", parsing size:" + inputsIndex + ", delimiter:" + delimiter + ".");
    }

    // sample negative only logic here
    if (modelConfig.getTrain().getSampleNegOnly()) {
        if (this.modelConfig.isFixInitialInput()) {
            // if fixInitialInput, sample hashcode in 1-sampleRate range out if negative records
            int startHashCode = (100 / this.modelConfig.getBaggingNum()) * this.trainerId;
            // here BaggingSampleRate means how many data will be used in training and validation, if it is 0.8, we
            // should take 1-0.8 to check endHashCode
            int endHashCode = startHashCode
                    + Double.valueOf((1d - this.modelConfig.getBaggingSampleRate()) * 100).intValue();
            if ((modelConfig.isRegression()
                    || (modelConfig.isClassification() && modelConfig.getTrain().isOneVsAll())) // regression or
                    // onevsall
                    && (int) (ideal[0] + 0.01d) == 0 // negative record
                    && isInRange(hashcode, startHashCode, endHashCode)) {
                return;
            }
        } else {
            // if not fixed initial input, and for regression or onevsall multiple classification (regression also).
            // if negative record
            if ((modelConfig.isRegression()
                    || (modelConfig.isClassification() && modelConfig.getTrain().isOneVsAll())) // regression or
                    // onevsall
                    && (int) (ideal[0] + 0.01d) == 0 // negative record
                    && Double.compare(super.sampelNegOnlyRandom.nextDouble(),
                            this.modelConfig.getBaggingSampleRate()) >= 0) {
                return;
            }
        }
    }

    FloatMLDataPair pair = new BasicFloatMLDataPair(new BasicFloatMLData(inputs), new BasicFloatMLData(ideal));

    // up sampling logic
    if (modelConfig.isRegression() && isUpSampleEnabled() && Double.compare(ideal[0], 1d) == 0) {
        // Double.compare(ideal[0], 1d) == 0 means positive tags; sample + 1 to avoid sample count to 0
        pair.setSignificance(significance * (super.upSampleRng.sample() + 1));
    } else {
        pair.setSignificance(significance);
    }

    boolean isValidation = false;
    if (workerContext.getAttachment() != null && workerContext.getAttachment() instanceof Boolean) {
        isValidation = (Boolean) workerContext.getAttachment();
    }

    boolean isInTraining = addDataPairToDataSet(hashcode, pair, isValidation);

    // do bagging sampling only for training data
    if (isInTraining) {
        float subsampleWeights = sampleWeights(pair.getIdealArray()[0]);
        if (isPositive(pair.getIdealArray()[0])) {
            this.positiveSelectedTrainCount += subsampleWeights * 1L;
        } else {
            this.negativeSelectedTrainCount += subsampleWeights * 1L;
        }
        // set weights to significance, if 0, significance will be 0, that is bagging sampling
        pair.setSignificance(pair.getSignificance() * subsampleWeights);
    } else {
        // for validation data, according bagging sampling logic, we may need to sampling validation data set, while
        // validation data set are only used to compute validation error, not to do real sampling is ok.
    }
}