View Javadoc

1   /*
2    * Copyright 2003-2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.commons.math.distribution;
18  
19  import org.apache.commons.discovery.tools.DiscoverClass;
20  
21  /***
22   * This factory provids the means to create common statistical distributions.
23   * The following distributions are supported:
24   * <ul>
25   * <li>Binomial</li>
26   * <li>Chi-Squared</li>
27   * <li>Exponential</li>
28   * <li>F</li>
29   * <li>Gamma</li>
30   * <li>HyperGeometric</li>
31   * <li>Poisson</li>
32   * <li>Normal</li>
33   * <li>Student's t</li>
34   * </ul>
35   *
36   * Common usage:<pre>
37   * DistributionFactory factory = DistributionFactory.newInstance();
38   *
39   * // create a Chi-Square distribution with 5 degrees of freedom.
40   * ChiSquaredDistribution chi = factory.createChiSquareDistribution(5.0);
41   * </pre>
42   *
43   * @version $Revision: 1.22 $ $Date: 2004/11/07 03:32:48 $
44   */
45  public abstract class DistributionFactory {
46      /***
47       * Default constructor.
48       */
49      protected DistributionFactory() {
50          super();
51      }
52      
53      /***
54       * Create an instance of a <code>DistributionFactory</code>
55       * @return a new factory. 
56       */
57      public static DistributionFactory newInstance() {
58          DistributionFactory factory = null;
59          try {
60              DiscoverClass dc = new DiscoverClass();
61              factory = (DistributionFactory) dc.newInstance(
62                  DistributionFactory.class,
63                  "org.apache.commons.math.distribution.DistributionFactoryImpl");
64          } catch(Throwable t) {
65              return new DistributionFactoryImpl();
66          }
67          return factory;
68      }
69  
70      /***
71       * Create a binomial distribution with the given number of trials and
72       * probability of success.
73       * 
74       * @param numberOfTrials the number of trials.
75       * @param probabilityOfSuccess the probability of success
76       * @return a new binomial distribution
77       */
78      public abstract BinomialDistribution createBinomialDistribution(
79          int numberOfTrials, double probabilityOfSuccess);
80          
81      /***
82       * Create a new chi-square distribution with the given degrees of freedom.
83       * 
84       * @param degreesOfFreedom degrees of freedom
85       * @return a new chi-square distribution  
86       */
87      public abstract ChiSquaredDistribution createChiSquareDistribution(
88          double degreesOfFreedom);
89      
90      /***
91       * Create a new exponential distribution with the given degrees of freedom.
92       * 
93       * @param mean mean
94       * @return a new exponential distribution  
95       */
96      public abstract ExponentialDistribution createExponentialDistribution(
97          double mean);
98      
99      /***
100      * Create a new F-distribution with the given degrees of freedom.
101      * 
102      * @param numeratorDegreesOfFreedom numerator degrees of freedom
103      * @param denominatorDegreesOfFreedom denominator degrees of freedom
104      * @return a new F-distribution 
105      */
106     public abstract FDistribution createFDistribution(
107         double numeratorDegreesOfFreedom, double denominatorDegreesOfFreedom);
108     
109     /***
110      * Create a new gamma distribution with the given shape and scale
111      * parameters.
112      * 
113      * @param alpha the shape parameter
114      * @param beta the scale parameter
115      * 
116      * @return a new gamma distribution  
117      */
118     public abstract GammaDistribution createGammaDistribution(
119         double alpha, double beta);
120 
121     /***
122      * Create a new t distribution with the given degrees of freedom.
123      * 
124      * @param degreesOfFreedom degrees of freedom
125      * @return a new t distribution  
126      */
127     public abstract TDistribution createTDistribution(double degreesOfFreedom);
128     
129     /***
130      * Create a new hypergeometric distribution with the given the population
131      * size, the number of successes in the population, and the sample size.
132      * 
133      * @param populationSize the population size
134      * @param numberOfSuccesses number of successes in the population
135      * @param sampleSize the sample size
136      * @return a new hypergeometric desitribution
137      */
138     public abstract HypergeometricDistribution
139         createHypergeometricDistribution(int populationSize,
140             int numberOfSuccesses, int sampleSize);
141  
142 	/***
143 	 * Create a new normal distribution with the given mean and standard
144 	 * deviation.
145      * 
146 	 * @param mean the mean of the distribution
147 	 * @param sd standard deviation
148 	 * @return a new normal distribution  
149 	 */           
150     public abstract NormalDistribution 
151     	createNormalDistribution(double mean, double sd);
152     	
153 	/***
154 	 * Create a new normal distribution with mean zero and standard
155 	 * deviation one.
156      * 
157 	 * @return a new normal distribution.  
158 	 */               
159 	public abstract NormalDistribution createNormalDistribution();
160     
161     /***
162      * Create a new Poisson distribution with poisson parameter lambda.
163      * 
164      * @param lambda poisson parameter
165      * @return a new normal distribution.  
166      */               
167     public abstract PoissonDistribution 
168         createPoissonDistribution(double lambda);
169 }