Example usage for org.jfree.data.statistics HistogramType SCALE_AREA_TO_1

List of usage examples for org.jfree.data.statistics HistogramType SCALE_AREA_TO_1

Introduction

In this page you can find the example usage for org.jfree.data.statistics HistogramType SCALE_AREA_TO_1.

Prototype

HistogramType SCALE_AREA_TO_1

To view the source code for org.jfree.data.statistics HistogramType SCALE_AREA_TO_1.

Click Source Link

Document

Scale area to one.

Usage

From source file:com.jaxzin.iraf.demo.Main.java

private static IntervalXYDataset createData(final int count) {
    final HistogramDataset data = new HistogramDataset();
    data.setType(HistogramType.SCALE_AREA_TO_1);
    data.addSeries("freq", createNormalDist(count, 0), (int) Math.round(Math.sqrt(count)));
    data.addSeries("rel_freq", createNormalDist(count, 2), (int) Math.round(Math.sqrt(count)));
    data.addSeries("area", createNormalDist(count, -2), (int) Math.round(Math.sqrt(count)));
    return data;//from  www. jav a2 s  .  com
}

From source file:edu.gmu.cs.sim.util.media.chart.HistogramGenerator.java

public HistogramGenerator() {
    // buildChart is called by super() first

    LabelledList list = new LabelledList("Show Histogram...");
    DisclosurePanel pan1 = new DisclosurePanel("Show Histogram...", list);

    final HistogramType[] styles = new HistogramType[] { HistogramType.FREQUENCY,
            HistogramType.RELATIVE_FREQUENCY, HistogramType.SCALE_AREA_TO_1 };
    final JComboBox style = new JComboBox(
            new String[] { "By Frequency", "By Relative Frequency", "With Area = 1.0" });
    style.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            histogramType = styles[style.getSelectedIndex()];
            HistogramDataset dataset = (HistogramDataset) (getSeriesDataset());
            dataset.setType(histogramType);
        }//from w ww.j ava2s.c om
    });
    list.add(style);
    addGlobalAttribute(pan1);
}

From source file:MSUmpire.DIA.MixtureModelKDESemiParametric.java

public void GeneratePlot(String pngfile) throws IOException {
    String modelfile = FilenameUtils.getFullPath(pngfile) + "/" + FilenameUtils.getBaseName(pngfile)
            + "_ModelPoints.txt";
    FileWriter writer = new FileWriter(modelfile);

    double[] IDObs = new double[IDEmpiricalDist.getN()];
    double[] DecoyObs = new double[DecoyEmpiricalDist.getN()];

    for (int i = 0; i < IDEmpiricalDist.getN(); i++) {
        IDObs[i] = IDEmpiricalDist.getObs(i);
    }/*from   ww  w  .j a v  a2s. c o m*/
    for (int i = 0; i < DecoyEmpiricalDist.getN(); i++) {
        DecoyObs[i] = DecoyEmpiricalDist.getObs(i);
    }

    XYSeries model1 = new XYSeries("Incorrect matches");
    XYSeries model2 = new XYSeries("Correct matches");
    XYSeries model3 = new XYSeries("All target hits");

    writer.write("UScore\tModel\tCorrect\tDecoy\n");
    for (int i = 0; i < NoBinPoints; i++) {
        model1.add(model_kde_x[i], decoy_kde_y[i]);
        model2.add(model_kde_x[i], correct_kde_y[i]);
        model3.add(model_kde_x[i], model_kde_y[i]);
        writer.write(model_kde_x[i] + "\t" + model_kde_y[i] + "\t" + correct_kde_y[i] + "\t" + decoy_kde_y[i]
                + "\n");
    }
    writer.close();

    MixtureModelProb = new float[NoBinPoints + 1][3];
    float positiveaccu = 0f;
    float negativeaccu = 0f;

    MixtureModelProb[0][0] = (float) model2.getMaxX() + Float.MIN_VALUE;
    MixtureModelProb[0][1] = 1f;
    MixtureModelProb[0][2] = 1f;

    for (int i = 1; i < NoBinPoints + 1; i++) {
        double positiveNumber = correct_kde_y[NoBinPoints - i];
        double negativeNumber = decoy_kde_y[NoBinPoints - i];
        MixtureModelProb[i][0] = (float) model_kde_x[NoBinPoints - i];
        positiveaccu += positiveNumber;
        negativeaccu += negativeNumber;
        MixtureModelProb[i][2] = 0.999999f * (float) (positiveNumber / (negativeNumber + positiveNumber));
        MixtureModelProb[i][1] = 0.999999f * (float) (positiveaccu / (negativeaccu + positiveaccu));
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(model1);
    dataset.addSeries(model2);
    dataset.addSeries(model3);

    HistogramDataset histogramDataset = new HistogramDataset();
    histogramDataset.setType(HistogramType.SCALE_AREA_TO_1);
    histogramDataset.addSeries("ID hits", IDObs, 100);
    histogramDataset.addSeries("Decoy hits", DecoyObs, 100);
    //histogramDataset.addSeries("Model hits", ModelObs, 100);

    JFreeChart chart = ChartFactory.createHistogram(FilenameUtils.getBaseName(pngfile), "Score", "Hits",
            histogramDataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = chart.getXYPlot();

    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(min, max);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setForegroundAlpha(0.8f);
    chart.setBackgroundPaint(Color.white);

    XYLineAndShapeRenderer render = new XYLineAndShapeRenderer();

    plot.setDataset(1, dataset);
    plot.setRenderer(1, render);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    try {
        ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
    } catch (IOException e) {
    }
}

From source file:org.jfree.data.statistics.HistogramDataset.java

/**
 * Returns the y-value for a bin (calculated to take into account the
 * histogram type)./*  ww  w  .  j  a  va 2s.  c  o  m*/
 *
 * @param series  the series index (in the range <code>0</code> to
 *     <code>getSeriesCount() - 1</code>).
 * @param item  the item index (zero based).
 *
 * @return The y-value.
 *
 * @throws IndexOutOfBoundsException if <code>series</code> is outside the
 *     specified range.
 */
@Override
public Number getY(int series, int item) {
    List bins = getBins(series);
    HistogramBin bin = (HistogramBin) bins.get(item);
    double total = getTotal(series);
    double binWidth = getBinWidth(series);

    if (this.type == HistogramType.FREQUENCY) {
        return new Double(bin.getCount());
    } else if (this.type == HistogramType.RELATIVE_FREQUENCY) {
        return new Double(bin.getCount() / total);
    } else if (this.type == HistogramType.SCALE_AREA_TO_1) {
        return new Double(bin.getCount() / (binWidth * total));
    } else { // pretty sure this shouldn't ever happen
        throw new IllegalStateException();
    }
}

From source file:MSUmpire.DIA.TargetMatchScoring.java

public void MixtureModeling() throws IOException {
    if (libTargetMatches.isEmpty()) {
        return;// w w  w.  j a v  a 2s  . c o  m
    }
    int IDNo = 0;
    int decoyNo = 0;
    int modelNo = 0;
    double IDmean = 0d;
    double Decoymean = 0d;

    for (UmpireSpecLibMatch match : libIDMatches) {
        if (match.BestHit != null) {
            IDNo++;
            IDmean += match.BestHit.UmpireScore;
        }
    }

    decoyNo = decoyModelingList.size();
    for (PeakGroupScore peakGroupScore : decoyModelingList) {
        Decoymean += peakGroupScore.UmpireScore;
    }

    for (UmpireSpecLibMatch match : libTargetMatches) {
        //modelNo+= match.TargetHits.size();
        if (match.BestMS1Hit != null) {
            modelNo++;
        }
        if (match.BestMS2Hit != null) {
            modelNo++;
        }
    }

    Decoymean /= decoyNo;
    IDmean /= IDNo;

    PVector[] points = new PVector[modelNo];
    PVector[] centroids = new PVector[2];

    int idx = 0;
    for (UmpireSpecLibMatch match : libTargetMatches) {
        if (match.BestMS1Hit != null) {
            points[idx] = new PVector(1);
            points[idx].array[0] = match.BestMS1Hit.UmpireScore;
            idx++;
        }
        if (match.BestMS2Hit != null) {
            points[idx] = new PVector(1);
            points[idx].array[0] = match.BestMS2Hit.UmpireScore;
            idx++;
        }
        //            for(PeakGroupScore peakGroupScore : match.TargetHits){
        //                points[idx] = new PVector(1);
        //                points[idx].array[0] = match.BestMS2Hit.UmpireScore;
        //                idx++;
        //            }
    }

    MixtureModel mmc;
    centroids[0] = new PVector(1);
    centroids[0].array[0] = Decoymean;
    centroids[1] = new PVector(1);
    centroids[1].array[0] = IDmean;
    Vector<PVector>[] clusters = KMeans.run(points, 2, centroids);
    MixtureModel mm = ExpectationMaximization1D.initialize(clusters);
    mmc = ExpectationMaximization1D.run(points, mm);
    DecimalFormat df = new DecimalFormat("#.####");
    Logger.getRootLogger()
            .debug("----------------------------------------------------------------------------------------");
    Logger.getRootLogger().debug("No. of modeling points=" + modelNo);
    Logger.getRootLogger().debug("ID hits mean=" + df.format(IDmean));
    Logger.getRootLogger().debug("Decoy hits mean=" + df.format(Decoymean));
    //System.out.print("T-test: p-value=" + df.format(model.ttest.pValue).toString() + "\n");
    Logger.getRootLogger()
            .debug("Incorrect hits model mean=" + df.format(((PVector) mmc.param[0]).array[0]) + " variance="
                    + df.format(((PVector) mmc.param[0]).array[1]) + " weight=" + df.format(mmc.weight[0]));
    Logger.getRootLogger()
            .debug("Correct hits model mean=" + df.format(((PVector) mmc.param[1]).array[0]) + " variance="
                    + df.format(((PVector) mmc.param[1]).array[1]) + " weight=" + df.format(mmc.weight[1]));

    if (((PVector) mmc.param[0]).array[0] > ((PVector) mmc.param[1]).array[0]) {
        return;
    }

    float max = (float) (((PVector) mmc.param[1]).array[0] + 4 * Math.sqrt(((PVector) mmc.param[1]).array[1]));
    float min = (float) (((PVector) mmc.param[0]).array[0] - 4 * Math.sqrt(((PVector) mmc.param[0]).array[1]));

    IDNo = 0;
    decoyNo = 0;
    modelNo = 0;

    for (PeakGroupScore peakGroupScore : decoyModelingList) {
        if (peakGroupScore.UmpireScore > min && peakGroupScore.UmpireScore < max) {
            decoyNo++;
        }
    }

    for (UmpireSpecLibMatch match : libIDMatches) {
        if (match.BestHit != null && match.BestHit.UmpireScore > min && match.BestHit.UmpireScore < max) {
            IDNo++;
        }
    }

    for (UmpireSpecLibMatch match : libTargetMatches) {
        //targetNo += match.TargetHits.size();
        //decoyNo += match.DecoyHits.size();
        if (match.BestMS1Hit != null && match.BestMS1Hit.UmpireScore > min
                && match.BestMS1Hit.UmpireScore < max) {
            modelNo++;
        }
        if (match.BestMS2Hit != null && match.BestMS2Hit.UmpireScore > min
                && match.BestMS2Hit.UmpireScore < max) {
            modelNo++;
        }
        //modelNo += match.TargetHits.size();            
    }

    double[] IDObs = new double[IDNo];
    double[] DecoyObs = new double[decoyNo];
    double[] ModelObs = new double[modelNo];
    idx = 0;
    int didx = 0;
    int midx = 0;
    for (UmpireSpecLibMatch match : libIDMatches) {
        if (match.BestHit != null && match.BestHit.UmpireScore > min && match.BestHit.UmpireScore < max) {
            IDObs[idx++] = match.BestHit.UmpireScore;
        }
    }
    for (PeakGroupScore peakGroupScore : decoyModelingList) {
        if (peakGroupScore.UmpireScore > min && peakGroupScore.UmpireScore < max) {
            DecoyObs[didx++] = peakGroupScore.UmpireScore;
        }
    }

    for (UmpireSpecLibMatch match : libTargetMatches) {
        //            for(PeakGroupScore peak : match.TargetHits){
        //                ModelObs[midx++]=peak.UmpireScore;
        //            }
        if (match.BestMS1Hit != null && match.BestMS1Hit.UmpireScore > min
                && match.BestMS1Hit.UmpireScore < max) {
            ModelObs[midx++] = match.BestMS1Hit.UmpireScore;
        }
        if (match.BestMS2Hit != null && match.BestMS2Hit.UmpireScore > min
                && match.BestMS2Hit.UmpireScore < max) {
            ModelObs[midx++] = match.BestMS2Hit.UmpireScore;
        }
    }

    String pngfile = FilenameUtils.getFullPath(Filename) + "/" + FilenameUtils.getBaseName(Filename) + "_"
            + LibID + "_LibMatchModel.png";
    XYSeries model1 = new XYSeries("Incorrect matches");
    XYSeries model2 = new XYSeries("Correct matches");
    XYSeries model3 = new XYSeries("All target hits");

    String modelfile = FilenameUtils.getFullPath(pngfile) + "/" + FilenameUtils.getBaseName(pngfile)
            + "_ModelPoints.txt";
    FileWriter writer = new FileWriter(modelfile);
    writer.write("UScore\tModel\tCorrect\tDecoy\n");

    int NoPoints = 1000;
    double[] model_kde_x = new double[NoPoints];
    float intv = (max - min) / NoPoints;
    PVector point = new PVector(2);
    for (int i = 0; i < NoPoints; i++) {
        point.array[0] = max - i * intv;
        model_kde_x[i] = point.array[0];
        point.array[1] = mmc.EF.density(point, mmc.param[0]) * mmc.weight[0];
        model1.add(point.array[0], point.array[1]);
        point.array[1] = mmc.EF.density(point, mmc.param[1]) * mmc.weight[1];
        model2.add(point.array[0], point.array[1]);

    }

    KernelDensityEstimator kde = new KernelDensityEstimator();
    kde.SetData(ModelObs);
    double[] model_kde_y = kde.Density(model_kde_x);

    for (int i = 0; i < NoPoints; i++) {
        if (model_kde_x[i] > min && model_kde_x[i] < max) {
            point.array[0] = max - i * intv;
            model_kde_x[i] = point.array[0];
            model3.add(model_kde_x[i], model_kde_y[i]);
            writer.write(point.array[0] + "\t" + mmc.EF.density(point, mmc.param[0]) * mmc.weight[0] + "\t"
                    + mmc.EF.density(point, mmc.param[1]) * mmc.weight[1] + "\t" + model_kde_y[i] + "\n");
        }
    }
    writer.close();
    MixtureModelProb = new float[NoPoints + 1][3];
    float positiveaccu = 0f;
    float negativeaccu = 0f;

    MixtureModelProb[0][0] = (float) model2.getMaxX() + Float.MIN_VALUE;
    MixtureModelProb[0][1] = 1f;
    MixtureModelProb[0][2] = 1f;

    for (int i = 1; i < NoPoints + 1; i++) {
        float positiveNumber = model2.getY(NoPoints - i).floatValue();
        float negativeNumber = model1.getY(NoPoints - i).floatValue();
        MixtureModelProb[i][0] = model2.getX(NoPoints - i).floatValue();
        positiveaccu += positiveNumber;
        negativeaccu += negativeNumber;
        MixtureModelProb[i][2] = positiveNumber / (negativeNumber + positiveNumber);
        MixtureModelProb[i][1] = positiveaccu / (negativeaccu + positiveaccu);
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(model1);
    dataset.addSeries(model2);
    dataset.addSeries(model3);

    HistogramDataset histogramDataset = new HistogramDataset();
    histogramDataset.setType(HistogramType.SCALE_AREA_TO_1);
    histogramDataset.addSeries("ID hits", IDObs, 100);
    histogramDataset.addSeries("Decoy hits", DecoyObs, 100);
    //histogramDataset.addSeries("Model hits", ModelObs, 100);

    JFreeChart chart = ChartFactory.createHistogram(FilenameUtils.getBaseName(pngfile), "Score", "Hits",
            histogramDataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = chart.getXYPlot();

    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(min, max);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setForegroundAlpha(0.8f);
    chart.setBackgroundPaint(Color.white);

    XYLineAndShapeRenderer render = new XYLineAndShapeRenderer();
    //        render.setSeriesPaint(0, Color.DARK_GRAY);
    //        render.setSeriesPaint(1, Color.DARK_GRAY); 
    //        render.setSeriesPaint(2, Color.GREEN); 
    //        render.setSeriesShape(0, new Ellipse2D.Double(0, 0, 2, 2));
    //        render.setSeriesShape(1, new Ellipse2D.Double(0, 0, 2, 2));
    //        render.setSeriesShape(2, new Ellipse2D.Double(0, 0, 2.5f, 2.5f));
    //        render.setSeriesStroke(1, new BasicStroke(1.0f));
    //        render.setSeriesStroke(0, new BasicStroke(1.0f));
    //        render.setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setDataset(1, dataset);
    plot.setRenderer(1, render);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    try {
        ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
    } catch (IOException e) {
    }
}