1 16 17 package org.apache.commons.math.distribution; 18 19 import java.io.Serializable ; 20 21 28 public class CauchyDistributionImpl extends AbstractContinuousDistribution 29 implements CauchyDistribution, Serializable { 30 31 32 static final long serialVersionUID = 8589540077390120676L; 33 34 35 private double median = 0; 36 37 38 private double scale = 1; 39 40 44 public CauchyDistributionImpl(){ 45 this(0.0, 1.0); 46 } 47 48 53 public CauchyDistributionImpl(double median, double s){ 54 super(); 55 setMedian(median); 56 setScale(s); 57 } 58 59 64 public double cumulativeProbability(double x) { 65 return 0.5 + (Math.atan((x - median) / scale) / Math.PI); 66 } 67 68 72 public double getMedian() { 73 return median; 74 } 75 76 80 public double getScale() { 81 return scale; 82 } 83 84 96 public double inverseCumulativeProbability(double p) { 97 double ret; 98 if (p < 0.0 || p > 1.0) { 99 throw new IllegalArgumentException 100 ("probability argument must be between 0 and 1 (inclusive)"); 101 } else if (p == 0) { 102 ret = Double.NEGATIVE_INFINITY; 103 } else if (p == 1) { 104 ret = Double.POSITIVE_INFINITY; 105 } else { 106 ret = median + scale * Math.tan(Math.PI * (p - .5)); 107 } 108 return ret; 109 } 110 111 115 public void setMedian(double median) { 116 this.median = median; 117 } 118 119 124 public void setScale(double s) { 125 if (s <= 0.0) { 126 throw new IllegalArgumentException ( 127 "Scale must be positive."); 128 } 129 scale = s; 130 } 131 132 141 protected double getDomainLowerBound(double p) { 142 double ret; 143 144 if (p < .5) { 145 ret = -Double.MAX_VALUE; 146 } else { 147 ret = getMedian(); 148 } 149 150 return ret; 151 } 152 153 162 protected double getDomainUpperBound(double p) { 163 double ret; 164 165 if (p < .5) { 166 ret = getMedian(); 167 } else { 168 ret = Double.MAX_VALUE; 169 } 170 171 return ret; 172 } 173 174 182 protected double getInitialDomain(double p) { 183 double ret; 184 185 if (p < .5) { 186 ret = getMedian() - getScale(); 187 } else if (p > .5) { 188 ret = getMedian() + getScale(); 189 } else { 190 ret = getMedian(); 191 } 192 193 return ret; 194 } 195 } 196 | Popular Tags |