View Javadoc
1 /* 2 * Beta.java 3 * 4 * Created on March 8, 2005, 1:48 PM 5 */ 6 7 package org.mrd.random; 8 9 /*** 10 * 11 * @author administrator 12 */ 13 public class LimitedBeta extends cern.jet.random.Beta{ 14 15 /*** Creates a new instance of Beta */ 16 public LimitedBeta(double alpha, double beta, edu.cornell.lassp.houle.RngPack.RandomElement random) { 17 super(alpha,beta,random); 18 19 if(alpha <= 0) throw new IllegalArgumentException("alpha <= 0.0"); 20 if(beta <= 0) throw new IllegalArgumentException("beta <= 0.0"); 21 } 22 /*** Creates a new instance of Beta */ 23 public LimitedBeta(double arg0, double arg1, edu.cornell.lassp.houle.RngPack.RandomElement random, boolean byMean, boolean limitVariance) { 24 super(1,1,random); 25 26 if(arg0 <= 0){ 27 arg0 = 1.00e-14; 28 } 29 30 if(arg1 <= 0){ 31 arg1 = 1.00e-14; 32 } 33 34 if(byMean){ 35 36 if(arg0 >= 1){ 37 arg0 = 1.0 - 1.00e-14; 38 } 39 40 /* if limitVar then don't let the std go over uniform or get bigger than Math.min(1-arg0,arg0) */ 41 if(limitVariance){ 42 arg1 = Math.min(arg1,Math.sqrt(1.0/12.0)); 43 arg1 = Math.min(arg1,0.5-Math.abs(arg0-0.5)); 44 } 45 46 double a = arg0 * ((( arg0 * ( 1 - arg0 )) / ( arg1 * arg1 )) - 1 ); 47 double b = (1-arg0) * ((( arg0 * ( 1 - arg0 )) / ( arg1 * arg1 )) - 1 ); 48 49 this.setState(Math.min(a,Double.MAX_VALUE),Math.min(b,Double.MAX_VALUE)); 50 }else{ 51 this.setState(arg0,arg1); 52 } 53 } 54 55 /*** Getter for property alpha. 56 * @return Value of property alpha. 57 */ 58 public double getAlpha() { 59 return alpha; 60 } 61 62 /*** Getter for property beta. 63 * @return Value of property beta. 64 */ 65 public double getBeta() { 66 return beta; 67 } 68 69 /*** Getter for property mean. 70 * @return Value of property mean. 71 */ 72 public double getMean() { 73 return alpha/(alpha + beta); 74 } 75 76 /*** Getter for property std. 77 * @return Value of property std. 78 */ 79 public double getStd() { 80 return Math.sqrt(getVariance()); 81 } 82 83 /*** Getter for property variance. 84 * @return Value of property variance. 85 */ 86 public double getVariance() { 87 return (alpha*beta)/((alpha+beta+1)*Math.pow(alpha+beta,2)); 88 } 89 }

This page was automatically generated by Maven