List of usage examples for java.lang Double doubleValue
@HotSpotIntrinsicCandidate public double doubleValue()
From source file:org.deegree.portal.standard.context.control.AbstractContextListener.java
/** * Convenience method to extract the boundig box from an rpc fragment. * // w ww. j a v a 2 s. co m * @param bboxStruct * the <code>RPCStruct</code> containing the bounding box. For example, * <code><member><name>boundingBox</name>etc...</code>. * @param crs * a coordinate system value, may be null. * @return an envelope with the boundaries defined in the rpc structure */ protected Envelope extractBBox(RPCStruct bboxStruct, CoordinateSystem crs) { Double minx = (Double) bboxStruct.getMember(Constants.RPC_BBOXMINX).getValue(); Double miny = (Double) bboxStruct.getMember(Constants.RPC_BBOXMINY).getValue(); Double maxx = (Double) bboxStruct.getMember(Constants.RPC_BBOXMAXX).getValue(); Double maxy = (Double) bboxStruct.getMember(Constants.RPC_BBOXMAXY).getValue(); Envelope bbox = GeometryFactory.createEnvelope(minx.doubleValue(), miny.doubleValue(), maxx.doubleValue(), maxy.doubleValue(), crs); return bbox; }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
private double[] boxPlotValues(CoolMapObject object, VNode rowNode, VNode columnNode) { if (rowNode == null || columnNode == null || rowNode.isSingleNode() && columnNode.isSingleNode()) { return null; } else {/* www. ja v a 2s . com*/ Integer[] rowIndices; Integer[] colIndices; if (rowNode.isGroupNode()) { rowIndices = rowNode.getBaseIndicesFromCOntology((CMatrix) object.getBaseCMatrices().get(0), COntology.ROW); } else { rowIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)).getIndexOfRowName(rowNode.getName()) }; } if (columnNode.isGroupNode()) { colIndices = columnNode.getBaseIndicesFromCOntology((CMatrix) object.getBaseCMatrices().get(0), COntology.COLUMN); } else { colIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0)).getIndexOfColName(columnNode.getName()) }; } //A box plot across all matrices List<CMatrix> matrices = object.getBaseCMatrices(); Double value; ArrayList<Double> values = new ArrayList<Double>(); //add values for (Integer i : rowIndices) { if (i == null || i < 0) { continue; } for (Integer j : colIndices) { if (j == null || j < 0) { continue; } //Double value = (Double) getCoolMapObject().getViewValue(i, j); //This is wrong. it should eb the base matrix value, not the view values for (CMatrix<Double> matrix : matrices) { value = matrix.getValue(i, j); if (value == null || value.isNaN()) { continue; } else { //System.out.println(i + " " + j + " " + v); values.add(value); } } } } if (values.isEmpty()) { return null; } Collections.sort(values); int size = values.size(); double min = values.get(0); double max = values.get(values.size() - 1); double median; if (size % 2 == 0) { median = (values.get(size / 2) + values.get(size / 2 - 1)) / 2; } else { median = (values.get(size / 2)); } double[] valueArray = new double[values.size()]; int c = 0; for (Double d : values) { valueArray[c++] = d.doubleValue(); } Arrays.sort(valueArray); Percentile percentile = new Percentile(); double q1 = percentile.evaluate(valueArray, 25); double q3 = percentile.evaluate(valueArray, 75); // double median = percentile.evaluate(valueArray, 50); return new double[] { min, q1, median, q3, max }; } }
From source file:ch.epfl.lsir.xin.algorithm.core.MatrixFactorization.java
/** * This function learns a matrix factorization model using Alternative Least Square * refer to "Large-scale Parallel Collaborative Filtering for the Netix Prize" * *//* ww w . ja va2 s .co m*/ public void buildALS() { double preError = Double.MAX_VALUE; Matrix identify = Matrix.identity(this.latentFactors, this.latentFactors); for (int i = 0; i < this.Iterations; i++) { System.out.println("Iteration: " + i); double error = 0; //overall error of this iteration //fix item matrix M, solve user matrix U for (int j = 0; j < this.userMatrix.getRows(); j++) { //latent factor of items that are rated by user j int n = this.ratingMatrix.getUserRatingNumber(j);//number of items rated by user j double[][] m = new double[n][this.latentFactors]; int index = 0; for (int k = 0; k < this.itemMatrix.getRows(); k++) { if (!Double.isNaN(this.ratingMatrix.get(j, k))) { m[index++] = this.itemMatrix.getRowValues(k); } } Matrix M = new Matrix(m); //step 1: Matrix A = M.transpose().times(M).plus(identify.times(this.regUser).times(n)); //step 2: double[][] r = new double[1][n];//ratings of this user int index1 = 0; for (int k = 0; k < this.ratingMatrix.getColumn(); k++) { Double rating = this.ratingMatrix.getRatingMatrix().get(j).get(k); if (rating != null) { r[0][index1++] = rating.doubleValue(); } } Matrix R = new Matrix(r); Matrix V = M.transpose().times(R.transpose()); //step 3: the updated user matrix wrt user j Matrix uj = A.inverse().times(V); this.userMatrix.getValues()[j] = uj.transpose().getArray()[0]; } //fix user matrix U, solve item matrix M for (int j = 0; j < this.itemMatrix.getRows(); j++) { //latent factor of users that have rated item j int n = this.ratingMatrix.getItemRatingNumber(j);//number of users rate item j double[][] u = new double[n][this.latentFactors]; int index = 0; for (int k = 0; k < this.userMatrix.getRows(); k++) { if (!Double.isNaN(this.ratingMatrix.get(k, j))) { u[index++] = this.userMatrix.getRowValues(k); } } if (u.length == 0) continue; Matrix U = new Matrix(u); //step 1: Matrix A = U.transpose().times(U).plus(identify.times(this.regItem).times(n)); //step 2: double[][] r = new double[1][n];//ratings of this item int index1 = 0; for (int k = 0; k < this.ratingMatrix.getRow(); k++) { Double rating = this.ratingMatrix.getRatingMatrix().get(k).get(j); if (rating != null) { r[0][index1++] = rating.doubleValue(); } } Matrix R = new Matrix(r); Matrix V = U.transpose().times(R.transpose()); //step 3: the updated item matrix wrt item j Matrix mj = A.inverse().times(V); this.itemMatrix.getValues()[j] = mj.transpose().getArray()[0]; } //check for convergence //error ArrayList<MatrixEntry2D> entries = this.ratingMatrix.getValidEntries(); for (int k = 0; k < entries.size(); k++) { MatrixEntry2D entry = entries.get(k); double prediction = predict(entry.getRowIndex(), entry.getColumnIndex(), false); if (prediction > this.maxRating) prediction = this.maxRating; if (prediction < this.minRating) prediction = this.minRating; error = error + Math.abs(entry.getValue() - prediction); for (int j = 0; j < this.latentFactors; j++) { error = error + this.regUser / 2 * Math.pow(this.userMatrix.get(entry.getRowIndex(), j), 2) + this.regItem / 2 * Math.pow(this.itemMatrix.get(entry.getColumnIndex(), j), 2); } } this.logger.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " Iteration " + i + " : Error ~ " + error); this.logger.flush(); //check for convergence if (Math.abs(error - preError) <= this.convergence && error <= preError) { logger.println("The algorithm convergences."); this.logger.flush(); break; } preError = error; logger.flush(); } }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.teacher.onlineTests.ReadDistributedTestMarksToString.java
protected String run(String executionCourseId, String[] distributedTestCodes) throws FenixServiceException { StringBuilder result = new StringBuilder(); result.append(BundleUtil.getString(Bundle.APPLICATION, "label.username")).append("\t"); result.append(BundleUtil.getString(Bundle.APPLICATION, "label.number")).append("\t"); result.append(BundleUtil.getString(Bundle.APPLICATION, "label.name")).append("\t"); ExecutionCourse executionCourse = FenixFramework.getDomainObject(executionCourseId); List<Registration> studentsFromAttendsList = (List) CollectionUtils.collect(executionCourse.getAttendsSet(), new Transformer() { @Override// w ww . j ava2s . c o m public Object transform(Object input) { return ((Attends) input).getRegistration(); } }); final Set<Registration> students = new HashSet<Registration>(); for (final String distributedTestCode : distributedTestCodes) { final DistributedTest distributedTest = FenixFramework.getDomainObject(distributedTestCode); students.addAll(distributedTest.findStudents()); } List<Registration> studentList = concatStudentsLists(studentsFromAttendsList, students); Double[] maxValues = new Double[distributedTestCodes.length]; for (int i = 0; i < distributedTestCodes.length; i++) { DistributedTest distributedTest = FenixFramework.getDomainObject(distributedTestCodes[i]); if (distributedTest == null) { throw new InvalidArgumentsServiceException(); } maxValues[i] = distributedTest.calculateMaximumDistributedTestMark(); result.append(distributedTest.getTitle()); result.append("\t"); if (maxValues[i].doubleValue() > 0) { result.append("%\t"); } } for (Registration registration : studentList) { result.append("\n"); result.append(registration.getPerson().getUsername()); result.append("\t"); result.append(registration.getNumber()); result.append("\t"); result.append(registration.getPerson().getName()); result.append("\t"); for (int i = 0; i < distributedTestCodes.length; i++) { Double finalMark = new Double(0); DecimalFormat df = new DecimalFormat("#0.##"); DecimalFormat percentageFormat = new DecimalFormat("#%"); final DistributedTest distributedTest = FenixFramework.getDomainObject(distributedTestCodes[i]); finalMark = distributedTest.calculateTestFinalMarkForStudent(registration); if (finalMark == null) { result.append("NA\t"); if (maxValues[i].doubleValue() > 0) { result.append("NA\t"); } } else { if (finalMark.doubleValue() < 0) { result.append("0\t"); } else { result.append(df.format(finalMark.doubleValue())); result.append("\t"); } if (maxValues[i].doubleValue() > 0) { double finalMarkPercentage = finalMark.doubleValue() * java.lang.Math.pow(maxValues[i].doubleValue(), -1); if (finalMarkPercentage < 0) { result.append("0%\t"); } else { result.append(percentageFormat.format(finalMarkPercentage)); result.append("\t"); } } } } } return result.toString(); }
From source file:org.jbpm.designer.bpmn2.validation.BPMN2SyntaxChecker.java
private void checkTask(Task task, Scenario defaultScenario) { // simulation validation for (ElementParameters eleType : getElementParameters(defaultScenario, task)) { if (eleType.getCostParameters() != null) { CostParameters costParams = eleType.getCostParameters(); if (costParams.getUnitCost() != null) { FloatingParameterType unitCostVal = (FloatingParameterType) costParams.getUnitCost() .getParameterValue().get(0); Double val = unitCostVal.getValue(); if (val.doubleValue() < 0) { addError(task, new ValidationSyntaxError(task, SIMULATION_TYPE, SyntaxCheckerErrors.COST_PER_TIME_UNIT_MUST_BE_POSITIVE)); }//from w w w. ja va 2s . c om } } if (eleType.getResourceParameters() != null) { ResourceParameters resourceParams = eleType.getResourceParameters(); if (resourceParams.getQuantity() != null) { FloatingParameterType workingHoursVal = (FloatingParameterType) resourceParams.getQuantity() .getParameterValue().get(0); if (workingHoursVal.getValue() < 0) { addError(task, new ValidationSyntaxError(task, SIMULATION_TYPE, SyntaxCheckerErrors.WORKING_HOURS_MUST_BE_POSITIVE)); } } } } }
From source file:gov.nih.nci.cma.web.graphing.GEPlot.java
/** * * @param rbinaryFileName/*from w ww.j a va 2 s.c o m*/ * @param samples * @param reporters * @return 1 if the data set was prepared successfully * -1 if there was a problem preparing the data set */ public int prepareGeneGraphDataSet(String rbinaryFileName, List<SampleGroup> samples, ReporterGroup reporters) { for (SampleGroup sample : samples) groupList.add(sample.getGroupName()); List<ExpressionLookupFinding> findings = null; try { findings = AnalysisHelper.getExpressionValuesForReporters(reporters, rbinaryFileName, samples); } catch (Exception e) { logger.error("Error calling AnalysisHelper.getExpressionValuesForReporters"); logger.error(e); } int count = 0; if (findings != null && !findings.isEmpty()) { for (ExpressionLookupFinding finding : findings) { if (finding.getStatus() == FindingStatus.Error) return -1; List<DataPointVector> dataPointVectors = finding.getDataVectors(); if (!dataPointVectors.isEmpty()) { //Each DataPointVector contains data for a reporter. for (DataPointVector reporter : dataPointVectors) { List<Double> datalist = new ArrayList<Double>(); Map<String, List<Double>> tempMap = rawDataMap.get(reporter.getName()); if (tempMap == null) { tempMap = new HashMap<String, List<Double>>(); rawDataMap.put(reporter.getName(), tempMap); } List<DataPoint> dataPoints = reporter.getDataPoints(); for (DataPoint dataPoint : dataPoints) { datalist.add(dataPoint.getX()); } bwdataset.add(datalist, reporter.getName(), groupList.get(count)); tempMap.put(groupList.get(count), datalist); //The log2 value here is the mean log2 expression value for the probeset Double log2 = reporter.getMeanX(); Double stdDouble = reporter.getStdDeviationX(); //Generate log2 values for log2Dataset log2Dataset.add(log2, stdDouble, //new Double(stdd), reporter.getName(), groupList.get(count)); //The geometric mean is the anti-log2 mean value for the probeset. double log2Value = log2.doubleValue(); double stdd = stdDouble.doubleValue(); double mean = Fmath.antilog2(log2Value); gmDataset.addValue(new Double(mean), reporter.getName(), groupList.get(count)); //stddev for the probeset and sample group pair. stdDevMap.put(reporter.getName() + "::" + groupList.get(count), decimalFormat.format(stdd)); } } count++; } imgW = calculateImageWidth(bwdataset.getRowCount(), bwdataset.getColumnCount()); } return 1; }
From source file:Util.PacketGenerator.java
public void GenerateGraphGnuplot() { try {//from w w w. j av a2 s. c o m for (int j = 6; j <= 6; j++) { File real = new File("D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\Real.csv"); for (int k = 1; k <= 4; k++) { File simu = new File( "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\SimulacaoInstancia" + k + ".csv"); File dat = new File( "D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "\\SimulacaoInstancia" + k + ".txt"); FileInputStream simuFIS = new FileInputStream(simu); DataInputStream simuDIS = new DataInputStream(simuFIS); BufferedReader simuBR = new BufferedReader(new InputStreamReader(simuDIS)); FileInputStream realFIS = new FileInputStream(real); DataInputStream realDIS = new DataInputStream(realFIS); BufferedReader realBR = new BufferedReader(new InputStreamReader(realDIS)); PrintWriter datPW = new PrintWriter(dat); String lineSimu = simuBR.readLine(); String lineReal = realBR.readLine(); double maxX = 0.0; double maxY = 0.0; HashMap<Double, Double> map = new HashMap<>(); while (lineSimu != null && lineReal != null) { lineSimu = lineSimu.replaceAll(",", "."); String[] simuMatriz = lineSimu.split(";"); String[] realMatriz = lineReal.split(";"); for (int i = 0; i < simuMatriz.length; i++) { try { Integer valorReal = Integer.parseInt(realMatriz[i]); Double valorSimu = Double.parseDouble(simuMatriz[i]); if (map.containsKey(valorReal) && map.containsValue(valorSimu)) { continue; } map.put(valorReal.doubleValue(), valorSimu); datPW.write(valorReal.doubleValue() + "\t"); datPW.write(valorReal.doubleValue() + "\t"); datPW.write(valorSimu.doubleValue() + "\t"); datPW.write(valorReal.doubleValue() * 1.2 + "\t"); datPW.write(valorReal.doubleValue() * 0.8 + "\n"); if (valorReal > maxX) { maxX = valorReal; } if (valorSimu > maxY) { maxY = valorSimu; } } catch (NumberFormatException ex) { } } lineSimu = simuBR.readLine(); lineReal = realBR.readLine(); } simuFIS.close(); simuDIS.close(); simuBR.close(); realFIS.close(); realDIS.close(); realBR.close(); datPW.close(); Double max = Math.max(maxX, maxY); max *= 1.05; Process p = Runtime.getRuntime().exec("cmd"); new Thread(new SyncPipe(p.getErrorStream(), System.err)).start(); new Thread(new SyncPipe(p.getInputStream(), System.out)).start(); PrintWriter stdin = new PrintWriter(p.getOutputStream()); stdin.println("gnuplot"); stdin.println("cd 'D:\\Mestrado\\SketchMatrix\\trunk\\Simulations\\Analise\\Scenario1\\Topology" + j + "'"); stdin.println("set terminal postscript eps enhanced \"Times\" 20"); stdin.println("set output \"SimulacaoInstancia" + k + ".eps\""); stdin.println("unset title"); stdin.println("unset style line"); stdin.println("set style line 1 pt 7 lc 7 lw 1"); stdin.println("set style line 2 lt 1 lc 7 lw 1"); stdin.println("set style line 3 lt 4 lc 7 lw 1"); stdin.println("set style line 4 lt 4 lc 7 lw 1"); stdin.println("set style line 5 lt 5 lc 5 lw 3"); stdin.println("set style line 6 lt 6 lc 6 lw 3"); stdin.println("set style line 7 pt 7 lc 7 lw 3"); if (k == 4) { stdin.println("set ylabel \"CMO-MT\""); stdin.println("set xlabel \"Real\""); } else { stdin.println("set ylabel \"Zhao\""); stdin.println("set xlabel \"CMO-MT\""); } stdin.println("set key top left"); stdin.println("set xrange [0:" + max.intValue() + "]"); stdin.println("set yrange [0:" + max.intValue() + "]"); stdin.println("set grid ytics lc rgb \"#bbbbbb\" lw 1 lt 0"); stdin.println("set grid xtics lc rgb \"#bbbbbb\" lw 1 lt 0"); stdin.println("plot " + "x title \"Referencia\" ls 2," + "\"SimulacaoInstancia" + k + ".txt\" using 1:3 title \"Matriz\" ls 7," + "1.2*x title \"Superior 20%\" ls 4," + "0.8*x title \"Inferior 20%\" ls 4"); stdin.println("exit"); stdin.println("exit"); // write any other commands you want here stdin.close(); int returnCode = p.waitFor(); System.out.println("Return code = " + returnCode); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.l2jfree.gameserver.gameobjects.templates.L2NpcTemplate.java
public double getVulnerability(Stats id) { if (_vulnerabilities == null) return 1; Double vuln = _vulnerabilities.get(id); return vuln == null ? 1 : vuln.doubleValue(); }
From source file:org.sakaiproject.tool.gradebook.ui.GradebookDependentBean.java
/** * We can't rely on the converters to properly display 2 decimals for us, * b/c setMaxFractionDigits rounds /*from ww w .j a v a2 s . co m*/ * @param score * @return */ public Double truncateScore(Double score) { if (score == null) return null; return new Double(FacesUtil.getRoundDown(score.doubleValue(), 2)); }
From source file:org.pentaho.platform.uifoundation.chart.PieDatasetChartDefinition.java
/** * @param node//w ww . ja v a 2s . c om * The labelGap to set. */ public void setLabelGap(final Node labelGapNode) { if (labelGapNode != null) { String gapNodeStr = labelGapNode.getText(); Double doubleValue = new Double(gapNodeStr); setLabelGap(doubleValue.doubleValue()); } }