List of usage examples for java.lang Math log10
@HotSpotIntrinsicCandidate public static double log10(double a)
From source file:edu.umn.cs.spatialHadoop.operations.GeometricPlot.java
/** * Draws an image that can be used as a scale for heat maps generated using * Plot or PlotPyramid.//from ww w. jav a2 s. c o m * @param output - Output path * @param valueRange - Range of values of interest * @param width - Width of the generated image * @param height - Height of the generated image * @throws IOException */ public static void drawScale(Path output, MinMax valueRange, int width, int height) throws IOException { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setBackground(Color.BLACK); g.clearRect(0, 0, width, height); // fix this part to work according to color1, color2 and gradient type for (int y = 0; y < height; y++) { Color color = NASARectangle.calculateColor(y); g.setColor(color); g.drawRect(width * 3 / 4, y, width / 4, 1); } int fontSize = 24; g.setFont(new Font("Arial", Font.BOLD, fontSize)); int step = (valueRange.maxValue - valueRange.minValue) * fontSize * 10 / height; step = (int) Math.pow(10, Math.round(Math.log10(step))); int min_value = valueRange.minValue / step * step; int max_value = valueRange.maxValue / step * step; for (int value = min_value; value <= max_value; value += step) { int y = fontSize + (height - fontSize) - value * (height - fontSize) / (valueRange.maxValue - valueRange.minValue); g.setColor(Color.WHITE); g.drawString(String.valueOf(value), 5, y); } g.dispose(); FileSystem fs = output.getFileSystem(new Configuration()); FSDataOutputStream outStream = fs.create(output, true); ImageIO.write(image, "png", outStream); outStream.close(); }
From source file:org.eclipse.january.dataset.DatasetUtils.java
/** * Function that returns a normalised dataset which is bounded between 0 and 1 * and has been distributed on a log10 scale * @param a dataset//from w w w .ja va2 s .co m * @return normalised dataset */ public static Dataset lognorm(Dataset a) { double amin = a.min().doubleValue(); double aptp = Math.log10(a.max().doubleValue() - amin + 1.); Dataset temp = Maths.subtract(a, amin - 1.); temp = Maths.log10(temp); temp = Maths.divide(temp, aptp); return temp; }
From source file:org.ohmage.query.impl.DocumentQueries.java
/** * Builds the name of a folder by prepending zeroes where necessary and * converting the name into a String./* www. ja v a 2s . c o m*/ * * @param name The name of the file as an integer. * * @param numFilesPerDirectory The maximum number of files allowed in the * directory used to determine how many zeroes * to prepend. * * @return A String representing the directory name based on the * parameters. */ private String directoryNameBuilder(long name, int numFilesPerDirectory) { int nameLength = String.valueOf(name).length(); int maxLength = new Double(Math.log10(numFilesPerDirectory)).intValue(); int numberOfZeros = maxLength - nameLength; StringBuilder builder = new StringBuilder(); for (int i = 0; i < numberOfZeros; i++) { builder.append("0"); } builder.append(String.valueOf(name)); return builder.toString(); }
From source file:marytts.tools.redstart.AdminWindow.java
private void jMenuItem_ImportTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem_ImportTextActionPerformed JFileChooser fc = new JFileChooser(new File(voiceFolderPathString)); fc.setDialogTitle("Choose text file to import"); //fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showOpenDialog(this); if (returnVal != JFileChooser.APPROVE_OPTION) return;/*from w w w . j av a 2 s.c o m*/ File file = fc.getSelectedFile(); if (file == null) return; String[] lines = null; try { lines = StringUtils.readTextFile(file.getAbsolutePath(), "UTF-8"); } catch (IOException ioe) { ioe.printStackTrace(); } if (lines == null || lines.length == 0) return; Object[] options = new Object[] { "Keep first column", "Discard first column" }; int answer = JOptionPane.showOptionDialog(this, "File contains " + lines.length + " sentences.\n" + "Sample line:\n" + lines[0] + "\n" + "Keep or discard first column?", "Import details", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); boolean discardFirstColumn = (answer == JOptionPane.NO_OPTION); String prefix = (String) JOptionPane.showInputDialog(this, "Prefix to use for individual sentence filenames:", "Choose filename prefix", JOptionPane.PLAIN_MESSAGE, null, null, "s"); int numDigits = (int) Math.log10(lines.length) + 1; String pattern = prefix + "%0" + numDigits + "d.txt"; File scriptFile = new File(voiceFolderPathString + "/" + file.getName() + ".script.txt"); PrintWriter scriptWriter = null; try { scriptWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(scriptFile), "UTF-8")); } catch (IOException e) { JOptionPane.showMessageDialog(this, "Cannot write to script file " + scriptFile.getAbsolutePath() + ":\n" + e.getMessage()); if (scriptWriter != null) scriptWriter.close(); return; } File textFolder = getPromptFolderPath(); // if filename ends with ".txt_tr" then it has also transcriptions in it String selectedFile_ext = FilenameUtils.getExtension(file.getName()); Boolean inputHasAlsoTranscription = false; File transcriptionFolder = new File(""); // transcription folder name, and makedir if (selectedFile_ext.equals("txt_tr")) { System.out.println("txt_tr"); if (lines.length % 2 == 0) { // even } else { // odd System.err.println(".txt_tr file has an odd number of lines, so it's corrupted, exiting."); System.exit(0); } inputHasAlsoTranscription = true; String transcriptionFolderName = voiceFolderPathString + AdminWindow.TRANSCRIPTION_FOLDER_NAME; transcriptionFolder = new File(transcriptionFolderName); if (transcriptionFolder.exists()) { System.out.println("transcription folder already exists"); } else { if (transcriptionFolder.mkdirs()) { System.out.println("transcription folder created"); } else { System.err.println("Cannot create transcription folder -- exiting."); System.exit(0); } } } else { System.out.println("input file extension is not txt_tr, but " + selectedFile_ext + ", so it contains ortographic sentences without transcriptions."); } for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (discardFirstColumn) line = line.substring(line.indexOf(' ') + 1); int sent_index = i + 1; if (inputHasAlsoTranscription == true) { sent_index = i / 2 + 1; } String filename = String.format(pattern, sent_index); System.out.println(filename + " " + line); File textFile = new File(textFolder, filename); if (textFile.exists()) { JOptionPane.showMessageDialog(this, "Cannot writing file " + filename + ":\n" + "File exists!\n" + "Aborting text file import."); return; } PrintWriter pw = null; try { pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(textFile), "UTF-8")); pw.println(line); scriptWriter.println(filename.substring(0, filename.lastIndexOf('.')) + " " + line); } catch (IOException ioe) { JOptionPane.showMessageDialog(this, "Error writing file " + filename + ":\n" + ioe.getMessage()); ioe.printStackTrace(); return; } finally { if (pw != null) pw.close(); } // transcription case: if (inputHasAlsoTranscription == true) { // modify pattern: best would be something like sed "s/.txt$/.tr$/" // easy but dirty: String transc_pattern = pattern.replace(".txt", ".tr"); filename = String.format(transc_pattern, sent_index); i++; line = lines[i]; if (discardFirstColumn) line = line.substring(line.indexOf(' ') + 1); File transcriptionTextFile = new File(transcriptionFolder, filename); if (transcriptionTextFile.exists()) { JOptionPane.showMessageDialog(this, "Cannot writing file " + transcriptionTextFile.getName() + ":\n" + "File exists!\n" + "Aborting text file import."); return; } pw = null; try { pw = new PrintWriter( new OutputStreamWriter(new FileOutputStream(transcriptionTextFile), "UTF-8")); pw.println(line); scriptWriter.println(filename.substring(0, filename.lastIndexOf('.')) + " " + line); } catch (IOException ioe) { JOptionPane.showMessageDialog(this, "Error writing file " + filename + ":\n" + ioe.getMessage()); ioe.printStackTrace(); return; } finally { if (pw != null) pw.close(); } } } scriptWriter.close(); setupVoice(); }
From source file:org.esa.nest.gpf.ASARCalibrator.java
/** * Remove the antenna pattern compensation and range spreading loss applied to the pixel. * * @param x The x coordinate of the pixel in the source image. * @param y The y coordinate of the pixel in the source image. * @param v The pixel value. * @param bandPolar The polarization of the source band. * @param bandUnit The source band unit. * @param subSwathIndex The sub swath index for current pixel for wide swath product case. * @return The pixel value with antenna pattern compensation and range spreading loss correction removed. *//*w w w .j a v a 2s . co m*/ public double applyRetroCalibration(int x, int y, double v, String bandPolar, final Unit.UnitType bandUnit, int[] subSwathIndex) { if (!retroCalibrationFlag) { return v; } int bandPolarIdx = 0; if (bandPolar != null && mdsPolar[1] != null && mdsPolar[1].contains(bandPolar)) { bandPolarIdx = 1; } final double zeroDopplerTime = firstLineUTC + y * lineTimeInterval; final double satelitteHeight = computeSatelliteHeight(zeroDopplerTime, orbitStateVectors); AbstractMetadata.SRGRCoefficientList srgrConvParam = null; if (srgrFlag) { srgrConvParam = getSRGRCoefficientsForARangeLine(zeroDopplerTime); } final TiePointInterpolator slantRangeTPGInterp = new TiePointInterpolator(slantRangeTime); final double slantRange = computeSlantRange(x, y, srgrConvParam, slantRangeTPGInterp); // in m final double elevationAngle = computeElevationAngle(slantRange, satelitteHeight, avgSceneHeight + getEarthRadius(x, y)); double gain = 0.0; if (wideSwathProductFlag) { gain = getAntennaPatternGain(elevationAngle, bandPolarIdx, oldRefElevationAngle, oldAntennaPatternWideSwath, true, subSwathIndex); } else { gain = computeAntPatGain(elevationAngle, oldRefElevationAngle[0], oldAntennaPatternSingleSwath[bandPolarIdx]); } if (bandUnit == Unit.UnitType.AMPLITUDE) { return v * Math.sqrt(gain) * Math.pow(refSlantRange800km / slantRange, halfRangeSpreadingCompPower); // amplitude } else if (bandUnit == Unit.UnitType.AMPLITUDE_DB) { return 10.0 * Math.log10(Math.pow(10, v / 10.0) * Math.sqrt(gain) * Math.pow(refSlantRange800km / slantRange, halfRangeSpreadingCompPower)); } else if (bandUnit == Unit.UnitType.INTENSITY || bandUnit == Unit.UnitType.REAL || bandUnit == Unit.UnitType.IMAGINARY) { return v * gain * Math.pow(refSlantRange800km / slantRange, rangeSpreadingCompPower); // intensity } else if (bandUnit == Unit.UnitType.INTENSITY_DB) { return 10.0 * Math.log10(Math.pow(10, v / 10.0) * gain * Math.pow(refSlantRange800km / slantRange, rangeSpreadingCompPower)); } else { throw new OperatorException("Unknown band unit"); } }
From source file:org.gumtree.vis.plot1d.LogarithmizableAxis.java
private List getAllTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { List ticks = new java.util.ArrayList(); //get lower bound value: double lowerBoundVal = getRange().getLowerBound(); //if small log values and lower bound value too small // then set to a small value (don't allow <= 0): if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) { lowerBoundVal = SMALL_LOG_VALUE; }//from w w w .ja v a 2 s .c om //get upper bound value double upperBoundVal = getRange().getUpperBound(); //get log10 version of lower bound and round to integer: int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal)); //get log10 version of upper bound and round to integer: int iEndCount = (int) Math.rint(switchedLog10(upperBoundVal)); if (iBegCount == iEndCount && iBegCount > 0 && Math.pow(10, iBegCount) > lowerBoundVal) { //only 1 power of 10 value, it's > 0 and its resulting // tick value will be larger than lower bound of data --iBegCount; //decrement to generate more ticks } int numberOfGrids = 0; int numberOfTicks = 0; NumberTick lastTick = null; double tickVal; String tickLabel; // tickVal = lowerBoundVal; // // tickLabel = Long.toString((long) Math.rint(tickVal)); // ticks.add(new NumberTick(new Double(tickVal), tickLabel, // TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0)); boolean zeroTickFlag = false; for (int i = iBegCount; i <= iEndCount; i++) { //for each tick with a label to be displayed int jEndCount = 10; if (i == iEndCount) { // jEndCount = 1; } for (int j = 0; j < jEndCount; j++) { //for each tick to be displayed if (this.smallLogFlag) { //small log values in use tickVal = Math.pow(10, i) + (Math.pow(10, i) * j); //first tick of group; create label text if (this.log10TickLabelsFlag) { //if flag then tickLabel = "10^" + i; //create "log10"-type label } else { //not "log10"-type label if (this.expTickLabelsFlag) { //if flag then tickLabel = "1e" + i; //create "1e#"-type label } else { //not "1e#"-type label if (i >= 0) { // if positive exponent then // make integer NumberFormat format = getNumberFormatOverride(); if (format != null) { tickLabel = format.format(tickVal); } else { tickLabel = Long.toString((long) Math.rint(tickVal)); } } else { //negative exponent; create fractional value //set exact number of fractional digits to // be shown: this.numberFormatterObj.setMaximumFractionDigits(-i); //create tick label: tickLabel = this.numberFormatterObj.format(tickVal); } } } } else { //not small log values in use; allow for values <= 0 if (zeroTickFlag) { //if did zero tick last iter then --j; } //decrement to do 1.0 tick now tickVal = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j) : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j)); if (!zeroTickFlag) { // did not do zero tick last // iteration if (i > iBegCount && i < iEndCount && Math.abs(tickVal - 1.0) < 0.0001) { // not first or last tick on graph and value // is 1.0 tickVal = 0.0; //change value to 0.0 zeroTickFlag = true; //indicate zero tick tickLabel = "0"; //create label for tick } else { //first or last tick on graph or value is 1.0 //create label for tick: tickLabel = createTickLabel(tickVal, i); } } else { // not first tick of group tickLabel = createTickLabel(tickVal, i); } } if (tickVal > upperBoundVal) { if (lastTick != null) { String lastTickText = lastTick.getText(); if (lastTickText == null || lastTickText.trim().length() == 0) { ticks.remove(lastTick); ticks.add(new NumberTick(lastTick.getValue(), createTickLabel(lastTick.getValue(), i - 1), lastTick.getTextAnchor(), lastTick.getRotationAnchor(), lastTick.getAngle())); } } if (ticks.size() < 2) { double definition = Math.abs(lowerBoundVal - upperBoundVal); int numberOfDigits = 0; if (definition >= 1) numberOfDigits = 0; else { numberOfDigits = (int) Math.ceil((-Math.log10(definition))); } tickVal = lowerBoundVal; if (definition > 1) tickLabel = Long.toString((long) Math.rint(tickVal)); else tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString(); ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0)); tickVal = upperBoundVal; if (definition > 1) tickLabel = Long.toString((long) Math.rint(tickVal)); else tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString(); ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0)); } return ticks; //if past highest data value then exit method } if (tickVal >= lowerBoundVal - SMALL_LOG_VALUE) { //tick value not below lowest data value TextAnchor anchor = null; TextAnchor rotationAnchor = null; double angle = 0.0; if (isVerticalTickLabels()) { if (edge == RectangleEdge.LEFT) { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; angle = -Math.PI / 2.0; } else { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; angle = Math.PI / 2.0; } } else { if (edge == RectangleEdge.LEFT) { anchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; } else { anchor = TextAnchor.CENTER_LEFT; rotationAnchor = TextAnchor.CENTER_LEFT; } } //create tick object and add to list: lastTick = new NumberTick(new Double(tickVal), tickLabel, anchor, rotationAnchor, angle); ticks.add(lastTick); if (tickLabel != null && tickLabel.trim().length() > 0) numberOfTicks++; numberOfGrids++; } } } if (ticks.size() < 2) { double definition = Math.abs(lowerBoundVal - upperBoundVal); int numberOfDigits = 0; if (definition >= 1) numberOfDigits = 0; else { numberOfDigits = (int) Math.ceil((-Math.log10(definition))); } tickVal = lowerBoundVal; if (definition > 1) tickLabel = Long.toString((long) Math.rint(tickVal)); else tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString(); ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0)); tickVal = upperBoundVal; if (definition > 1) tickLabel = Long.toString((long) Math.rint(tickVal)); else tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString(); ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0)); } return ticks; }
From source file:org.esa.s1tbx.calibration.gpf.ASARCalibrator.java
/** * Remove the antenna pattern compensation and range spreading loss applied to the pixel. * * @param x The x coordinate of the pixel in the source image. * @param y The y coordinate of the pixel in the source image. * @param v The pixel value. * @param bandPolar The polarization of the source band. * @param bandUnit The source band unit. * @param subSwathIndex The sub swath index for current pixel for wide swath product case. * @return The pixel value with antenna pattern compensation and range spreading loss correction removed. *///from ww w . j av a2s.c o m public double applyRetroCalibration(int x, int y, double v, String bandPolar, final Unit.UnitType bandUnit, int[] subSwathIndex) { if (!retroCalibrationFlag) { return v; } int bandPolarIdx = 0; if (bandPolar != null && mdsPolar[1] != null && mdsPolar[1].contains(bandPolar)) { bandPolarIdx = 1; } final double zeroDopplerTime = firstLineUTC + y * lineTimeInterval; final double satelitteHeight = computeSatelliteHeight(zeroDopplerTime, orbitStateVectors); AbstractMetadata.SRGRCoefficientList srgrConvParam = null; if (srgrFlag) { srgrConvParam = getSRGRCoefficientsForARangeLine(zeroDopplerTime); } final TiePointInterpolator slantRangeTPGInterp = new TiePointInterpolator(slantRangeTime); final double slantRange = computeSlantRange(x, y, srgrConvParam, slantRangeTPGInterp); // in m final double elevationAngle = computeElevationAngle(slantRange, satelitteHeight, avgSceneHeight + getEarthRadius(x, y)); double gain = 0.0; if (wideSwathProductFlag) { gain = getAntennaPatternGain(elevationAngle, bandPolarIdx, oldRefElevationAngle, oldAntennaPatternWideSwath, true, subSwathIndex); } else { gain = computeAntPatGain(elevationAngle, oldRefElevationAngle[0], oldAntennaPatternSingleSwath[bandPolarIdx]); } if (bandUnit == Unit.UnitType.AMPLITUDE) { return v * Math.sqrt(gain) * FastMath.pow(refSlantRange800km / slantRange, halfRangeSpreadingCompPower); // amplitude } else if (bandUnit == Unit.UnitType.AMPLITUDE_DB) { return 10.0 * Math.log10(FastMath.pow(10, v / 10.0) * Math.sqrt(gain) * FastMath.pow(refSlantRange800km / slantRange, halfRangeSpreadingCompPower)); } else if (bandUnit == Unit.UnitType.INTENSITY || bandUnit == Unit.UnitType.REAL || bandUnit == Unit.UnitType.IMAGINARY) { return v * gain * FastMath.pow(refSlantRange800km / slantRange, rangeSpreadingCompPower); // intensity } else if (bandUnit == Unit.UnitType.INTENSITY_DB) { return 10.0 * Math.log10(FastMath.pow(10, v / 10.0) * gain * FastMath.pow(refSlantRange800km / slantRange, rangeSpreadingCompPower)); } else { throw new OperatorException("Unknown band unit"); } }
From source file:netdecoder.NetDecoder.java
public Set<String> prioritizeSinks(Map<String, Node> controlNetwork, Map<String, Node> diseaseNetwork, String condition, int topSinks, RJava rJava, String filename, List<String> Rscripts) throws IOException { Map<String, Map<String, Double>> flowInNetworks = getFlowInNetworks(controlNetwork, diseaseNetwork); Map<String, Double> controlSinksMap = NetDecoderUtils.getSinks(controlNetwork); Map<String, Double> diseaseSinksMap = NetDecoderUtils.getSinks(diseaseNetwork); Set<String> allSinks = new LinkedHashSet(controlSinksMap.keySet()); allSinks.addAll(diseaseSinksMap.keySet()); Map<String, Double> flowDifference = NetDecoderUtils.getFlowDifference(flowInNetworks, allSinks); Map<String, Double> sortedScores = NetworkFlow.sortByValues(flowDifference); List<String> aux = new ArrayList(sortedScores.keySet()); List<String> topGenes_down = aux.subList(0, topSinks); List<String> topGenes_up = aux.subList(aux.size() - topSinks, aux.size()); List<String> topGenes = new ArrayList(topGenes_down); topGenes.addAll(topGenes_up);/*from www . j a v a 2 s . c o m*/ Map<String, Double> topGenesScores = new LinkedHashMap(); for (String g : topGenes) { if (sortedScores.get(g) > 0) { topGenesScores.put(g, Math.log10(sortedScores.get(g))); } else { double tmp = -Math.log10(Math.abs(sortedScores.get(g))); topGenesScores.put(g, tmp); } } String name = filename + "_SINKS"; NetDecoderUtils.saveFlows(topGenesScores, name + ".txt"); //rJava.plotHeatmapSH2(name, condition, topSinks, "Key targets",filename); String heatmap = rJava.createHeatmapSH2Script(name, condition, topSinks, "Key targets", filename); Rscripts.add(heatmap); //save network motifs for network routers here (downstream genes, network router is "from" in the edge): Map<String, Double> totalFlowsDisease = NetDecoderUtils.getTotalFlow(diseaseNetwork); Map<String, Double> totalFlowsControl = NetDecoderUtils.getTotalFlow(controlNetwork); for (String gene : topGenesScores.keySet()) { if (controlNetwork.containsKey(gene)) { List<Edge> controlEdges = controlNetwork.get(gene).getEdges(); Map<String, Node> cNet = NetDecoderUtils.createMotifTargets(gene, controlEdges); (new NetworkFlow()).saveSubNet(cNet, filename + "_" + gene + "_KT_Control.txt"); Map<String, Double> controlDiff = getFlowDifference(flowInNetworks, cNet.keySet()); Map<String, Double> controlTotal = getTotalFlowInProteins(totalFlowsControl, cNet.keySet()); Map<String, Double> controlEdgesFlow = getEdgeFlow(cNet); NetDecoderUtils.saveFlows(controlTotal, filename + "_" + gene + "_KT_totalFlow_Control.txt"); NetDecoderUtils.saveFlows(controlDiff, filename + "_" + gene + "_KT_flowDifference_Control.txt"); NetDecoderUtils.saveFlows(controlEdgesFlow, filename + "_" + gene + "_KT_edge_flows_Control.txt"); //rJava.exportGML2(filename + "_" + gene + "_KT_Control", // filename + "_" + gene + "_KT_totalFlow_Control", // filename + "_" + gene + "_KT_flowDifference_Control"); String gmlControl = rJava.createScriptExportGML2(filename + "_" + gene + "_KT_Control", filename + "_" + gene + "_KT_totalFlow_Control", filename + "_" + gene + "_KT_flowDifference_Control"); //rJava.plotDistribution(filename + "_" + gene + "_KT_edge_flows_Control", "Control"); String distrControl = rJava .createDistributionScript(filename + "_" + gene + "_KT_edge_flows_Control", "Control"); Rscripts.add(gmlControl); Rscripts.add(distrControl); } if (diseaseNetwork.containsKey(gene)) { List<Edge> diseaseEdges = diseaseNetwork.get(gene).getEdges(); Map<String, Node> dNet = NetDecoderUtils.createMotifTargets(gene, diseaseEdges); (new NetworkFlow()).saveSubNet(dNet, filename + "_" + gene + "_KT_Disease.txt"); Map<String, Double> diseaseDiff = getFlowDifference(flowInNetworks, dNet.keySet()); Map<String, Double> diseaseTotal = getTotalFlowInProteins(totalFlowsDisease, dNet.keySet()); Map<String, Double> diseaseEdgesFlow = getEdgeFlow(dNet); NetDecoderUtils.saveFlows(diseaseTotal, filename + "_" + gene + "_KT_totalFlow_Disease.txt"); NetDecoderUtils.saveFlows(diseaseDiff, filename + "_" + gene + "_KT_flowDifference_Disease.txt"); NetDecoderUtils.saveFlows(diseaseEdgesFlow, filename + "_" + gene + "_KT_edge_flows_Disease.txt"); /*rJava.exportGML2(filename + "_" + gene + "_KT_Disease", filename + "_" + gene + "_KT_totalFlow_Disease", filename + "_" + gene + "_KT_flowDifference_Disease"); rJava.plotDistribution(filename + "_" + gene + "_KT_edge_flows_Disease", condition);*/ String gmlDisease = rJava.createScriptExportGML2(filename + "_" + gene + "_KT_Disease", filename + "_" + gene + "_KT_totalFlow_Disease", filename + "_" + gene + "_KT_flowDifference_Disease"); String distrDisease = rJava .createDistributionScript(filename + "_" + gene + "_KT_edge_flows_Disease", condition); Rscripts.add(gmlDisease); Rscripts.add(distrDisease); } } return topGenesScores.keySet(); }
From source file:org.broadinstitute.gatk.utils.MathUtils.java
/** * Returns a series of integer values between start and stop, inclusive, * expontentially distributed between the two. That is, if there are * ten values between 0-10 there will be 10 between 10-100. * * WARNING -- BADLY TESTED/*from w w w. ja v a 2 s . com*/ * @param start * @param stop * @param eps * @return */ public static List<Integer> log10LinearRange(final int start, final int stop, final double eps) { final LinkedList<Integer> values = new LinkedList<>(); final double log10range = Math.log10(stop - start); if (start == 0) values.add(0); double i = 0.0; while (i <= log10range) { final int index = (int) Math.round(Math.pow(10, i)) + start; if (index < stop && (values.peekLast() == null || values.peekLast() != index)) values.add(index); i += eps; } if (values.peekLast() == null || values.peekLast() != stop) values.add(stop); return values; }
From source file:org.nd4j.linalg.util.BigDecimalMath.java
/** * The hyperbolic sine.//from w w w.java2 s .c o m * * @param x the argument. * @return the sinh(x) = (exp(x)-exp(-x))/2 . */ static public BigDecimal sinh(final BigDecimal x) { if (x.compareTo(BigDecimal.ZERO) < 0) { return sinh(x.negate()).negate(); } else if (x.compareTo(BigDecimal.ZERO) == 0) { return BigDecimal.ZERO; } else { if (x.doubleValue() > 2.4) { /* Move closer to zero with sinh(2x)= 2*sinh(x)*cosh(x). */ BigDecimal two = new BigDecimal(2); BigDecimal xhalf = x.divide(two); BigDecimal resul = sinh(xhalf).multiply(cosh(xhalf)).multiply(two); /* The error in the result is set by the error in x itself. * The first derivative of sinh(x) is cosh(x), so the absolute error * in the result is cosh(x)*errx, and the relative error is coth(x)*errx = errx/tanh(x) */ double eps = Math.tanh(x.doubleValue()); MathContext mc = new MathContext(err2prec(0.5 * x.ulp().doubleValue() / eps)); return resul.round(mc); } else { BigDecimal xhighpr = scalePrec(x, 2); /* Simple Taylor expansion, sum_{i=0..infinity} x^(2i+1)/(2i+1)! */ BigDecimal resul = xhighpr; /* x^i */ BigDecimal xpowi = xhighpr; /* 2i+1 factorial */ BigInteger ifac = BigInteger.ONE; /* The error in the result is set by the error in x itself. */ double xUlpDbl = x.ulp().doubleValue(); /* The error in the result is set by the error in x itself. * We need at most k terms to squeeze x^(2k+1)/(2k+1)! below this value. * x^(2k+1) < x.ulp; (2k+1)*log10(x) < -x.precision; 2k*log10(x)< -x.precision; * 2k*(-log10(x)) > x.precision; 2k*log10(1/x) > x.precision */ int k = (int) (x.precision() / Math.log10(1.0 / xhighpr.doubleValue())) / 2; MathContext mcTay = new MathContext(err2prec(x.doubleValue(), xUlpDbl / k)); for (int i = 1;; i++) { /* TBD: at which precision will 2*i or 2*i+1 overflow? */ ifac = ifac.multiply(new BigInteger("" + (2 * i))); ifac = ifac.multiply(new BigInteger("" + (2 * i + 1))); xpowi = xpowi.multiply(xhighpr).multiply(xhighpr); BigDecimal corr = xpowi.divide(new BigDecimal(ifac), mcTay); resul = resul.add(corr); if (corr.abs().doubleValue() < 0.5 * xUlpDbl) { break; } } /* The error in the result is set by the error in x itself. */ MathContext mc = new MathContext(x.precision()); return resul.round(mc); } } }