Example usage for org.apache.commons.math.distribution GammaDistributionImpl cumulativeProbability

List of usage examples for org.apache.commons.math.distribution GammaDistributionImpl cumulativeProbability

Introduction

In this page you can find the example usage for org.apache.commons.math.distribution GammaDistributionImpl cumulativeProbability.

Prototype

public double cumulativeProbability(double x) throws MathException 

Source Link

Document

For this distribution, X, this method returns P(X < x).

Usage

From source file:adams.gui.visualization.stats.paintlet.Gamma.java

/**
 * The paint routine of the paintlet.//from w ww. ja v  a  2s  .c  o  m
 *
 * @param g      the graphics context to use for painting
 * @param moment   what {@link PaintMoment} is currently being painted
 */
@Override
protected void doPerformPaint(Graphics g, PaintMoment moment) {
    if ((m_Data != null) && (m_Sorted != null) && m_Shape != -1.0) {
        GUIHelper.configureAntiAliasing(g, m_AntiAliasingEnabled);

        for (int i = 0; i < m_Sorted.length; i++) {
            Graphics2D g2d = (Graphics2D) g;
            //If data points are to be filled
            if (m_Fill) {
                g2d.setColor(m_FillColor);
                g2d.setStroke(new BasicStroke(0));
                g2d.fillOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2,
                        m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size);
            }
            //outline of data point
            g2d.setStroke(new BasicStroke(m_StrokeThickness));
            g2d.setColor(m_Color);
            g2d.drawOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2,
                    m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size);
        }

        //If drawing regression fit diagonal
        if (m_RegressionLine) {
            g.setColor(Color.BLACK);
            double[] newData = new double[m_Sorted.length];
            for (int i = 0; i < m_Sorted.length; i++) {
                newData[i] = Math.log(m_Sorted[i]);
            }
            GammaDistributionImpl gd = new GammaDistributionImpl(m_Shape, m_Scale);
            //draw the expected diagonal line using the gamma distribution
            for (int i = 0; i < m_Sorted.length - 1; i++) {
                double p1;
                try {
                    p1 = gd.cumulativeProbability(newData[i]);
                } catch (MathException e) {
                    p1 = 0;
                }
                double p2;
                try {
                    p2 = gd.cumulativeProbability(newData[i + 1]);
                } catch (MathException e) {
                    p2 = 0;
                }
                g.drawLine(m_AxisBottom.valueToPos(m_Sorted[i]), m_AxisLeft.valueToPos(p1),
                        m_AxisBottom.valueToPos(m_Sorted[i + 1]), m_AxisLeft.valueToPos(p2));
            }
        }
    }
}