List of usage examples for java.lang Double valueOf
@HotSpotIntrinsicCandidate public static Double valueOf(double d)
From source file:ml.shifu.shifu.udf.PSICalculatorUDF.java
@Override public Tuple exec(Tuple input) throws IOException { if (input == null || input.size() < 2) { return null; }//from w w w. j a v a 2 s . c o m Integer columnId = (Integer) input.get(0); DataBag databag = (DataBag) input.get(1); ColumnConfig columnConfig = this.columnConfigList.get(columnId); List<Integer> negativeBin = columnConfig.getBinCountNeg(); List<Integer> positiveBin = columnConfig.getBinCountPos(); List<Double> expected = new ArrayList<Double>(negativeBin.size()); for (int i = 0; i < columnConfig.getBinCountNeg().size(); i++) { if (columnConfig.getTotalCount() == 0) { expected.add(0D); } else { expected.add( ((double) negativeBin.get(i) + (double) positiveBin.get(i)) / columnConfig.getTotalCount()); } } Iterator<Tuple> iter = databag.iterator(); Double psi = 0D; List<String> unitStats = new ArrayList<String>(); while (iter.hasNext()) { Tuple tuple = iter.next(); if (tuple != null && tuple.size() != 0) { String subBinStr = (String) tuple.get(1); String[] subBinArr = StringUtils.split(subBinStr, CalculateStatsUDF.CATEGORY_VAL_SEPARATOR); List<Double> subCounter = new ArrayList<Double>(); Double total = 0D; for (String binningElement : subBinArr) { Double dVal = Double.valueOf(binningElement); subCounter.add(dVal); total += dVal; } int i = 0; for (Double sub : subCounter) { if (total == 0) { continue; } else if (expected.get(i) == 0) { continue; } else { double logNum = (sub / total) / expected.get(i); if (logNum <= 0) { continue; } else { psi = psi + ((sub / total - expected.get(i)) * Math.log(logNum)); } } i++; } unitStats.add((String) tuple.get(2)); } } // sort by unit Collections.sort(unitStats); Tuple output = TupleFactory.getInstance().newTuple(3); output.set(0, columnId); output.set(1, psi); output.set(2, StringUtils.join(unitStats, CalculateStatsUDF.CATEGORY_VAL_SEPARATOR)); return output; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.SBISpeedometer.java
/** * set parameters for the creation of the chart getting them from template or from LOV. * //from www . j a v a2s . c om * @param content the content of the template. * * @return A chart that displays a value as a dial. */ public void configureChart(SourceBean content) { super.configureChart(content); logger.debug("IN"); if (!isLovConfDefined) { logger.debug("Configuration set in template"); if (confParameters.get("increment") != null) { String increment = (String) confParameters.get("increment"); setIncrement(Double.valueOf(increment).doubleValue()); } else { logger.error("increment not defined"); return; } if (confParameters.get("minor_tick") != null) { String minorTickCount = (String) confParameters.get("minor_tick"); setMinorTickCount(Integer.valueOf(minorTickCount).intValue()); } else { setMinorTickCount(10); } if (confParameters.get("dialtextuse") != null) { String dialtextusetemp = (String) confParameters.get("dialtextuse"); if (dialtextusetemp.equalsIgnoreCase("true")) { dialtextuse = true; } else dialtextuse = false; } if (dialtextuse && confParameters.get("dialtext") != null) { dialtext = (String) confParameters.get("dialtext"); } //reading intervals information SourceBean intervalsSB = (SourceBean) content.getAttribute("INTERVALS"); if (intervalsSB == null) { intervalsSB = (SourceBean) content.getAttribute("CONF.INTERVALS"); } List intervalsAttrsList = null; if (intervalsSB != null) { intervalsAttrsList = intervalsSB.getContainedSourceBeanAttributes(); } if (intervalsAttrsList == null || intervalsAttrsList.isEmpty()) { // if intervals are not defined realize a single interval logger.warn("intervals not defined; default settings"); KpiInterval interval = new KpiInterval(); interval.setMin(getLower()); interval.setMax(getUpper()); interval.setColor(Color.WHITE); addInterval(interval); } else { Iterator intervalsAttrsIter = intervalsAttrsList.iterator(); while (intervalsAttrsIter.hasNext()) { SourceBeanAttribute paramSBA = (SourceBeanAttribute) intervalsAttrsIter.next(); SourceBean param = (SourceBean) paramSBA.getValue(); String min = (String) param.getAttribute("min"); String max = (String) param.getAttribute("max"); String col = (String) param.getAttribute("color"); KpiInterval interval = new KpiInterval(); interval.setMin(Double.valueOf(min).doubleValue()); interval.setMax(Double.valueOf(max).doubleValue()); Color color = new Color(Integer.decode(col).intValue()); if (color != null) { interval.setColor(color); } else { // sets default color interval.setColor(Color.WHITE); } addInterval(interval); } } } else { logger.debug("configuration defined in LOV" + confDataset); String increment = (String) sbRow.getAttribute("increment"); String minorTickCount = (String) sbRow.getAttribute("minor_tick"); setIncrement(Double.valueOf(increment).doubleValue()); setMinorTickCount(Integer.valueOf(minorTickCount).intValue()); String intervalsNumber = (String) sbRow.getAttribute("intervals_number"); if (intervalsNumber == null || intervalsNumber.equals("") || intervalsNumber.equals("0")) { // if intervals are not specified KpiInterval interval = new KpiInterval(); interval.setMin(getLower()); interval.setMax(getUpper()); interval.setColor(Color.WHITE); addInterval(interval); } else { for (int i = 1; i <= Integer.valueOf(intervalsNumber).intValue(); i++) { KpiInterval interval = new KpiInterval(); String min = (String) sbRow.getAttribute("min" + (new Integer(i)).toString()); String max = (String) sbRow.getAttribute("max" + (new Integer(i)).toString()); String col = (String) sbRow.getAttribute("color" + (new Integer(i)).toString()); interval.setMin(Double.valueOf(min).doubleValue()); interval.setMax(Double.valueOf(max).doubleValue()); Color color = new Color(Integer.decode(col).intValue()); interval.setColor(color); addInterval(interval); } } } logger.debug("out"); }
From source file:com.ottogroup.bi.streaming.operator.json.aggregate.functions.DoubleContentAggregateFunctionTest.java
/** * Test case for {@link DoubleContentAggregateFunction#min(Double, Double)} being * provided null as input to old min parameter *///from w w w. j a v a2s . c o m @Test public void testMin_withNullOldMin() throws Exception { Assert.assertEquals(Double.valueOf(9.87), new DoubleContentAggregateFunction().min(null, Double.valueOf(9.87))); }
From source file:com.mythesis.profileanalysis.Metrics.java
/** * A method that that computes log-likelihood given the results of LDA * @param LDAdirectory the directory that contains the model to be evaluated * @param file the name of the the file that contains the documents * @return log-likelihood/*w w w . j a v a 2 s .co m*/ */ public double getLogLikelihood(String LDAdirectory, String file) { double logLikelihood = 0.0; double alpha = 0.0; int T = 0; int W = 0; double beta = 0.0; int D = 0; File root = new File(LDAdirectory); File[] contents = root.listFiles(); List<String> others = new ArrayList<>(); List<String> tassign = new ArrayList<>(); for (File f : contents) { String str = f.getAbsolutePath().substring(f.getAbsolutePath().lastIndexOf('\\') + 1); if (str.endsWith("others") && str.startsWith(file)) { try { others = readLines(f); } catch (IOException ex) { Logger.getLogger(Evaluate.class.getName()).log(Level.SEVERE, null, ex); } } if (str.endsWith("tassign") && str.startsWith(file)) { try { tassign = readLines(f); } catch (IOException ex) { Logger.getLogger(Evaluate.class.getName()).log(Level.SEVERE, null, ex); } } } for (String s : others) { if (s.startsWith("nwords")) W = Integer.valueOf(s.substring(s.indexOf('=') + 1)); if (s.startsWith("ntopics")) T = Integer.valueOf(s.substring(s.indexOf('=') + 1)); if (s.startsWith("beta")) beta = Double.valueOf(s.substring(s.indexOf('=') + 1)); if (s.startsWith("alpha")) alpha = Double.valueOf(s.substring(s.indexOf('=') + 1)); if (s.startsWith("ndocs")) D = Integer.valueOf(s.substring(s.indexOf('=') + 1)); } //n_w_j is the number of times term w in topic j //n_j is the total number of terms in topic j //n_d_j is the number of times a word from document d has been assigned to topic j //n_d is the total number of topics in document d int[] n_j = new int[T]; int[][] n_w_j = new int[W][T]; int[][] n_d_j = new int[D][T]; int[] n_d = new int[D]; int index = 0; for (String doc : tassign) { String[] wordTopicTemp = doc.split(" "); for (String s : wordTopicTemp) { for (int i = 0; i < T; i++) { if (s.endsWith(String.valueOf(i))) { n_j[i]++; n_d_j[index][i]++; } } n_d[index]++; } index++; } Map<String, Integer> wordTopic = new HashMap<>(); for (String doc : tassign) { String[] temp = doc.split(" "); for (String s : temp) { Integer count = wordTopic.get(s); wordTopic.put(s, (count == null) ? 1 : count + 1); } } String[] temp; for (String s : wordTopic.keySet()) { temp = s.split(":"); int word = Integer.valueOf(temp[0]); int topic = Integer.valueOf(temp[1]); n_w_j[word][topic] = wordTopic.get(s); } // first part-log(p(z)) double logGammaAlpha = logGamma(alpha); for (int doc = 0; doc < D; doc++) { for (int topic = 0; topic < T; topic++) { if (n_d_j[doc][topic] > 0) { logLikelihood += logGamma(alpha + n_d_j[doc][topic]) - logGammaAlpha; } } logLikelihood -= logGamma(T * alpha + n_d[doc]); } logLikelihood += D * logGamma(alpha * T); //second part-log(p(w|z)) double logGammaBeta = logGamma(beta); for (int word = 0; word < W; word++) { for (int topic = 0; topic < T; topic++) { if (n_w_j[word][topic] == 0) { continue; } logLikelihood += logGamma(beta + n_w_j[word][topic]) + logGammaBeta; } } for (int topic = 0; topic < T; topic++) { logLikelihood -= logGamma((beta * W) + n_j[topic]); } logLikelihood += T * logGamma(beta * W); return logLikelihood; }
From source file:flow.visibility.pcap.FlowProcess.java
/** function to create internal frame contain flow summary chart */ public static JInternalFrame FlowStatistic() { final StringBuilder errbuf = new StringBuilder(); // For any error msgs final String file = "tmp-capture-file.pcap"; //System.out.printf("Opening file for reading: %s%n", file); /*************************************************************************** * Second we open up the selected file using openOffline call **************************************************************************/ Pcap pcap = Pcap.openOffline(file, errbuf); if (pcap == null) { System.err.printf("Error while opening device for capture: " + errbuf.toString()); }/* w w w. ja v a2 s. co m*/ Pcap pcap1 = Pcap.openOffline(file, errbuf); FlowMap map = new FlowMap(); pcap1.loop(Pcap.LOOP_INFINITE, map, null); //System.out.printf(map.toString()); //System.out.printf(map.toString2()); /** Splitting the packets statistics strings from FlowMap function */ String packet = map.toString2(); String[] NumberPacket = packet.split(","); final XYSeries Flow = new XYSeries("Flow"); for (int i = 0; i < NumberPacket.length - 1; i = i + 1) { //System.out.printf(NumberPacket[i+1] + "\n"); double NoPacket = Double.valueOf(NumberPacket[i + 1]); Flow.add(i, NoPacket); } /** Create dataset for chart */ final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(Flow); /** Create the internal frame contain flow summary chart */ JInternalFrame FlowStatistic = new JInternalFrame("Flow Statistic", true, true, true, true); FlowStatistic.setBounds(0, 0, 600, 330); ChartPanel chartPanel = new ChartPanel(createChart(dataset)); chartPanel.setMouseZoomable(true, false); FlowStatistic.add(chartPanel); FlowStatistic.setVisible(true); FlowStatistic.revalidate(); pcap1.close(); return FlowStatistic; }
From source file:com.pivotal.gemfire.tools.pulse.internal.service.ClusterMemberService.java
public JSONObject execute(final HttpServletRequest request) throws Exception { // get cluster object Cluster cluster = Repository.get().getCluster(); // json object to be sent as response JSONObject responseJSON = new JSONObject(); Cluster.Member[] clusterMembersList = cluster.getMembers(); // create members json List<JSONObject> memberListJson = new ArrayList<JSONObject>(); try {/*from www . j av a 2 s . co m*/ for (Cluster.Member clusterMember : clusterMembersList) { JSONObject memberJSON = new JSONObject(); // getting members detail memberJSON.put("memberId", clusterMember.getId()); memberJSON.put("name", clusterMember.getName()); memberJSON.put("host", clusterMember.getHost()); DecimalFormat df2 = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN); long usedHeapSize = cluster.getUsedHeapSize(); long currentHeap = clusterMember.getCurrentHeapSize(); if (usedHeapSize > 0) { float heapUsage = ((float) currentHeap / (float) usedHeapSize) * 100; memberJSON.put(this.HEAP_USAGE, Double.valueOf(df2.format(heapUsage))); } else { memberJSON.put(this.HEAP_USAGE, 0); } Float currentCPUUsage = clusterMember.getCpuUsage(); memberJSON.put("cpuUsage", Float.valueOf(df2.format(currentCPUUsage))); memberJSON.put("currentHeapUsage", clusterMember.getCurrentHeapSize()); memberJSON.put("isManager", clusterMember.isManager()); memberJSON.put("uptime", TimeUtils.convertTimeSecondsToHMS(clusterMember.getUptime())); memberJSON.put("loadAvg", clusterMember.getLoadAverage()); memberJSON.put("sockets", clusterMember.getTotalFileDescriptorOpen()); memberJSON.put("openFDs", clusterMember.getTotalFileDescriptorOpen()); memberJSON.put("threads", clusterMember.getNumThreads()); // Number of member clients if (PulseController.getPulseProductSupport() .equalsIgnoreCase(PulseConstants.PRODUCT_NAME_GEMFIREXD)) { memberJSON.put("clients", clusterMember.getNumGemFireXDClients()); } else { memberJSON.put("clients", clusterMember.getMemberClientsHMap().size()); } memberJSON.put("queues", clusterMember.getQueueBacklog()); memberListJson.add(memberJSON); } // clucter's Members responseJSON.put("members", memberListJson); // Send json response return responseJSON; } catch (JSONException e) { throw new Exception(e); } }
From source file:com.insightml.utils.Collections.java
public static <T, N extends Number> LinkedList<Pair<T, N>> sortDescending2(final List<Pair<T, N>> list) { final LinkedList<Pair<T, N>> newList = new LinkedList(list); java.util.Collections.sort(newList, (o1, o2) -> { int comp = Double.valueOf(o1.getSecond().doubleValue()).compareTo(o2.getSecond().doubleValue()); if (comp == 0) { if (o1.getFirst() instanceof Comparable) { comp = ((Comparable) o1.getFirst()).compareTo(o2.getFirst()); Check.state(comp != 0);/*from www . j a va 2 s . c om*/ } else { return 0; } } return comp > 0 ? -1 : 1; }); return newList; }
From source file:it.geosolutions.geostore.services.rest.utils.Convert.java
public static Attribute convertAttribute(ShortAttribute shattr) throws InternalErrorWebEx { Attribute ret = new Attribute(); ret.setName(shattr.getName());// w w w.j av a 2 s. co m ret.setType(shattr.getType()); if (shattr.getType() == null) throw new BadRequestWebEx("Missing type for attribute " + shattr); switch (ret.getType()) { case DATE: try { ret.setDateValue(Attribute.DATE_FORMAT.parse(shattr.getValue())); } catch (ParseException e) { throw new BadRequestWebEx("Error parsing attribute date value " + shattr); } break; case NUMBER: try { ret.setNumberValue(Double.valueOf(shattr.getValue())); } catch (NumberFormatException ex) { throw new BadRequestWebEx("Error parsing number value " + shattr); } break; case STRING: ret.setTextValue(shattr.getValue()); break; default: throw new InternalErrorWebEx("Unknown attribute type " + shattr); } return ret; }
From source file:edu.sampleu.travel.workflow.TravelAccountRulesEngineExecutor.java
@Override public EngineResults execute(RouteContext routeContext, Engine engine) { Map<String, String> contextQualifiers = new HashMap<String, String>(); contextQualifiers.put("namespaceCode", CONTEXT_NAMESPACE_CODE); contextQualifiers.put("name", CONTEXT_NAME); SelectionCriteria sectionCriteria = SelectionCriteria.createCriteria(null, contextQualifiers, Collections.singletonMap("Campus", "BL")); // extract facts from routeContext String docContent = routeContext.getDocument().getDocContent(); String subsidizedPercentStr = getElementValue(docContent, "//newMaintainableObject//subsidizedPercent"); String accountTypeCode = getElementValue(docContent, "//newMaintainableObject/dataObject/extension/accountTypeCode"); String initiator = getElementValue(docContent, "//documentInitiator//principalId"); Facts.Builder factsBuilder = Facts.Builder.create(); if (StringUtils.isNotEmpty(subsidizedPercentStr)) { factsBuilder.addFact("Subsidized Percent", Double.valueOf(subsidizedPercentStr)); }/* w w w . j ava2s . c om*/ factsBuilder.addFact("Account Type Code", accountTypeCode); factsBuilder.addFact("Initiator Principal ID", initiator); return engine.execute(sectionCriteria, factsBuilder.build(), null); }
From source file:de.tudarmstadt.lt.ltbot.prefetch.DecesiveValuePrioritizer.java
public void setAssignmentBoundaries(String assignmentBoundaries) { String[] bounds_as_strarr = assignmentBoundaries.split(","); double[] bounds = new double[bounds_as_strarr.length + 1]; // first value is a dummy value, never used for (int i = 0; i < bounds_as_strarr.length; i++) bounds[i + 1] = Double.valueOf(bounds_as_strarr[i]); kp.put("assignmentBoundaries", assignmentBoundaries); _assignmentBoundaries = bounds;/*from w w w.j a va 2s . c o m*/ }