Example usage for java.lang Double isInfinite

List of usage examples for java.lang Double isInfinite

Introduction

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

Prototype

public boolean isInfinite() 

Source Link

Document

Returns true if this Double value is infinitely large in magnitude, false otherwise.

Usage

From source file:org.sonar.api.database.model.MeasureModel.java

/**
 * Creates a measure based on a metric and a double value
 *///from w w  w  .ja  v a 2 s  . c o  m
public MeasureModel(int metricId, Double val) {
    if (val.isNaN() || val.isInfinite()) {
        throw new IllegalArgumentException("Measure value is NaN. Metric=" + metricId);
    }
    this.metricId = metricId;
    this.value = val;
}

From source file:org.sonar.api.database.model.MeasureModel.java

/**
 * Sets the measure value//from   ww w. j  a v a2  s  .  com
 *
 * @throws IllegalArgumentException in case value is not a valid double
 */
public MeasureModel setValue(Double value) {
    if (value != null && (value.isNaN() || value.isInfinite())) {
        throw new IllegalArgumentException();
    }
    this.value = value;
    return this;
}

From source file:org.azrul.langmera.QLearningAnalytics.java

@Override
public void learn(DecisionFeedback currentFeedback, Vertx vertx, Runnable responseAction) {

    LocalMap<String, DetailDecisionFeedback> decisionFeedbackMap = vertx.sharedData()
            .getLocalMap("DECISION_FEEDBACK");
    LocalMap<String, DecisionRequest> decisionRequestMap = vertx.sharedData().getLocalMap("DECISION_REQUEST");
    LocalMap<String, DecisionResponse> decisionResponseMap = vertx.sharedData()
            .getLocalMap("DECISION_RESPONSE");
    LocalMap<String, Double> q = vertx.sharedData().getLocalMap("Q");
    LocalMap<Long, String> trackers = vertx.sharedData().getLocalMap("FEEDBACK_TRACKER");

    int feedbackCount = decisionFeedbackMap.size();
    boolean skipLearning = false;
    if (decisionRequestMap.get(currentFeedback.getDecisionId()) == null) {
        skipLearning = true;/*from ww w  .  j  a  v  a2s .com*/
    }
    if (decisionResponseMap.get(currentFeedback.getDecisionId()) == null) {
        skipLearning = true;
    }
    if (skipLearning == false) {
        String context = decisionRequestMap.get(currentFeedback.getDecisionId()).getContext();
        String decision = decisionResponseMap.get(currentFeedback.getDecisionId()).getDecision();

        DetailDecisionFeedback detailFB = new DetailDecisionFeedback();
        detailFB.setFeedback(currentFeedback);
        detailFB.setContext(context);
        detailFB.setDecision(decision);
        decisionFeedbackMap.put(currentFeedback.getDecisionId(), detailFB);

        Long trackerKey = (new Date()).getTime();
        trackers.put(trackerKey, currentFeedback.getDecisionId());

        int feedbackCountByDecision = 0;
        List<Double> rewards = new ArrayList<>();
        for (DetailDecisionFeedback fb : decisionFeedbackMap.values()) {
            if (context.equals(decisionFeedbackMap.get(fb.getFeedback().getDecisionId()).getContext())
                    && decision
                            .equals(decisionFeedbackMap.get(fb.getFeedback().getDecisionId()).getDecision())) {
                feedbackCountByDecision++;
                rewards.add(fb.getFeedback().getScore());
            }
        }

        Double w = 0.0;
        Double alpha = config.getProperty("alpha", Double.class);

        //if no step parameter is configured, calculate it
        if (alpha == null) {
            alpha = 1.0 / (feedbackCountByDecision);
        }

        //non-stationary q-learning
        int i = 0;
        for (Double ri : rewards) {
            i++;
            w = w + alpha * (Math.pow(1 - alpha, feedbackCountByDecision - i)) * ri;
        }
        Double newQ = w;

        //System.out.println(feedbackCount+" Q:["+context + ":" + decision+"]"+newQ);
        //save what we learn
        if (newQ.isInfinite() || newQ.isNaN()) {
            //skip
        } else {
            String key = context + ":" + decision;
            q.put(key, newQ);
        }

        //Limit the number of history taken into account - prevents memory leak
        if (feedbackCount > config.getProperty("maxHistoryRetained", Integer.class)) {
            Long tk = Collections.min(trackers.keySet());
            String decisionIDWithMinTracker = trackers.get(tk);
            decisionFeedbackMap.remove(decisionIDWithMinTracker);
            trackers.remove(tk);
        }

        //clear cached req/resp once the feedback has come back
        decisionRequestMap.remove(currentFeedback.getDecisionId());
        decisionResponseMap.remove(currentFeedback.getDecisionId());

        //Get maxQ
        Double maxQ = Double.NEGATIVE_INFINITY;
        String decisionWithMaxQ = null;
        for (String contextDecision : q.keySet()) {
            if (q.get(contextDecision) > maxQ) {
                decisionWithMaxQ = contextDecision;
                maxQ = q.get(contextDecision);
            }
        }

        //keep traces
        if (Boolean.TRUE.equals(config.getProperty("collect.traces", Boolean.class))) {
            Date now = new Date();
            for (String contextDecision : q.keySet()) {
                List<Double> qtrace = traces.get(contextDecision);
                if (qtrace == null) {
                    qtrace = new ArrayList<Double>();
                    qtrace.add(q.get(contextDecision));
                    traces.put(contextDecision, qtrace);
                } else {
                    qtrace.add(q.get(contextDecision));
                }
                String[] c = contextDecision.split(":");
                Trace trace = new Trace(currentFeedback.getDecisionId(), c[0], q.get(contextDecision), maxQ,
                        now, c[1], currentFeedback.getScore());
                vertx.eventBus().publish("SAVE_TRACE_TO_TRACE",
                        SerializationUtils.serialize((Serializable) trace));
            }
        }

        //            //put in in-memory DB
        //            
        //            
        //            String[] c = decisionWithMaxQ.split(":");
        //            if (InMemoryDB.store.get(0)==null){
        //                List<Object> imContext = new ArrayList<Object>();
        //                imContext.add(c[0]);
        //                InMemoryDB.store.add(0,imContext);
        //            }else{
        //                InMemoryDB.store.get(0).add(c[0]);
        //            }
        //            
        //            if (InMemoryDB.store.get(1)==null){
        //                List<Object> imDecision = new ArrayList<Object>();
        //                imDecision.add(c[1]);
        //                InMemoryDB.store.add(1,imDecision);
        //            }else{
        //                InMemoryDB.store.get(1).add(c[1]);
        //            }
        //            
        //            if (InMemoryDB.store.get(2)==null){
        //                List<Object> imMaxQ = new ArrayList<Object>();
        //                imMaxQ.add(maxQ);
        //                InMemoryDB.store.add(2,imMaxQ);
        //            }else{
        //                InMemoryDB.store.get(2).add(maxQ);
        //            }
        //            
        //            if (InMemoryDB.store.get(3)==null){
        //                List<Object> imTime= new ArrayList<Object>();
        //                imTime.add(new Date());
        //                InMemoryDB.store.add(3,imTime);
        //            }else{
        //                InMemoryDB.store.get(3).add(new Date());
        //            }

        responseAction.run();
        if (Boolean.TRUE.equals(currentFeedback.getTerminal())) {
            long delta = (new Date()).getTime() - startTime;
            System.out.println("Time taken to process " + feedbackCount + " msgs:" + delta + " ms");
            System.out.println("Time taken per msg: " + (delta / feedbackCount) + " ms");
            System.out
                    .println("Msgs per s: " + ((1000.0 * (double) feedbackCount) / ((double) delta)) + " msgs");
            if (Boolean.TRUE.equals(config.getProperty("collect.traces", Boolean.class))
                    && Boolean.TRUE.equals(config.getProperty("display.desktop.chart", Boolean.class))) {
                final LineChart demo = new LineChart(chartDesc, traces);
                demo.pack();
                demo.setVisible(true);
            }
        }
    } else {
        logger.log(Level.WARNING, "Attempt to learn from a feedback with no corresponding request/response");
        responseAction.run();
    }
    //
    //select qmovies,qsports,qconcerts from 
    //   (select t1.qvalue as qsports,t1.decisionid from trace t1 where t1.decision='SPORTS' order by t1.decisiontime) as A1 
    //   join (select t2.qvalue as qmovies,t2.decisionid from trace t2 where t2.decision='MOVIES' order by t2.decisiontime) as A2 on A1.decisionid = A2.decisionid
    //   join (select t3.qvalue as qconcerts,t3.decisionid from trace t3 where t3.decision='CONCERTS' order by t3.decisiontime) as A3 on A1.decisionid = A3.decisionid

}

From source file:org.jahia.services.content.nodetypes.JahiaCndWriter.java

/**
 * write prop def//ww  w  .  j  a  v  a 2 s.co m
 * @param pd
 */
private void writePropertyDefExtension(ExtendedNodeType ntd, ExtendedPropertyDefinition pd) throws IOException {
    out.write("\n" + INDENT + "- ");
    out.write(pd.getName());
    out.write(" (");
    out.write(PropertyType.nameFromValue(pd.getRequiredType()).toLowerCase());

    if (SelectorType.nameFromValue(pd.getSelector()) != null
            && (SelectorType.defaultSelectors.get(pd.getRequiredType()) == null
                    || pd.getSelector() != SelectorType.defaultSelectors.get(pd.getRequiredType())
                    || !pd.getSelectorOptions().isEmpty())) {
        out.write(", ");
        out.write(SelectorType.nameFromValue(pd.getSelector()).toLowerCase());
        Map<String, String> selectorOptions = pd.getSelectorOptions();
        if (!selectorOptions.isEmpty()) {
            out.write("[");
            Iterator<Map.Entry<String, String>> keys = selectorOptions.entrySet().iterator();
            while (keys.hasNext()) {
                Map.Entry<String, String> entry = keys.next();
                String key = entry.getKey();
                String value = entry.getValue();
                out.write(key);
                if (StringUtils.isNotBlank(value)) {
                    out.write("='" + value + "'");
                }
                if (keys.hasNext()) {
                    out.write(",");
                }
            }
            out.write("]");
        }
    }
    out.write(")");
    writeDefaultValues(pd.getDefaultValuesAsUnexpandedValue());
    out.write(ntd.getPrimaryItemName() != null && ntd.getPrimaryItemName().equals(pd.getName()) ? " primary"
            : "");
    if (pd.isMandatory()) {
        out.write(" mandatory");
    }
    if (pd.isAutoCreated()) {
        out.write(" autocreated");
    }
    if (pd.isProtected()) {
        out.write(" protected");
    }
    if (pd.isMultiple()) {
        out.write(" multiple");
    }
    if (pd.isHidden()) {
        out.write(" hidden");
    }
    if (pd.isInternationalized()) {
        out.write(" internationalized");
    }
    if (pd.getOnConflict() != OnConflictAction.USE_LATEST) {
        out.write(" onconflict=" + OnConflictAction.nameFromValue(pd.getOnConflict()));
    }

    if (pd.getIndex() != IndexType.TOKENIZED) {
        out.write(" indexed=" + IndexType.nameFromValue(pd.getIndex()));
    }

    final Double scoreboost = pd.getScoreboost();
    if (!scoreboost.isInfinite() && !scoreboost.isNaN() && !scoreboost.equals(1.0)) {
        out.write(" scoreboost=" + scoreboost);
    }
    if (pd.getAnalyzer() != null) {
        out.write(" analyzer=" + pd.getAnalyzer());
    }
    if (pd.isFacetable()) {
        out.write(" facetable");
    }
    if (pd.isHierarchical()) {
        out.write(" hierarchical");
    }
    if (!pd.isQueryOrderable()) {
        out.write(" noqueryorder");
    }
    if (!pd.isFullTextSearchable()) {
        out.write(" nofulltext");
    }
    if (pd.getLocalItemType() != null) {
        out.write(" itemtype = " + pd.getLocalItemType());
    }
    if (pd.getOnParentVersion() != OnParentVersionAction.VERSION) {
        out.write(" ");
        out.write(OnParentVersionAction.nameFromValue(pd.getOnParentVersion()).toLowerCase());
    }
    String[] availableQueryOperators = pd.getAvailableQueryOperators();
    if (availableQueryOperators != null && availableQueryOperators.length > 0) {
        writeQueryOperators(availableQueryOperators);
    }

    writeValueConstraints(pd.getValueConstraintsAsValue());
}

From source file:org.locationtech.udig.processingtoolbox.tools.ScatterPlotDialog.java

private XYDataset getScatterPlotData(SimpleFeatureCollection features, String xField, String yField) {
    XYSeries xySeries = new XYSeries(features.getSchema().getTypeName());
    minMaxVisitor.reset();/*w  w w  . ja  v  a  2  s  .  c o m*/

    Expression xExpression = ff.property(xField);
    Expression yExpression = ff.property(yField);

    SimpleFeatureIterator featureIter = features.features();
    try {
        while (featureIter.hasNext()) {
            SimpleFeature feature = featureIter.next();

            Double xVal = xExpression.evaluate(feature, Double.class);
            if (xVal == null || xVal.isNaN() || xVal.isInfinite()) {
                continue;
            }

            Double yVal = yExpression.evaluate(feature, Double.class);
            if (yVal == null || yVal.isNaN() || yVal.isInfinite()) {
                continue;
            }

            minMaxVisitor.visit(xVal, yVal);
            xySeries.add(new XYDataItem2(feature, xVal, yVal));
        }
    } finally {
        featureIter.close();
    }

    return new XYSeriesCollection(xySeries);
}

From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java

private double[] getValues(SimpleFeatureCollection features, String field) {
    minMaxVisitor.reset();/*from  ww  w  .j  a v a 2 s  .  c o  m*/

    double[] values = new double[features.size()];
    SimpleFeatureIterator featureIter = features.features();
    try {
        Expression expression = ff.property(field);
        int index = 0;
        while (featureIter.hasNext()) {
            SimpleFeature feature = featureIter.next();
            Double val = expression.evaluate(feature, Double.class);
            if (val == null || val.isNaN() || val.isInfinite()) {
                continue;
            }
            values[index++] = val;
            minMaxVisitor.visit(val, val);
        }
    } finally {
        featureIter.close();
    }

    return values;
}

From source file:org.egov.pgr.dashboard.service.DashboardService.java

private List<Map<String, Object>> performanceProjection(List<Object[]> wardwisePerformanceData) {
    DecimalFormat df = new DecimalFormat("####0.00");
    List<Map<String, Object>> compAggrData = new ArrayList<>();
    for (Object[] compData : wardwisePerformanceData) {
        Map<String, Object> complaintData = new HashMap<>();
        complaintData.put("name", compData[0]);
        BigInteger compData1 = (BigInteger) compData[1];
        BigInteger compData3 = (BigInteger) compData[3];
        BigInteger compData4 = (BigInteger) compData[4];
        double noOfCompAsOnDate = compData1.doubleValue();
        double noOfCompReceivedBtw = compData3.doubleValue();
        double noOfCompPenAsonDate = compData4.doubleValue();
        Double yValue = 100 * (noOfCompAsOnDate + noOfCompReceivedBtw - noOfCompPenAsonDate)
                / (noOfCompAsOnDate + noOfCompReceivedBtw);
        if (yValue.isNaN() || yValue.isInfinite())
            complaintData.put("y", BigDecimal.ZERO);
        else/*from   ww  w.  j  a  v  a 2 s.  co m*/
            complaintData.put("y", new BigDecimal(df.format(yValue)));
        compAggrData.add(complaintData);
    }

    // SORT ZONEWISE PERFORMANCE BY REDRESSAL %
    sortData(compAggrData, "y");
    Collections.reverse(compAggrData);
    return compAggrData;
}

From source file:org.sonar.server.issue.index.IssueIndex.java

private Optional<Long> getMinCreatedAt(Map<String, QueryBuilder> filters, QueryBuilder esQuery) {
    String facetNameAndField = IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT;
    SearchRequestBuilder esRequest = client.prepareSearch(INDEX_TYPE_ISSUE).setSize(0);
    BoolQueryBuilder esFilter = boolQuery();
    filters.values().stream().filter(Objects::nonNull).forEach(esFilter::must);
    if (esFilter.hasClauses()) {
        esRequest.setQuery(QueryBuilders.filteredQuery(esQuery, esFilter));
    } else {/*from ww  w. j  a  v  a 2 s . c  o  m*/
        esRequest.setQuery(esQuery);
    }
    esRequest.addAggregation(AggregationBuilders.min(facetNameAndField).field(facetNameAndField));
    Min minValue = esRequest.get().getAggregations().get(facetNameAndField);

    Double actualValue = minValue.getValue();
    if (actualValue.isInfinite()) {
        return Optional.empty();
    }
    return Optional.of(actualValue.longValue());
}

From source file:org.egov.pgr.dashboard.service.DashboardService.java

private List<Map<String, Object>> performanceAnalysis(List<Object[]> wardwisePerformanceData,
        DateTime currentDate) {//  ww w .j  ava  2s.  co  m
    List<Map<String, Object>> compAggrData = new ArrayList<>();
    String formattedFrm = endOfGivenDate(currentDate.minusDays(14)).toString(defaultDateFormatter());
    String formattedDayAfterFrm = startOfGivenDate(currentDate.minusDays(13)).toString(defaultDateFormatter());
    String formattedTo = currentDate.toString(defaultDateFormatter());
    DecimalFormat df = new DecimalFormat("####0.00");
    for (Object[] compData : wardwisePerformanceData) {
        Map<String, Object> complaintData = new HashMap<>();
        complaintData.put("zone", compData[0]);
        BigInteger compData1 = (BigInteger) compData[1];
        BigInteger compData3 = (BigInteger) compData[3];
        BigInteger compData4 = (BigInteger) compData[4];
        double noOfCompAsOnDate = compData1.doubleValue();
        double noOfCompReceivedBtw = compData3.doubleValue();
        double noOfCompPenAsonDate = compData4.doubleValue();
        complaintData.put("dateAsOn2WeekBack", formattedFrm);
        complaintData.put("noOfCompAsOnDate", noOfCompAsOnDate);
        complaintData.put("dateAsOnDayAfter", formattedDayAfterFrm);
        complaintData.put("noOfCompReceivedBtw", noOfCompReceivedBtw);
        complaintData.put("dateAsOn", formattedTo);
        complaintData.put("noOfCompPenAsonDate", noOfCompPenAsonDate);
        Double disposalPerc = 100 * (noOfCompAsOnDate + noOfCompReceivedBtw - noOfCompPenAsonDate)
                / (noOfCompAsOnDate + noOfCompReceivedBtw);
        if (disposalPerc.isNaN() || disposalPerc.isInfinite())
            complaintData.put(DISPOSALPERC, "0.00");
        else
            complaintData.put(DISPOSALPERC, df.format(disposalPerc));
        complaintData.put("lat", compData[6]);
        complaintData.put("lng", compData[7]);
        complaintData.put("zoneId", compData[8]);
        compAggrData.add(complaintData);
    }

    // SORT ZONEWISE PERFORMANCE BY REDRESSAL %
    sortData(compAggrData, DISPOSALPERC);
    Collections.reverse(compAggrData);
    // ASSIGN A RANK BASED ON ORDER
    assignRank(compAggrData, "rank");
    return compAggrData;
}

From source file:org.egov.pgr.service.dashboard.DashboardService.java

private List<Map<String, Object>> performanceProjection(final List<Object[]> wardwisePerformanceData,
        final DateTime currentDate) {
    final DecimalFormat df = new DecimalFormat("####0.00");
    final List<Map<String, Object>> compAggrData = new ArrayList<Map<String, Object>>();
    for (final Object[] compData : wardwisePerformanceData) {
        final Map<String, Object> complaintData = new HashMap<String, Object>();
        complaintData.put("name", compData[0]);
        final BigInteger compData1 = (BigInteger) compData[1];
        final BigInteger compData3 = (BigInteger) compData[3];
        final BigInteger compData4 = (BigInteger) compData[4];
        final double noOfCompAsOnDate = compData1.doubleValue();
        final double noOfCompReceivedBtw = compData3.doubleValue();
        final double noOfCompPenAsonDate = compData4.doubleValue();
        final Double yValue = 100 * (noOfCompAsOnDate + noOfCompReceivedBtw - noOfCompPenAsonDate)
                / (noOfCompAsOnDate + noOfCompReceivedBtw);
        if (yValue.isNaN() || yValue.isInfinite())
            complaintData.put("y", BigDecimal.ZERO);
        else/*from   w  w  w .java2  s  .c om*/
            complaintData.put("y", new BigDecimal(df.format(yValue)));
        compAggrData.add(complaintData);
    }

    // SORT ZONEWISE PERFORMANCE BY REDRESSAL %
    sortData(compAggrData, "y");
    Collections.reverse(compAggrData);
    return compAggrData;
}