1 16 17 package org.apache.commons.math.distribution; 18 19 import java.io.Serializable ; 20 21 28 public class WeibullDistributionImpl extends AbstractContinuousDistribution 29 implements WeibullDistribution, Serializable { 30 31 32 static final long serialVersionUID = 8589540077390120676L; 33 34 35 private double alpha; 36 37 38 private double beta; 39 40 46 public WeibullDistributionImpl(double alpha, double beta){ 47 super(); 48 setShape(alpha); 49 setScale(beta); 50 } 51 52 57 public double cumulativeProbability(double x) { 58 double ret; 59 if (x <= 0.0) { 60 ret = 0.0; 61 } else { 62 ret = 1.0 - Math.exp(-Math.pow(x / getScale(), getShape())); 63 } 64 return ret; 65 } 66 67 71 public double getShape() { 72 return alpha; 73 } 74 75 79 public double getScale() { 80 return beta; 81 } 82 83 95 public double inverseCumulativeProbability(double p) { 96 double ret; 97 if (p < 0.0 || p > 1.0) { 98 throw new IllegalArgumentException 99 ("probability argument must be between 0 and 1 (inclusive)"); 100 } else if (p == 0) { 101 ret = 0.0; 102 } else if (p == 1) { 103 ret = Double.POSITIVE_INFINITY; 104 } else { 105 ret = getScale() * Math.pow(-Math.log(1.0 - p), 1.0 / getShape()); 106 } 107 return ret; 108 } 109 110 114 public void setShape(double alpha) { 115 if (alpha <= 0.0) { 116 throw new IllegalArgumentException ( 117 "Shape must be positive."); 118 } 119 this.alpha = alpha; 120 } 121 122 126 public void setScale(double beta) { 127 if (beta <= 0.0) { 128 throw new IllegalArgumentException ( 129 "Scale must be positive."); 130 } 131 this.beta = beta; 132 } 133 134 143 protected double getDomainLowerBound(double p) { 144 return 0.0; 145 } 146 147 156 protected double getDomainUpperBound(double p) { 157 return Double.MAX_VALUE; 158 } 159 160 168 protected double getInitialDomain(double p) { 169 return Math.pow(getScale() * Math.log(2.0), 1.0 / getShape()); 171 } 172 } 173 | Popular Tags |