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

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

Introduction

In this page you can find the example usage for org.apache.commons.math.distribution ExponentialDistributionImpl 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.Exponential.java

/**
 * The paint routine of the paintlet./*  w ww  .  ja va 2s  .  c  om*/
 *
 * @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)) {
        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]);
            }
            ExponentialDistributionImpl ex = new ExponentialDistributionImpl(StatUtils.mean(newData));
            //draw the expected diagonal line using the exponential distribution
            for (int i = 0; i < m_Sorted.length - 1; i++) {
                double prob1;
                try {
                    prob1 = ex.cumulativeProbability(newData[i]);
                } catch (MathException e) {
                    prob1 = 0;
                }
                double prob2;
                try {
                    prob2 = ex.cumulativeProbability(newData[i + 1]);
                } catch (MathException e) {
                    prob2 = 0;
                }
                double p1 = -Math.log(1 - prob1);
                double p2 = -Math.log(1 - prob2);
                g.drawLine(m_AxisBottom.valueToPos(m_Sorted[i]), m_AxisLeft.valueToPos(p1),
                        m_AxisBottom.valueToPos(m_Sorted[i + 1]), m_AxisLeft.valueToPos(p2));
            }
        }
    }
}