001: /*
002: * Copyright 2003-2005 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.commons.math.distribution;
018:
019: import org.apache.commons.discovery.tools.DiscoverClass;
020:
021: /**
022: * This factory provids the means to create common statistical distributions.
023: * The following distributions are supported:
024: * <ul>
025: * <li>Binomial</li>
026: * <li>Cauchy</li>
027: * <li>Chi-Squared</li>
028: * <li>Exponential</li>
029: * <li>F</li>
030: * <li>Gamma</li>
031: * <li>HyperGeometric</li>
032: * <li>Poisson</li>
033: * <li>Normal</li>
034: * <li>Student's t</li>
035: * <li>Weibull</li>
036: * </ul>
037: *
038: * Common usage:<pre>
039: * DistributionFactory factory = DistributionFactory.newInstance();
040: *
041: * // create a Chi-Square distribution with 5 degrees of freedom.
042: * ChiSquaredDistribution chi = factory.createChiSquareDistribution(5.0);
043: * </pre>
044: *
045: * @version $Revision: 201915 $ $Date: 2005-06-26 15:20:57 -0700 (Sun, 26 Jun 2005) $
046: */
047: public abstract class DistributionFactory {
048: /**
049: * Default constructor.
050: */
051: protected DistributionFactory() {
052: super ();
053: }
054:
055: /**
056: * Create an instance of a <code>DistributionFactory</code>
057: * @return a new factory.
058: */
059: public static DistributionFactory newInstance() {
060: DistributionFactory factory = null;
061: try {
062: DiscoverClass dc = new DiscoverClass();
063: factory = (DistributionFactory) dc
064: .newInstance(DistributionFactory.class,
065: "org.apache.commons.math.distribution.DistributionFactoryImpl");
066: } catch (Throwable t) {
067: return new DistributionFactoryImpl();
068: }
069: return factory;
070: }
071:
072: /**
073: * Create a binomial distribution with the given number of trials and
074: * probability of success.
075: *
076: * @param numberOfTrials the number of trials.
077: * @param probabilityOfSuccess the probability of success
078: * @return a new binomial distribution
079: */
080: public abstract BinomialDistribution createBinomialDistribution(
081: int numberOfTrials, double probabilityOfSuccess);
082:
083: /**
084: * Create a new cauchy distribution with the given median and scale.
085: * @param median the median of the distribution
086: * @param scale the scale
087: * @return a new cauchy distribution
088: * @since 1.1
089: */
090: public CauchyDistribution createCauchyDistribution(double median,
091: double scale) {
092: return new CauchyDistributionImpl(median, scale);
093: }
094:
095: /**
096: * Create a new chi-square distribution with the given degrees of freedom.
097: *
098: * @param degreesOfFreedom degrees of freedom
099: * @return a new chi-square distribution
100: */
101: public abstract ChiSquaredDistribution createChiSquareDistribution(
102: double degreesOfFreedom);
103:
104: /**
105: * Create a new exponential distribution with the given degrees of freedom.
106: *
107: * @param mean mean
108: * @return a new exponential distribution
109: */
110: public abstract ExponentialDistribution createExponentialDistribution(
111: double mean);
112:
113: /**
114: * Create a new F-distribution with the given degrees of freedom.
115: *
116: * @param numeratorDegreesOfFreedom numerator degrees of freedom
117: * @param denominatorDegreesOfFreedom denominator degrees of freedom
118: * @return a new F-distribution
119: */
120: public abstract FDistribution createFDistribution(
121: double numeratorDegreesOfFreedom,
122: double denominatorDegreesOfFreedom);
123:
124: /**
125: * Create a new gamma distribution with the given shape and scale
126: * parameters.
127: *
128: * @param alpha the shape parameter
129: * @param beta the scale parameter
130: *
131: * @return a new gamma distribution
132: */
133: public abstract GammaDistribution createGammaDistribution(
134: double alpha, double beta);
135:
136: /**
137: * Create a new t distribution with the given degrees of freedom.
138: *
139: * @param degreesOfFreedom degrees of freedom
140: * @return a new t distribution
141: */
142: public abstract TDistribution createTDistribution(
143: double degreesOfFreedom);
144:
145: /**
146: * Create a new hypergeometric distribution with the given the population
147: * size, the number of successes in the population, and the sample size.
148: *
149: * @param populationSize the population size
150: * @param numberOfSuccesses number of successes in the population
151: * @param sampleSize the sample size
152: * @return a new hypergeometric desitribution
153: */
154: public abstract HypergeometricDistribution createHypergeometricDistribution(
155: int populationSize, int numberOfSuccesses, int sampleSize);
156:
157: /**
158: * Create a new normal distribution with the given mean and standard
159: * deviation.
160: *
161: * @param mean the mean of the distribution
162: * @param sd standard deviation
163: * @return a new normal distribution
164: */
165: public abstract NormalDistribution createNormalDistribution(
166: double mean, double sd);
167:
168: /**
169: * Create a new normal distribution with mean zero and standard
170: * deviation one.
171: *
172: * @return a new normal distribution.
173: */
174: public abstract NormalDistribution createNormalDistribution();
175:
176: /**
177: * Create a new Poisson distribution with poisson parameter lambda.
178: *
179: * @param lambda poisson parameter
180: * @return a new poisson distribution.
181: */
182: public abstract PoissonDistribution createPoissonDistribution(
183: double lambda);
184:
185: /**
186: * Create a new Weibull distribution with the given shape and scale
187: * parameters.
188: *
189: * @param alpha the shape parameter.
190: * @param beta the scale parameter.
191: * @return a new Weibull distribution.
192: * @since 1.1
193: */
194: public WeibullDistribution createWeibullDistribution(double alpha,
195: double beta) {
196: return new WeibullDistributionImpl(alpha, beta);
197: }
198: }
|