List of usage examples for java.lang Double MIN_VALUE
double MIN_VALUE
To view the source code for java.lang Double MIN_VALUE.
Click Source Link
From source file:ro.nextreports.engine.chart.JFreeChartExporter.java
private JFreeChart createBubbleChart() throws QueryException { bubbleDataset = new DefaultXYZDataset(); // x, y are inverted for jfree bubble chart! // that's why we use minX & maxX values to compute Tu (tickUnit) String chartTitle = replaceParameters(chart.getTitle().getTitle()); chartTitle = StringUtil.getI18nString(chartTitle, I18nUtil.getLanguageByName(chart, language)); String xLegend = StringUtil.getI18nString(replaceParameters(chart.getYLegend().getTitle()), I18nUtil.getLanguageByName(chart, language)); String yLegend = StringUtil.getI18nString(replaceParameters(chart.getXLegend().getTitle()), I18nUtil.getLanguageByName(chart, language)); JFreeChart jfreechart = ChartFactory.createBubbleChart(chartTitle, xLegend, // x-axis Label yLegend, // y-axis Label bubbleDataset, PlotOrientation.HORIZONTAL, true, true, false); // hide border jfreechart.setBorderVisible(false);/*from w w w . j a va 2s. c om*/ // title setTitle(jfreechart); boolean showValues = (chart.getShowYValuesOnChart() == null) ? false : chart.getShowYValuesOnChart(); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setForegroundAlpha(transparency); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); DecimalFormat decimalformat; DecimalFormat percentageFormat; if (chart.getYTooltipPattern() == null) { decimalformat = new DecimalFormat("#"); percentageFormat = new DecimalFormat("0.00%"); } else { decimalformat = new DecimalFormat(chart.getYTooltipPattern()); percentageFormat = decimalformat; } if (showValues) { // increase a little bit the range axis to view all item label values over bars xyplot.getRangeAxis().setUpperMargin(0.2); } // grid axis visibility & colors if ((chart.getXShowGrid() != null) && !chart.getXShowGrid()) { xyplot.setDomainGridlinesVisible(false); } else { if (chart.getXGridColor() != null) { xyplot.setDomainGridlinePaint(chart.getXGridColor()); } else { xyplot.setDomainGridlinePaint(Color.BLACK); } } if ((chart.getYShowGrid() != null) && !chart.getYShowGrid()) { xyplot.setRangeGridlinesVisible(false); } else { if (chart.getYGridColor() != null) { xyplot.setRangeGridlinePaint(chart.getYGridColor()); } else { xyplot.setRangeGridlinePaint(Color.BLACK); } } // chart background xyplot.setBackgroundPaint(chart.getBackground()); // labels color xyplot.getDomainAxis().setTickLabelPaint(chart.getXColor()); xyplot.getRangeAxis().setTickLabelPaint(chart.getYColor()); // legend color xyplot.getDomainAxis().setLabelPaint(chart.getXLegend().getColor()); xyplot.getRangeAxis().setLabelPaint(chart.getYLegend().getColor()); // legend font xyplot.getDomainAxis().setLabelFont(chart.getXLegend().getFont()); xyplot.getRangeAxis().setLabelFont(chart.getYLegend().getFont()); // axis color xyplot.getDomainAxis().setAxisLinePaint(chart.getxAxisColor()); xyplot.getRangeAxis().setAxisLinePaint(chart.getyAxisColor()); // hide labels if ((chart.getXShowLabel() != null) && !chart.getXShowLabel()) { xyplot.getDomainAxis().setTickLabelsVisible(false); xyplot.getDomainAxis().setTickMarksVisible(false); } if ((chart.getYShowLabel() != null) && !chart.getYShowLabel()) { xyplot.getRangeAxis().setTickLabelsVisible(false); xyplot.getRangeAxis().setTickMarksVisible(false); } // label orientation ValueAxis domainAxis = xyplot.getDomainAxis(); if (chart.getXorientation() == Chart.VERTICAL) { domainAxis.setLabelAngle(Math.PI / 2); } else if (chart.getXorientation() == Chart.DIAGONAL) { domainAxis.setLabelAngle(Math.PI / 4); } else if (chart.getXorientation() == Chart.HALF_DIAGONAL) { domainAxis.setLabelAngle(Math.PI / 8); } // labels fonts xyplot.getDomainAxis().setTickLabelFont(chart.getXLabelFont()); xyplot.getRangeAxis().setTickLabelFont(chart.getYLabelFont()); createChart(xyplot.getRangeAxis(), new Object[4]); double minX = Double.MAX_VALUE; double maxX = Double.MIN_VALUE; double minY = Double.MAX_VALUE; double maxY = Double.MIN_VALUE; double maxZ = Double.MIN_VALUE; for (String serie : bubbleData.keySet()) { XYZList xyzList = bubbleData.get(serie); List<Number> yList = xyzList.getyList(); for (Number n : yList) { minY = Math.min(minY, n.doubleValue()); maxY = Math.max(maxY, n.doubleValue()); } List<Number> xList = xyzList.getxList(); for (Number n : xList) { minX = Math.min(minX, n.doubleValue()); maxX = Math.max(maxX, n.doubleValue()); } List<Number> zList = xyzList.getzList(); for (Number n : zList) { maxZ = Math.max(maxZ, n.doubleValue()); } } double tu = Math.floor((maxX - minX) / 5 + 0.5d); NumberTickUnit rUnit = new NumberTickUnit(tu); ((NumberAxis) xyplot.getRangeAxis()).setTickUnit(rUnit); // make the bubble with text fit on X axis (which is shown vertically!) xyplot.getDomainAxis().setUpperMargin(0.2); xyplot.getDomainAxis().setLowerMargin(0.2); for (String serie : bubbleData.keySet()) { XYZList xyzList = bubbleData.get(serie); double[][] data = { getDoubleArray(xyzList.getyList()), getDoubleArray(xyzList.getxList()), getZDoubleArray(xyzList.getzList(), tu, maxZ) }; bubbleDataset.addSeries(serie, data); } int series = bubbleData.keySet().size(); for (int i = 0; i < series; i++) { xyitemrenderer.setSeriesPaint(i, chart.getForegrounds().get(i)); if (showValues) { xyitemrenderer.setSeriesItemLabelsVisible(i, true); xyitemrenderer.setSeriesItemLabelGenerator(i, new StandardXYItemLabelGenerator("{2}", decimalformat, percentageFormat)); } } // show labels on bubbles xyitemrenderer.setBaseItemLabelsVisible(true); xyitemrenderer.setBaseItemLabelGenerator(new LegendXYItemLabelGenerator()); return jfreechart; }
From source file:com.zimbra.perf.chart.ChartUtil.java
private List<JFreeChart> createJFReeChart(ChartSettings cs) { double minValue = Double.MAX_VALUE; double maxValue = Double.MIN_VALUE; double d = 0; double count = 0; double total = 0; TimeSeriesCollection data = new TimeSeriesCollection(); ArrayList<ChartSettings> syntheticSettings = new ArrayList<ChartSettings>(); for (GroupPlotSettings gps : cs.getGroupPlots()) { String groupBy = gps.getGroupBy(); DataColumn dc = new DataColumn(gps.getInfile(), groupBy); StringSeries groupBySeries = mStringSeries.get(dc); dc = new DataColumn(gps.getInfile(), gps.getDataColumn()); DataSeries ds = mDataSeries.get(dc); int idx = 0; Map<String, List<Integer>> groups = new HashMap<String, List<Integer>>(); for (StringEntry e : groupBySeries.dataCollection) { String g = e.getVal(); List<Integer> indices = groups.get(g); if (indices == null) { indices = new ArrayList<Integer>(); groups.put(g, indices);// ww w .j a v a 2 s . c o m } indices.add(idx); idx++; } for (Map.Entry<String, List<Integer>> g : groups.entrySet()) { String groupByValue = g.getKey(); if (gps.getIgnoreSet().contains(groupByValue)) continue; List<Integer> indices = g.getValue(); DataSeries syntheticDS = new DataSeries(); DataColumn c = new DataColumn(gps.getInfile(), GROUP_PLOT_SYNTHETIC + groupByValue + ":" + gps.getDataColumn()); for (int i : indices) { Entry e = ds.get(i); syntheticDS.AddEntry(e.getTimestamp(), e.getVal()); } mDataSeries.put(c, syntheticDS); PlotSettings syntheticPlot = new PlotSettings(groupByValue, c.getInfile(), c.getColumn(), gps.getShowRaw(), gps.getShowMovingAvg(), gps.getMovingAvgPoints(), gps.getMultiplier(), gps.getDivisor(), gps.getNonNegative(), gps.getPercentTime(), gps.getDataFunction(), gps.getAggregateFunction(), gps.getOptional(), null, null); cs.addPlot(syntheticPlot); if (cs.getOutDocument() != null) { ChartSettings s = new ChartSettings(String.format(cs.getTitle(), groupByValue), cs.getCategory(), String.format(cs.getOutfile(), groupByValue), cs.getXAxis(), cs.getYAxis(), cs.getAllowLogScale(), cs.getPlotZero(), cs.getWidth(), cs.getHeight(), null, cs.getTopPlots(), cs.getTopPlotsType()); s.addPlot(syntheticPlot); syntheticSettings.add(s); } } } if (cs.getOutDocument() != null && cs.getGroupPlots().size() != 0) { ArrayList<JFreeChart> charts = new ArrayList<JFreeChart>(); for (ChartSettings c : syntheticSettings) { charts.addAll(createJFReeChart(c)); c.setOutDocument(cs.getOutDocument()); } mSyntheticChartSettings.addAll(syntheticSettings); return charts; } List<PlotSettings> plots = cs.getPlots(); if (cs.getTopPlots() > 0 && plots.size() > cs.getTopPlots()) { String aggregateFunction = cs.getTopPlotsType().name().toLowerCase(); System.out.println(String.format("Reducing %d to %d plots for chart '%s'", plots.size(), cs.getTopPlots(), cs.getTitle())); ArrayList<PlotAggregatePair> aggregates = new ArrayList<PlotAggregatePair>(); for (PlotSettings ps : plots) { DataColumn dc = new DataColumn(ps.getInfile(), ps.getDataColumn()); String key = ps.getInfile() + ":" + ps.getDataColumn() + ":" + ps.getAggregateFunction(); PlotDataIterator pdIter = new PlotDataIterator(ps, mDataSeries.get(dc)); double aggregate = mAggregator.compute(pdIter, aggregateFunction, mAggregateStartAt, mAggregateEndAt, key); aggregates.add(new PlotAggregatePair(ps, aggregate)); } Collections.sort(aggregates); while (aggregates.size() > cs.getTopPlots()) { PlotAggregatePair pair = aggregates.remove(0); plots.remove(pair.ps); } } for (PlotSettings ps : plots) { String columnName = ps.getDataColumn(); if (columnName == null) { columnName = RATIO_PLOT_SYNTHETIC + ps.getRatioTop() + "/" + ps.getRatioBottom(); String infile = ps.getInfile(); String[] top = ps.getRatioTop().split("\\+"); String[] bottom = ps.getRatioBottom().split("\\+"); DataColumn[] ratioTop = new DataColumn[top.length]; DataColumn[] ratioBottom = new DataColumn[bottom.length]; for (int i = 0, j = top.length; i < j; i++) ratioTop[i] = new DataColumn(infile, top[i]); for (int i = 0, j = bottom.length; i < j; i++) ratioBottom[i] = new DataColumn(infile, bottom[i]); DataSeries[] topData = new DataSeries[ratioTop.length]; DataSeries[] bottomData = new DataSeries[ratioBottom.length]; for (int i = 0, j = ratioTop.length; i < j; i++) topData[i] = mDataSeries.get(ratioTop[i]); for (int i = 0, j = ratioBottom.length; i < j; i++) bottomData[i] = mDataSeries.get(ratioBottom[i]); DataSeries ds = new DataSeries(); for (int i = 0, j = topData[0].size(); i < j; i++) { double topValue = 0.0; double bottomValue = 0.0; double ratio = 0.0; Entry lastEntry = null; for (int m = 0, n = topData.length; m < n; m++) { Entry e = topData[m].get(i); topValue += e.getVal(); } for (int m = 0, n = bottomData.length; m < n; m++) { Entry e = bottomData[m].get(i); bottomValue += e.getVal(); lastEntry = e; } if (bottomValue != 0.0) { ratio = topValue / bottomValue; } // should never be null assert lastEntry != null; ds.AddEntry(lastEntry.getTimestamp(), ratio); } mDataSeries.put(new DataColumn(infile, columnName), ds); ps.setDataColumn(columnName); } DataColumn dc = new DataColumn(ps.getInfile(), ps.getDataColumn()); DataSeries ds = mDataSeries.get(dc); TimeSeries ts = new TimeSeries(ps.getLegend(), FixedMillisecond.class); int numSamples = 0; for (PlotDataIterator pdIter = new PlotDataIterator(ps, ds); pdIter.hasNext(); numSamples++) { Pair<Date, Double> entry = pdIter.next(); Date tstamp = entry.getFirst(); double val = entry.getSecond().doubleValue(); if (val != 0 || cs.getPlotZero()) { if (d < minValue) minValue = val; if (d > maxValue) maxValue = val; count++; total += val; try { ts.addOrUpdate(new FixedMillisecond(tstamp), val); } catch (SeriesException e) { e.printStackTrace(System.out); } } } if (numSamples == 0 && ps.getOptional()) { System.out.format("Skipping optional plot %s (no data sample found)\n\n", ps.getLegend()); continue; } System.out.format("Adding %d %s points to %s.\n\n", ds.size(), ps.getLegend(), cs.getOutfile()); if (ps.getShowRaw()) { data.addSeries(ts); } if (ps.getShowMovingAvg()) { int numPoints = ps.getMovingAvgPoints(); if (numPoints == PlotSettings.DEFAULT_PLOT_MOVING_AVG_POINTS) { // Display 200 points for moving average. // Divide the total number of points by 200 to // determine the number of samples to average // for each point. numPoints = ts.getItemCount() / 200; } if (numPoints >= 2) { TimeSeries ma = MovingAverage.createPointMovingAverage(ts, ps.getLegend() + " (moving avg)", numPoints); data.addSeries(ma); } else { System.out.println("Not enough data to display moving average for " + ps.getLegend()); data.addSeries(ts); } } } // Create chart boolean legend = (data.getSeriesCount() > 1); JFreeChart chart = ChartFactory.createTimeSeriesChart(null, cs.getXAxis(), cs.getYAxis(), data, legend, false, false); // Make Y-axis logarithmic if a spike was detected if (cs.getAllowLogScale() && (minValue > 0) && (maxValue > 0) && (maxValue > 20 * (total / count))) { if (maxValue / minValue > 100) { XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis oldAxis = plot.getRangeAxis(); LogarithmicAxis newAxis = new LogarithmicAxis(oldAxis.getLabel()); plot.setRangeAxis(newAxis); } } mChartMap.put(cs, chart); return Arrays.asList(chart); }
From source file:br.fapesp.myutils.MyUtils.java
public static double getMax(double[] vec) { double max = Double.MIN_VALUE; for (int i = 0; i < vec.length; i++) if (vec[i] > max) max = vec[i];//from w w w .j av a 2s . co m return max; }
From source file:com.juanhg.angularmdisk.AngularMDiskApplet.java
private void autogeneratedCode() { JPanel panel_control = new JPanel(); panel_control.setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.RAISED, null, null), new BevelBorder(BevelBorder.RAISED, null, null, null, null))); JPanel panelInputs = new JPanel(); panelInputs.setToolTipText(""); panelInputs.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0))); JPanel panelTiempo = new JPanel(); panelTiempo.setToolTipText(""); panelTiempo.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0))); btnPhase1 = new JButton("Lanzar Insecto"); btnPhase1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { btnPhase1Event();// w w w .jav a2s. c o m } }); btnPhase1.setEnabled(false); JPanel panelOutputs = new JPanel(); panelOutputs.setToolTipText(""); panelOutputs.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0))); JPanel panelTitleOutputs = new JPanel(); panelTitleOutputs.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null)); JLabel labelOutputData = new JLabel("Datos de la Simulaci\u00F3n"); labelOutputData.setFont(new Font("Tahoma", Font.PLAIN, 14)); panelTitleOutputs.add(labelOutputData); lblDiskW = new JLabel("Velocidad Disco:"); lblDiskW.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblDiskWValue = new JLabel(); lblDiskWValue.setText("0"); lblDiskWValue.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblCriticRadius = new JLabel("Radio Cr\u00EDtico:"); lblCriticRadius.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblCriticRadiusValue = new JLabel(); lblCriticRadiusValue.setText("0"); lblCriticRadiusValue.setFont(new Font("Tahoma", Font.PLAIN, 14)); GroupLayout gl_panelOutputs = new GroupLayout(panelOutputs); gl_panelOutputs.setHorizontalGroup(gl_panelOutputs.createParallelGroup(Alignment.LEADING) .addComponent(panelTitleOutputs, GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE) .addGroup(gl_panelOutputs.createSequentialGroup().addContainerGap() .addGroup(gl_panelOutputs.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelOutputs.createSequentialGroup() .addComponent(lblCriticRadius, GroupLayout.PREFERRED_SIZE, 119, GroupLayout.PREFERRED_SIZE) .addGap(6)) .addGroup(gl_panelOutputs.createSequentialGroup() .addComponent(lblDiskW, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(26))) .addGroup(gl_panelOutputs.createParallelGroup(Alignment.LEADING) .addComponent(lblDiskWValue, GroupLayout.PREFERRED_SIZE, 147, GroupLayout.PREFERRED_SIZE) .addComponent(lblCriticRadiusValue, GroupLayout.PREFERRED_SIZE, 147, GroupLayout.PREFERRED_SIZE)) .addContainerGap(112, Short.MAX_VALUE))); gl_panelOutputs .setVerticalGroup(gl_panelOutputs.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelOutputs.createSequentialGroup() .addComponent(panelTitleOutputs, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(gl_panelOutputs.createParallelGroup(Alignment.BASELINE) .addComponent(lblDiskW).addComponent(lblDiskWValue)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(gl_panelOutputs.createParallelGroup(Alignment.BASELINE) .addComponent(lblCriticRadius, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) .addComponent(lblCriticRadiusValue, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)) .addGap(121))); panelOutputs.setLayout(gl_panelOutputs); panel_1 = new JPanel(); panel_1.setBorder(new LineBorder(new Color(0, 0, 0))); GroupLayout gl_panel_control = new GroupLayout(panel_control); gl_panel_control.setHorizontalGroup(gl_panel_control.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_control.createSequentialGroup().addContainerGap().addGroup(gl_panel_control .createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_control.createSequentialGroup() .addGroup(gl_panel_control.createParallelGroup(Alignment.TRAILING) .addComponent(panelInputs, GroupLayout.PREFERRED_SIZE, 396, GroupLayout.PREFERRED_SIZE) .addComponent(panelOutputs, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE) .addComponent(panelTiempo, GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)) .addGap(18)) .addGroup(gl_panel_control.createSequentialGroup() .addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 397, GroupLayout.PREFERRED_SIZE) .addContainerGap(17, Short.MAX_VALUE))))); gl_panel_control.setVerticalGroup(gl_panel_control.createParallelGroup(Alignment.LEADING) .addGroup(gl_panel_control.createSequentialGroup().addContainerGap() .addComponent(panelInputs, GroupLayout.PREFERRED_SIZE, 202, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(panelOutputs, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(panelTiempo, GroupLayout.PREFERRED_SIZE, 210, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED, 15, Short.MAX_VALUE).addComponent(panel_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addContainerGap())); JLabel lblNewLabel = new JLabel("GNU GENERAL PUBLIC LICENSE"); panel_1.add(lblNewLabel); rdbtnCam1 = new JRadioButton("C\u00E1mara Fija"); rdbtnCam1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { rdbtnCam1Event(); } }); rdbtnCam1.setSelected(true); rdbtnCam2 = new JRadioButton("C\u00E1mara M\u00F3vil"); rdbtnCam2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { rdbtnCam2Event(); } }); btnLaunchSimulation = new JButton("Iniciar"); btnLaunchSimulation.setFont(new Font("Tahoma", Font.PLAIN, 16)); btnLaunchSimulation.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { btnLaunchSimulationEvent(event); } }); btnPauseContinue = new JButton("Pausar"); btnPauseContinue.setFont(new Font("Tahoma", Font.PLAIN, 16)); btnPauseContinue.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { btnPauseContinueEvent(event); } }); panel = new JPanel(); panel.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null)); label = new JLabel("Datos de la Simulaci\u00F3n"); label.setFont(new Font("Tahoma", Font.PLAIN, 14)); panel.add(label); GroupLayout gl_panelTiempo = new GroupLayout(panelTiempo); gl_panelTiempo.setHorizontalGroup(gl_panelTiempo.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelTiempo.createSequentialGroup().addContainerGap() .addGroup(gl_panelTiempo.createParallelGroup(Alignment.LEADING, false) .addComponent(btnPhase1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnLaunchSimulation, GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)) .addGroup(gl_panelTiempo.createParallelGroup(Alignment.LEADING).addGroup(gl_panelTiempo .createSequentialGroup().addGap(52) .addGroup(gl_panelTiempo.createParallelGroup(Alignment.LEADING) .addComponent(rdbtnCam2).addComponent(rdbtnCam1, GroupLayout.PREFERRED_SIZE, 113, GroupLayout.PREFERRED_SIZE))) .addGroup(gl_panelTiempo.createSequentialGroup().addGap(21).addComponent( btnPauseContinue, GroupLayout.PREFERRED_SIZE, 168, GroupLayout.PREFERRED_SIZE))) .addContainerGap(47, Short.MAX_VALUE)) .addComponent(panel, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE)); gl_panelTiempo.setVerticalGroup(gl_panelTiempo.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelTiempo.createSequentialGroup() .addComponent(panel, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE).addGap(22) .addGroup(gl_panelTiempo.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelTiempo.createSequentialGroup().addComponent(rdbtnCam1) .addPreferredGap(ComponentPlacement.RELATED).addComponent(rdbtnCam2)) .addComponent(btnPhase1, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)) .addGap(18) .addGroup(gl_panelTiempo.createParallelGroup(Alignment.LEADING) .addComponent(btnPauseContinue, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE) .addComponent(btnLaunchSimulation, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE)))); panelTiempo.setLayout(gl_panelTiempo); JLabel LabelBugMass = new JLabel("Masa del Insecto"); LabelBugMass.setFont(new Font("Tahoma", Font.PLAIN, 14)); JLabel labelFallRadio = new JLabel("Radio de Ca\u00EDda"); labelFallRadio.setFont(new Font("Tahoma", Font.PLAIN, 14)); JLabel labelBugVelocity = new JLabel("Velocidad del Insecto"); labelBugVelocity.setFont(new Font("Tahoma", Font.PLAIN, 14)); JLabel labelDiskVelocity = new JLabel("Velocidad del Disco"); labelDiskVelocity.setFont(new Font("Tahoma", Font.PLAIN, 14)); JPanel panelTitle = new JPanel(); panelTitle.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null)); lblFallRadiusValue = new JLabel("10"); lblFallRadiusValue.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblBugVelocityValue = new JLabel("1"); lblBugVelocityValue.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblVelocityValue = new JLabel("0.5"); lblVelocityValue.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblInitMassValue = new JLabel("30"); lblInitMassValue.setFont(new Font("Tahoma", Font.PLAIN, 14)); sliderBugInitMass = new JSlider(); sliderBugInitMass.setValue(30); sliderBugInitMass.setMinimum(20); sliderBugInitMass.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent event) { sliderBugInitMassEvent(); } }); sliderBugInitMass.setMaximum(70); sliderFallRadius = new JSlider(); sliderFallRadius.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { sliderFallRadiusEvent(); } }); sliderFallRadius.setValue(10); sliderFallRadius.setMinorTickSpacing(1); sliderFallRadius.setMaximum(20); sliderBugVelocity = new JSlider(); sliderBugVelocity.setValue(10); sliderBugVelocity.setMaximum(20); sliderBugVelocity.setMinimum(5); sliderBugVelocity.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { sliderBugVelocityEvent(); } }); sliderBugVelocity.setMinorTickSpacing(1); sliderDiskVelocity = new JSlider(); sliderDiskVelocity.setMaximum(10); sliderDiskVelocity.setMinimum(1); sliderDiskVelocity.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { sliderDiskVelocityEvent(); } }); sliderDiskVelocity.setValue(5); sliderDiskVelocity.setMinorTickSpacing(1); JLabel lblCoeficienteDeRozamiento = new JLabel("Coef de Rozamiento"); lblCoeficienteDeRozamiento.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblFrictionValue = new JLabel("0.25"); lblFrictionValue.setFont(new Font("Tahoma", Font.PLAIN, 14)); sliderFriction = new JSlider(); sliderFriction.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { sliderFrictionEvent(); } }); sliderFriction.setValue(25); sliderFriction.setMinorTickSpacing(1); sliderFriction.setMinimum(1); sliderFriction.setMaximum(90); GroupLayout gl_panelInputs = new GroupLayout(panelInputs); gl_panelInputs.setHorizontalGroup(gl_panelInputs.createParallelGroup(Alignment.TRAILING) .addGroup(gl_panelInputs.createSequentialGroup().addContainerGap() .addGroup(gl_panelInputs.createParallelGroup(Alignment.TRAILING, false) .addComponent(labelBugVelocity, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(LabelBugMass, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(labelFallRadio, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)) .addGap(18) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addComponent(lblInitMassValue, GroupLayout.PREFERRED_SIZE, 42, GroupLayout.PREFERRED_SIZE) .addComponent(lblFallRadiusValue, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE) .addComponent(lblBugVelocityValue, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE)) .addGap(18) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addComponent(sliderFallRadius, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE) .addComponent(sliderBugInitMass, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE) .addComponent(sliderBugVelocity, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE) .addComponent(sliderDiskVelocity, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE)) .addGap(26)) .addGroup(gl_panelInputs.createSequentialGroup().addContainerGap() .addGroup(gl_panelInputs.createParallelGroup(Alignment.TRAILING) .addComponent(lblCoeficienteDeRozamiento, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE) .addComponent(labelDiskVelocity, GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING, false) .addGroup(Alignment.TRAILING, gl_panelInputs.createSequentialGroup() .addComponent(lblVelocityValue, GroupLayout.PREFERRED_SIZE, 43, GroupLayout.PREFERRED_SIZE) .addGap(204)) .addGroup(Alignment.TRAILING, gl_panelInputs.createSequentialGroup() .addComponent(lblFrictionValue, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(sliderFriction, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE) .addGap(26)))) .addComponent(panelTitle, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)); gl_panelInputs.setVerticalGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelInputs.createSequentialGroup() .addComponent(panelTitle, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGap(8) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelInputs.createParallelGroup(Alignment.BASELINE) .addComponent(LabelBugMass).addComponent(lblInitMassValue, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)) .addComponent(sliderBugInitMass, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelInputs.createParallelGroup(Alignment.BASELINE) .addComponent(labelFallRadio).addComponent(lblFallRadiusValue, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)) .addComponent(sliderFallRadius, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGap(11) .addGroup( gl_panelInputs.createParallelGroup(Alignment.LEADING).addComponent(labelBugVelocity) .addComponent(lblBugVelocityValue, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) .addComponent(sliderBugVelocity, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelInputs.createParallelGroup(Alignment.BASELINE) .addComponent(labelDiskVelocity).addComponent(lblVelocityValue, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)) .addComponent(sliderDiskVelocity, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) .addGroup(gl_panelInputs.createParallelGroup(Alignment.LEADING) .addGroup(gl_panelInputs.createSequentialGroup().addGap(12) .addGroup(gl_panelInputs.createParallelGroup(Alignment.BASELINE) .addComponent(lblCoeficienteDeRozamiento, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE) .addComponent(lblFrictionValue, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE))) .addGroup(gl_panelInputs.createSequentialGroup() .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(sliderFriction, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) .addGap(47))); JLabel lblDatosDeEntrada = new JLabel("Datos de Entrada"); lblDatosDeEntrada.setFont(new Font("Tahoma", Font.PLAIN, 14)); panelTitle.add(lblDatosDeEntrada); panelInputs.setLayout(gl_panelInputs); panel_control.setLayout(gl_panel_control); JPanel panel_visualizar = new JPanel(); GroupLayout groupLayout = new GroupLayout(getContentPane()); groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup().addContainerGap() .addComponent(panel_control, GroupLayout.PREFERRED_SIZE, 432, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(panel_visualizar, GroupLayout.PREFERRED_SIZE, 560, GroupLayout.PREFERRED_SIZE) .addContainerGap(32, Short.MAX_VALUE))); groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.TRAILING) .addGroup(groupLayout.createSequentialGroup().addContainerGap() .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING) .addComponent(panel_visualizar, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 598, Short.MAX_VALUE) .addComponent(panel_control, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 598, Short.MAX_VALUE)) .addContainerGap())); GridBagLayout gbl_panel_visualizar = new GridBagLayout(); gbl_panel_visualizar.columnWidths = new int[] { 0, 0 }; gbl_panel_visualizar.rowHeights = new int[] { 0, 0, 0 }; gbl_panel_visualizar.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; gbl_panel_visualizar.rowWeights = new double[] { 1.0, 1.0, Double.MIN_VALUE }; panel_visualizar.setLayout(gbl_panel_visualizar); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); GridBagConstraints gbc_tabbedPane = new GridBagConstraints(); gbc_tabbedPane.gridheight = 2; gbc_tabbedPane.fill = GridBagConstraints.BOTH; gbc_tabbedPane.gridx = 0; gbc_tabbedPane.gridy = 0; panel_visualizar.add(tabbedPane, gbc_tabbedPane); panelSimulation = new JPanelGrafica(); tabbedPane.addTab("Simulacin", null, panelSimulation, null); panelSimulation.setBackground(Color.WHITE); getContentPane().setLayout(groupLayout); }
From source file:ro.nextreports.engine.chart.JFreeChartExporter.java
private HashMap<String, String> createChart(List<String> yColumns, ValueAxis rangeAxis, Object[] charts) throws QueryException { int row = 0;/* ww w .j a v a 2s . c om*/ Object previous = null; String xColumn = chart.getXColumn(); String xPattern = chart.getXPattern(); String lastXValue = ""; HashMap<String, String> formatValues = new HashMap<String, String>(); Number min = Double.MAX_VALUE; Number max = Double.MIN_VALUE; int chartsNo = charts.length; int[] index = new int[chartsNo]; GFunction[] functions = new GFunction[chartsNo]; for (int i = 0; i < chartsNo; i++) { functions[i] = FunctionFactory.getFunction(chart.getYFunction()); index[i] = 1; } boolean isStacked = chart.getType().isStacked(); while (result.hasNext()) { Object[] objects = new Object[chartsNo]; Number[] computedValues = new Number[chartsNo]; String currentCategory = null; for (int i = 0; i < chartsNo; i++) { if (yColumns.get(i) != null) { objects[i] = result.nextValue(yColumns.get(i)); Number value = null; String sv = null; if (objects[i] instanceof Number) { value = (Number) objects[i]; } else if (objects[i] != null) { if (ChartType.BUBBLE == chart.getType().getType()) { sv = (String) objects[i]; } value = 1; integerXValue = false; } else { value = 0; } computedValues[i] = value; if (sv != null) { currentCategory = sv; } } } Object xValue = null; if (row == 0) { xValue = result.nextValue(xColumn); lastXObjValue = xValue; lastXValue = getStringValue(xColumn, xPattern); } else { xValue = previous; } Object newXValue = result.nextValue(xColumn); boolean add = false; int position = 0; // no function : add the value if (AbstractGFunction.NOOP.equals(functions[0].getName())) { lastXValue = getStringValue(xColumn, xPattern); add = true; // compute function } else { boolean equals = FunctionUtil.parameterEquals(xValue, newXValue); if (equals) { for (int i = 0; i < chartsNo; i++) { functions[i].compute(objects[i]); } } else { for (int i = 0; i < chartsNo; i++) { position = i; add = true; computedValues[i] = (Number) functions[i].getComputedValue(); functions[i].reset(); functions[i].compute(objects[i]); } } } if (add) { Number n; Number sum = 0; if (xValue instanceof Number) { n = (Number) newXValue; } else { integerXValue = false; n = index[position]++; } if (chart.getType().isBubble()) { XYZList xyzList = bubbleData.get(currentCategory); if (xyzList == null) { xyzList = new XYZList(); bubbleData.put(currentCategory, xyzList); } xyzList.getxList().add(computedValues[0]); xyzList.getyList().add(computedValues[1]); xyzList.getzList().add(computedValues[2]); min = Math.min(min.doubleValue(), computedValues[0].doubleValue()); max = Math.max(max.doubleValue(), computedValues[0].doubleValue()); } else { for (int i = 0; i < chartsNo; i++) { addValue(charts[i], n, lastXValue, computedValues[i], formatValues); if (!isStacked) { min = Math.min(min.doubleValue(), computedValues[i].doubleValue()); max = Math.max(max.doubleValue(), computedValues[i].doubleValue()); } else { sum = sum.doubleValue() + computedValues[i].doubleValue(); } } } if (isStacked) { min = 0; max = Math.max(max.doubleValue(), sum.doubleValue()); } lastXValue = getStringValue(xColumn, xPattern); if (ChartType.BUBBLE == chart.getType().getType()) { XYZList xyzList = bubbleData.get(currentCategory); xyzList.getLabels().add(lastXValue); } } row++; previous = newXValue; } // last group if (!AbstractGFunction.NOOP.equals(functions[0].getName())) { Number n; Number sum = 0; if (lastXObjValue instanceof Number) { n = (Number) lastXObjValue; } else { integerXValue = false; n = index[chartsNo - 1]++; } for (int i = 0; i < chartsNo; i++) { Number value = (Number) functions[i].getComputedValue(); addValue(charts[i], n, lastXValue, value, formatValues); if (!isStacked) { min = Math.min(min.doubleValue(), value.doubleValue()); max = Math.max(max.doubleValue(), value.doubleValue()); } else { sum = sum.doubleValue() + value.doubleValue(); } } if (isStacked) { min = 0; max = Math.max(max.doubleValue(), sum.doubleValue()); } } setAxisRange(rangeAxis, min, max); return formatValues; }
From source file:org.fao.geonet.kernel.search.LuceneQueryBuilder.java
public static NumericRangeQuery buildNumericRangeQueryForType(String fieldName, String min, String max, boolean minInclusive, boolean maxInclusive, String type) { NumericRangeQuery rangeQuery;/* www. j av a 2 s.com*/ if ("double".equals(type)) { rangeQuery = NumericRangeQuery.newDoubleRange(fieldName, (min == null ? Double.MIN_VALUE : Double.valueOf(min)), (max == null ? Double.MAX_VALUE : Double.valueOf(max)), true, true); } else if ("float".equals(type)) { rangeQuery = NumericRangeQuery.newFloatRange(fieldName, (min == null ? Float.MIN_VALUE : Float.valueOf(min)), (max == null ? Float.MAX_VALUE : Float.valueOf(max)), true, true); } else if ("long".equals(type)) { rangeQuery = NumericRangeQuery.newLongRange(fieldName, (min == null ? Long.MIN_VALUE : Long.valueOf(min)), (max == null ? Long.MAX_VALUE : Long.valueOf(max)), true, true); } else { rangeQuery = NumericRangeQuery.newIntRange(fieldName, (min == null ? Integer.MIN_VALUE : Integer.valueOf(min)), (max == null ? Integer.MAX_VALUE : Integer.valueOf(max)), true, true); } return rangeQuery; }
From source file:org.broadinstitute.gatk.utils.MathUtilsUnitTest.java
@Test public void testDirichletMultinomial() { List<double[]> testAlleles = Arrays.asList(new double[] { 80, 240 }, new double[] { 1, 10000 }, new double[] { 0, 500 }, new double[] { 5140, 20480 }, new double[] { 5000, 800, 200 }, new double[] { 6, 3, 1000 }, new double[] { 100, 400, 300, 800 }, new double[] { 8000, 100, 20, 80, 2 }, new double[] { 90, 20000, 400, 20, 4, 1280, 720, 1 }); Assert.assertTrue(/* ww w. ja va 2 s. co m*/ !Double.isInfinite(MathUtils.log10Gamma(1e-3)) && !Double.isNaN(MathUtils.log10Gamma(1e-3))); int[] numAlleleSampled = new int[] { 2, 5, 10, 20, 25 }; for (double[] alleles : testAlleles) { for (int count : numAlleleSampled) { // test that everything sums to one. Generate all multinomial draws List<Double> likelihoods = new ArrayList<>(100000); NextCounts generator = new NextCounts(alleles.length, count); double maxLog = Double.MIN_VALUE; //List<String> countLog = new ArrayList<String>(200); while (generator.hasNext()) { int[] thisCount = generator.next(); //countLog.add(Arrays.toString(thisCount)); Double likelihood = MathUtils.dirichletMultinomial(addEpsilon(alleles), thisCount); Assert.assertTrue(!Double.isNaN(likelihood) && !Double.isInfinite(likelihood), String.format("Likelihood for counts %s and nAlleles %d was %s", Arrays.toString(thisCount), alleles.length, Double.toString(likelihood))); if (likelihood > maxLog) maxLog = likelihood; likelihoods.add(likelihood); } //System.out.printf("%d likelihoods and max is (probability) %e\n",likelihoods.size(),Math.pow(10,maxLog)); Assert.assertEquals(MathUtils.sumLog10(unwrap(likelihoods)), 1.0, 1e-7, String.format("Counts %d and alleles %d have nLikelihoods %d. \n Counts: %s", count, alleles.length, likelihoods.size(), "NODEBUG"/*,countLog*/)); } } }
From source file:org.apache.rya.indexing.smarturi.duplication.DuplicateDataDetectorIT.java
@Test public void testDoubleProperty() throws SmartUriException { System.out.println("Double Property Test"); final ImmutableList.Builder<TestInput> builder = ImmutableList.builder(); // Tolerance 0.0 Tolerance tolerance = new Tolerance(0.0, ToleranceType.DIFFERENCE); builder.add(new TestInput(Double.MIN_VALUE, tolerance, false)); builder.add(new TestInput(-1.0, tolerance, false)); builder.add(new TestInput(0.0, tolerance, false)); builder.add(new TestInput(0.01, tolerance, false)); builder.add(new TestInput(0.02, tolerance, false)); builder.add(new TestInput(0.1, tolerance, false)); builder.add(new TestInput(0.2, tolerance, false)); builder.add(new TestInput(1.0, tolerance, false)); builder.add(new TestInput(71, tolerance, false)); builder.add(new TestInput(72, tolerance, false)); builder.add(new TestInput(72.4, tolerance, false)); builder.add(new TestInput(72.47, tolerance, false)); builder.add(new TestInput(72.48, tolerance, false)); builder.add(new TestInput(72.49, tolerance, false)); builder.add(new TestInput(72.5, tolerance, true)); // Equals value builder.add(new TestInput(72.51, tolerance, false)); builder.add(new TestInput(72.52, tolerance, false)); builder.add(new TestInput(72.53, tolerance, false)); builder.add(new TestInput(72.6, tolerance, false)); builder.add(new TestInput(73, tolerance, false)); builder.add(new TestInput(74, tolerance, false)); builder.add(new TestInput(100, tolerance, false)); builder.add(new TestInput(Double.MAX_VALUE, tolerance, false)); // Tolerance 0.01 tolerance = new Tolerance(0.01, ToleranceType.DIFFERENCE); builder.add(new TestInput(Double.MIN_VALUE, tolerance, false)); builder.add(new TestInput(-1.0, tolerance, false)); builder.add(new TestInput(0.0, tolerance, false)); builder.add(new TestInput(0.01, tolerance, false)); builder.add(new TestInput(0.02, tolerance, false)); builder.add(new TestInput(0.1, tolerance, false)); builder.add(new TestInput(0.2, tolerance, false)); builder.add(new TestInput(1.0, tolerance, false)); builder.add(new TestInput(71, tolerance, false)); builder.add(new TestInput(72, tolerance, false)); builder.add(new TestInput(72.4, tolerance, false)); builder.add(new TestInput(72.47, tolerance, false)); builder.add(new TestInput(72.48, tolerance, false)); builder.add(new TestInput(72.49, tolerance, true)); builder.add(new TestInput(72.5, tolerance, true)); // Equals value builder.add(new TestInput(72.51, tolerance, true)); builder.add(new TestInput(72.52, tolerance, false)); builder.add(new TestInput(72.53, tolerance, false)); builder.add(new TestInput(72.6, tolerance, false)); builder.add(new TestInput(73, tolerance, false)); builder.add(new TestInput(74, tolerance, false)); builder.add(new TestInput(100, tolerance, false)); builder.add(new TestInput(Double.MAX_VALUE, tolerance, false)); // Tolerance 0.02 tolerance = new Tolerance(0.02, ToleranceType.DIFFERENCE); builder.add(new TestInput(Double.MIN_VALUE, tolerance, false)); builder.add(new TestInput(-1.0, tolerance, false)); builder.add(new TestInput(0.0, tolerance, false)); builder.add(new TestInput(0.01, tolerance, false)); builder.add(new TestInput(0.02, tolerance, false)); builder.add(new TestInput(0.1, tolerance, false)); builder.add(new TestInput(0.2, tolerance, false)); builder.add(new TestInput(1.0, tolerance, false)); builder.add(new TestInput(71, tolerance, false)); builder.add(new TestInput(72, tolerance, false)); builder.add(new TestInput(72.4, tolerance, false)); builder.add(new TestInput(72.47, tolerance, false)); builder.add(new TestInput(72.48, tolerance, true)); builder.add(new TestInput(72.49, tolerance, true)); builder.add(new TestInput(72.5, tolerance, true)); // Equals value builder.add(new TestInput(72.51, tolerance, true)); builder.add(new TestInput(72.52, tolerance, true)); builder.add(new TestInput(72.53, tolerance, false)); builder.add(new TestInput(72.6, tolerance, false)); builder.add(new TestInput(73, tolerance, false)); builder.add(new TestInput(74, tolerance, false)); builder.add(new TestInput(100, tolerance, false)); builder.add(new TestInput(Double.MAX_VALUE, tolerance, false)); // Tolerance 0% tolerance = new Tolerance(0.0, ToleranceType.PERCENTAGE); builder.add(new TestInput(Double.MIN_VALUE, tolerance, false)); builder.add(new TestInput(-1.0, tolerance, false)); builder.add(new TestInput(0.0, tolerance, false)); builder.add(new TestInput(0.01, tolerance, false)); builder.add(new TestInput(0.02, tolerance, false)); builder.add(new TestInput(0.1, tolerance, false)); builder.add(new TestInput(0.2, tolerance, false)); builder.add(new TestInput(1.0, tolerance, false)); builder.add(new TestInput(71, tolerance, false)); builder.add(new TestInput(71.774, tolerance, false)); builder.add(new TestInput(71.775, tolerance, false)); builder.add(new TestInput(71.776, tolerance, false)); builder.add(new TestInput(72, tolerance, false)); builder.add(new TestInput(72.4, tolerance, false)); builder.add(new TestInput(72.47, tolerance, false)); builder.add(new TestInput(72.48, tolerance, false)); builder.add(new TestInput(72.49, tolerance, false)); builder.add(new TestInput(72.5, tolerance, true)); // Equals value builder.add(new TestInput(72.51, tolerance, false)); builder.add(new TestInput(72.52, tolerance, false)); builder.add(new TestInput(72.53, tolerance, false)); builder.add(new TestInput(72.6, tolerance, false)); builder.add(new TestInput(73, tolerance, false)); builder.add(new TestInput(73.224, tolerance, false)); builder.add(new TestInput(73.225, tolerance, false)); builder.add(new TestInput(73.226, tolerance, false)); builder.add(new TestInput(73, tolerance, false)); builder.add(new TestInput(74, tolerance, false)); builder.add(new TestInput(100, tolerance, false)); builder.add(new TestInput(Double.MAX_VALUE, tolerance, false)); // Tolerance 1% tolerance = new Tolerance(0.01, ToleranceType.PERCENTAGE); builder.add(new TestInput(Double.MIN_VALUE, tolerance, false)); builder.add(new TestInput(-1.0, tolerance, false)); builder.add(new TestInput(0.0, tolerance, false)); builder.add(new TestInput(0.01, tolerance, false)); builder.add(new TestInput(0.02, tolerance, false)); builder.add(new TestInput(0.1, tolerance, false)); builder.add(new TestInput(0.2, tolerance, false)); builder.add(new TestInput(1.0, tolerance, false)); builder.add(new TestInput(71, tolerance, false)); builder.add(new TestInput(71.774, tolerance, false)); builder.add(new TestInput(71.775, tolerance, true)); builder.add(new TestInput(71.776, tolerance, true)); builder.add(new TestInput(72, tolerance, true)); builder.add(new TestInput(72.4, tolerance, true)); builder.add(new TestInput(72.47, tolerance, true)); builder.add(new TestInput(72.48, tolerance, true)); builder.add(new TestInput(72.49, tolerance, true)); builder.add(new TestInput(72.5, tolerance, true)); // Equals value builder.add(new TestInput(72.51, tolerance, true)); builder.add(new TestInput(72.52, tolerance, true)); builder.add(new TestInput(72.53, tolerance, true)); builder.add(new TestInput(72.6, tolerance, true)); builder.add(new TestInput(73, tolerance, true)); builder.add(new TestInput(73.224, tolerance, true)); builder.add(new TestInput(73.225, tolerance, true)); builder.add(new TestInput(73.226, tolerance, false)); builder.add(new TestInput(74, tolerance, false)); builder.add(new TestInput(100, tolerance, false)); builder.add(new TestInput(Double.MAX_VALUE, tolerance, false)); // Tolerance 100% tolerance = new Tolerance(1.00, ToleranceType.PERCENTAGE); builder.add(new TestInput(Double.MIN_VALUE, tolerance, true)); builder.add(new TestInput(-1.0, tolerance, true)); builder.add(new TestInput(0.0, tolerance, true)); builder.add(new TestInput(0.01, tolerance, true)); builder.add(new TestInput(0.02, tolerance, true)); builder.add(new TestInput(0.1, tolerance, true)); builder.add(new TestInput(0.2, tolerance, true)); builder.add(new TestInput(1.0, tolerance, true)); builder.add(new TestInput(71, tolerance, true)); builder.add(new TestInput(71.774, tolerance, true)); builder.add(new TestInput(71.775, tolerance, true)); builder.add(new TestInput(71.776, tolerance, true)); builder.add(new TestInput(72, tolerance, true)); builder.add(new TestInput(72.4, tolerance, true)); builder.add(new TestInput(72.47, tolerance, true)); builder.add(new TestInput(72.48, tolerance, true)); builder.add(new TestInput(72.49, tolerance, true)); builder.add(new TestInput(72.5, tolerance, true)); // Equals value builder.add(new TestInput(72.51, tolerance, true)); builder.add(new TestInput(72.52, tolerance, true)); builder.add(new TestInput(72.53, tolerance, true)); builder.add(new TestInput(72.6, tolerance, true)); builder.add(new TestInput(73, tolerance, true)); builder.add(new TestInput(73.224, tolerance, true)); builder.add(new TestInput(73.225, tolerance, true)); builder.add(new TestInput(73.226, tolerance, true)); builder.add(new TestInput(74, tolerance, true)); builder.add(new TestInput(100, tolerance, true)); builder.add(new TestInput(Double.MAX_VALUE, tolerance, true)); final ImmutableList<TestInput> testInputs = builder.build(); testProperty(testInputs, PERSON_TYPE_URI, HAS_HEIGHT); }
From source file:org.apache.rya.indexing.smarturi.duplication.DuplicateDataDetectorTest.java
@Test public void testDoubleProperty() throws SmartUriException { System.out.println("Double Property Test"); final ImmutableList.Builder<TestInput> builder = ImmutableList.<TestInput>builder(); // Tolerance 0.0 Tolerance tolerance = new Tolerance(0.0, ToleranceType.DIFFERENCE); builder.add(new TestInput(Double.MIN_VALUE, tolerance, false)); builder.add(new TestInput(-1.0, tolerance, false)); builder.add(new TestInput(0.0, tolerance, false)); builder.add(new TestInput(0.01, tolerance, false)); builder.add(new TestInput(0.02, tolerance, false)); builder.add(new TestInput(0.1, tolerance, false)); builder.add(new TestInput(0.2, tolerance, false)); builder.add(new TestInput(1.0, tolerance, false)); builder.add(new TestInput(71, tolerance, false)); builder.add(new TestInput(72, tolerance, false)); builder.add(new TestInput(72.4, tolerance, false)); builder.add(new TestInput(72.47, tolerance, false)); builder.add(new TestInput(72.48, tolerance, false)); builder.add(new TestInput(72.49, tolerance, false)); builder.add(new TestInput(72.5, tolerance, true)); // Equals value builder.add(new TestInput(72.51, tolerance, false)); builder.add(new TestInput(72.52, tolerance, false)); builder.add(new TestInput(72.53, tolerance, false)); builder.add(new TestInput(72.6, tolerance, false)); builder.add(new TestInput(73, tolerance, false)); builder.add(new TestInput(74, tolerance, false)); builder.add(new TestInput(100, tolerance, false)); builder.add(new TestInput(Double.MAX_VALUE, tolerance, false)); // Tolerance 0.01 tolerance = new Tolerance(0.01, ToleranceType.DIFFERENCE); builder.add(new TestInput(Double.MIN_VALUE, tolerance, false)); builder.add(new TestInput(-1.0, tolerance, false)); builder.add(new TestInput(0.0, tolerance, false)); builder.add(new TestInput(0.01, tolerance, false)); builder.add(new TestInput(0.02, tolerance, false)); builder.add(new TestInput(0.1, tolerance, false)); builder.add(new TestInput(0.2, tolerance, false)); builder.add(new TestInput(1.0, tolerance, false)); builder.add(new TestInput(71, tolerance, false)); builder.add(new TestInput(72, tolerance, false)); builder.add(new TestInput(72.4, tolerance, false)); builder.add(new TestInput(72.47, tolerance, false)); builder.add(new TestInput(72.48, tolerance, false)); builder.add(new TestInput(72.49, tolerance, true)); builder.add(new TestInput(72.5, tolerance, true)); // Equals value builder.add(new TestInput(72.51, tolerance, true)); builder.add(new TestInput(72.52, tolerance, false)); builder.add(new TestInput(72.53, tolerance, false)); builder.add(new TestInput(72.6, tolerance, false)); builder.add(new TestInput(73, tolerance, false)); builder.add(new TestInput(74, tolerance, false)); builder.add(new TestInput(100, tolerance, false)); builder.add(new TestInput(Double.MAX_VALUE, tolerance, false)); // Tolerance 0.02 tolerance = new Tolerance(0.02, ToleranceType.DIFFERENCE); builder.add(new TestInput(Double.MIN_VALUE, tolerance, false)); builder.add(new TestInput(-1.0, tolerance, false)); builder.add(new TestInput(0.0, tolerance, false)); builder.add(new TestInput(0.01, tolerance, false)); builder.add(new TestInput(0.02, tolerance, false)); builder.add(new TestInput(0.1, tolerance, false)); builder.add(new TestInput(0.2, tolerance, false)); builder.add(new TestInput(1.0, tolerance, false)); builder.add(new TestInput(71, tolerance, false)); builder.add(new TestInput(72, tolerance, false)); builder.add(new TestInput(72.4, tolerance, false)); builder.add(new TestInput(72.47, tolerance, false)); builder.add(new TestInput(72.48, tolerance, true)); builder.add(new TestInput(72.49, tolerance, true)); builder.add(new TestInput(72.5, tolerance, true)); // Equals value builder.add(new TestInput(72.51, tolerance, true)); builder.add(new TestInput(72.52, tolerance, true)); builder.add(new TestInput(72.53, tolerance, false)); builder.add(new TestInput(72.6, tolerance, false)); builder.add(new TestInput(73, tolerance, false)); builder.add(new TestInput(74, tolerance, false)); builder.add(new TestInput(100, tolerance, false)); builder.add(new TestInput(Double.MAX_VALUE, tolerance, false)); // Tolerance 0% tolerance = new Tolerance(0.0, ToleranceType.PERCENTAGE); builder.add(new TestInput(Double.MIN_VALUE, tolerance, false)); builder.add(new TestInput(-1.0, tolerance, false)); builder.add(new TestInput(0.0, tolerance, false)); builder.add(new TestInput(0.01, tolerance, false)); builder.add(new TestInput(0.02, tolerance, false)); builder.add(new TestInput(0.1, tolerance, false)); builder.add(new TestInput(0.2, tolerance, false)); builder.add(new TestInput(1.0, tolerance, false)); builder.add(new TestInput(71, tolerance, false)); builder.add(new TestInput(71.774, tolerance, false)); builder.add(new TestInput(71.775, tolerance, false)); builder.add(new TestInput(71.776, tolerance, false)); builder.add(new TestInput(72, tolerance, false)); builder.add(new TestInput(72.4, tolerance, false)); builder.add(new TestInput(72.47, tolerance, false)); builder.add(new TestInput(72.48, tolerance, false)); builder.add(new TestInput(72.49, tolerance, false)); builder.add(new TestInput(72.5, tolerance, true)); // Equals value builder.add(new TestInput(72.51, tolerance, false)); builder.add(new TestInput(72.52, tolerance, false)); builder.add(new TestInput(72.53, tolerance, false)); builder.add(new TestInput(72.6, tolerance, false)); builder.add(new TestInput(73, tolerance, false)); builder.add(new TestInput(73.224, tolerance, false)); builder.add(new TestInput(73.225, tolerance, false)); builder.add(new TestInput(73.226, tolerance, false)); builder.add(new TestInput(73, tolerance, false)); builder.add(new TestInput(74, tolerance, false)); builder.add(new TestInput(100, tolerance, false)); builder.add(new TestInput(Double.MAX_VALUE, tolerance, false)); // Tolerance 1% tolerance = new Tolerance(0.01, ToleranceType.PERCENTAGE); builder.add(new TestInput(Double.MIN_VALUE, tolerance, false)); builder.add(new TestInput(-1.0, tolerance, false)); builder.add(new TestInput(0.0, tolerance, false)); builder.add(new TestInput(0.01, tolerance, false)); builder.add(new TestInput(0.02, tolerance, false)); builder.add(new TestInput(0.1, tolerance, false)); builder.add(new TestInput(0.2, tolerance, false)); builder.add(new TestInput(1.0, tolerance, false)); builder.add(new TestInput(71, tolerance, false)); builder.add(new TestInput(71.774, tolerance, false)); builder.add(new TestInput(71.775, tolerance, true)); builder.add(new TestInput(71.776, tolerance, true)); builder.add(new TestInput(72, tolerance, true)); builder.add(new TestInput(72.4, tolerance, true)); builder.add(new TestInput(72.47, tolerance, true)); builder.add(new TestInput(72.48, tolerance, true)); builder.add(new TestInput(72.49, tolerance, true)); builder.add(new TestInput(72.5, tolerance, true)); // Equals value builder.add(new TestInput(72.51, tolerance, true)); builder.add(new TestInput(72.52, tolerance, true)); builder.add(new TestInput(72.53, tolerance, true)); builder.add(new TestInput(72.6, tolerance, true)); builder.add(new TestInput(73, tolerance, true)); builder.add(new TestInput(73.224, tolerance, true)); builder.add(new TestInput(73.225, tolerance, true)); builder.add(new TestInput(73.226, tolerance, false)); builder.add(new TestInput(74, tolerance, false)); builder.add(new TestInput(100, tolerance, false)); builder.add(new TestInput(Double.MAX_VALUE, tolerance, false)); // Tolerance 100% tolerance = new Tolerance(1.00, ToleranceType.PERCENTAGE); builder.add(new TestInput(Double.MIN_VALUE, tolerance, true)); builder.add(new TestInput(-1.0, tolerance, true)); builder.add(new TestInput(0.0, tolerance, true)); builder.add(new TestInput(0.01, tolerance, true)); builder.add(new TestInput(0.02, tolerance, true)); builder.add(new TestInput(0.1, tolerance, true)); builder.add(new TestInput(0.2, tolerance, true)); builder.add(new TestInput(1.0, tolerance, true)); builder.add(new TestInput(71, tolerance, true)); builder.add(new TestInput(71.774, tolerance, true)); builder.add(new TestInput(71.775, tolerance, true)); builder.add(new TestInput(71.776, tolerance, true)); builder.add(new TestInput(72, tolerance, true)); builder.add(new TestInput(72.4, tolerance, true)); builder.add(new TestInput(72.47, tolerance, true)); builder.add(new TestInput(72.48, tolerance, true)); builder.add(new TestInput(72.49, tolerance, true)); builder.add(new TestInput(72.5, tolerance, true)); // Equals value builder.add(new TestInput(72.51, tolerance, true)); builder.add(new TestInput(72.52, tolerance, true)); builder.add(new TestInput(72.53, tolerance, true)); builder.add(new TestInput(72.6, tolerance, true)); builder.add(new TestInput(73, tolerance, true)); builder.add(new TestInput(73.224, tolerance, true)); builder.add(new TestInput(73.225, tolerance, true)); builder.add(new TestInput(73.226, tolerance, true)); builder.add(new TestInput(74, tolerance, true)); builder.add(new TestInput(100, tolerance, true)); builder.add(new TestInput(Double.MAX_VALUE, tolerance, true)); final ImmutableList<TestInput> testInputs = builder.build(); testProperty(testInputs, PERSON_TYPE_URI, HAS_HEIGHT); }
From source file:org.fhcrc.cpl.viewer.amt.AmtDatabaseMatcher.java
/** * Calculate linear mass calibration parameters by doing robust linear regression of * mass error in the matches vs. MS1 feature mass. * @param matchingResult/* w ww . j a va 2 s. c o m*/ * @param showCharts * @return */ public double[] calculateMassCalibrationParameters(FeatureSetMatcher.FeatureMatchingResult matchingResult, boolean showCharts) { int numMatches = matchingResult.size(); double[] ms1FeatureMasses = new double[numMatches]; double[] massErrorData = new double[numMatches]; int i = 0; double minMass = Double.MAX_VALUE; double maxMass = Double.MIN_VALUE; for (Feature ms1Feature : matchingResult.getMasterSetFeatures()) { ms1FeatureMasses[i] = ms1Feature.getMass(); if (ms1FeatureMasses[i] < minMass) minMass = ms1FeatureMasses[i]; if (ms1FeatureMasses[i] > maxMass) maxMass = ms1FeatureMasses[i]; Feature matchedAmtFeature = matchingResult.get(ms1Feature).get(0); massErrorData[i] = ms1Feature.getMass() - matchedAmtFeature.getMass(); i++; } double[] result = RegressionUtilities.robustRegression(ms1FeatureMasses, massErrorData); _log.debug("calculateMassCalibrationParameters, slope=" + result[1] + ", intercept=" + result[0]); if (showCharts) { //scatterplot of mass vs. deltaMass PanelWithScatterPlot psp = new PanelWithScatterPlot(ms1FeatureMasses, massErrorData, "MS1 feature mass vs. (signed) match mass error"); psp.addLine(result[1], result[0], minMass, maxMass); psp.setName("Before calibration"); psp.setAxisLabels("MS1 Feature Mass", "Absolute (Da) error (MS1 - AMT)"); psp.displayInTab(); } return result; }