001: /*
002: * Copyright 2003-2004 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: package org.apache.commons.math.distribution;
017:
018: /**
019: * A concrete distribution factory. This is the default factory used by
020: * Commons-Math.
021: *
022: * @version $Revision: 201915 $ $Date: 2005-06-26 15:20:57 -0700 (Sun, 26 Jun 2005) $
023: */
024: public class DistributionFactoryImpl extends DistributionFactory {
025:
026: /**
027: * Default constructor. Package scope to prevent unwanted instantiation.
028: */
029: public DistributionFactoryImpl() {
030: super ();
031: }
032:
033: /**
034: * Create a new chi-square distribution with the given degrees of freedom.
035: *
036: * @param degreesOfFreedom degrees of freedom
037: * @return a new chi-square distribution
038: */
039: public ChiSquaredDistribution createChiSquareDistribution(
040: final double degreesOfFreedom) {
041:
042: return new ChiSquaredDistributionImpl(degreesOfFreedom);
043: }
044:
045: /**
046: * Create a new gamma distribution the given shape and scale parameters.
047: *
048: * @param alpha the shape parameter
049: * @param beta the scale parameter
050: * @return a new gamma distribution
051: */
052: public GammaDistribution createGammaDistribution(double alpha,
053: double beta) {
054:
055: return new GammaDistributionImpl(alpha, beta);
056: }
057:
058: /**
059: * Create a new t distribution with the given degrees of freedom.
060: *
061: * @param degreesOfFreedom degrees of freedom
062: * @return a new t distribution.
063: */
064: public TDistribution createTDistribution(double degreesOfFreedom) {
065: return new TDistributionImpl(degreesOfFreedom);
066: }
067:
068: /**
069: * Create a new F-distribution with the given degrees of freedom.
070: *
071: * @param numeratorDegreesOfFreedom numerator degrees of freedom
072: * @param denominatorDegreesOfFreedom denominator degrees of freedom
073: * @return a new F-distribution
074: */
075: public FDistribution createFDistribution(
076: double numeratorDegreesOfFreedom,
077: double denominatorDegreesOfFreedom) {
078: return new FDistributionImpl(numeratorDegreesOfFreedom,
079: denominatorDegreesOfFreedom);
080: }
081:
082: /**
083: * Create a new exponential distribution with the given degrees of freedom.
084: *
085: * @param mean mean
086: * @return a new exponential distribution
087: */
088: public ExponentialDistribution createExponentialDistribution(
089: double mean) {
090: return new ExponentialDistributionImpl(mean);
091: }
092:
093: /**
094: * Create a binomial distribution with the given number of trials and
095: * probability of success.
096: *
097: * @param numberOfTrials the number of trials
098: * @param probabilityOfSuccess the probability of success
099: * @return a new binomial distribution
100: */
101: public BinomialDistribution createBinomialDistribution(
102: int numberOfTrials, double probabilityOfSuccess) {
103: return new BinomialDistributionImpl(numberOfTrials,
104: probabilityOfSuccess);
105: }
106:
107: /**
108: * Create a new hypergeometric distribution with the given the population
109: * size, the number of successes in the population, and the sample size.
110: *
111: * @param populationSize the population size
112: * @param numberOfSuccesses number of successes in the population
113: * @param sampleSize the sample size
114: * @return a new hypergeometric desitribution
115: */
116: public HypergeometricDistribution createHypergeometricDistribution(
117: int populationSize, int numberOfSuccesses, int sampleSize) {
118: return new HypergeometricDistributionImpl(populationSize,
119: numberOfSuccesses, sampleSize);
120: }
121:
122: /**
123: * Create a new normal distribution with the given mean and standard
124: * deviation.
125: *
126: * @param mean the mean of the distribution
127: * @param sd standard deviation
128: * @return a new normal distribution
129: */
130: public NormalDistribution createNormalDistribution(double mean,
131: double sd) {
132: return new NormalDistributionImpl(mean, sd);
133: }
134:
135: /**
136: * Create a new normal distribution with the mean zero and standard
137: * deviation one.
138: *
139: * @return a new normal distribution
140: */
141: public NormalDistribution createNormalDistribution() {
142: return new NormalDistributionImpl();
143: }
144:
145: /**
146: * Create a new Poisson distribution with poisson parameter lambda.
147: * <p>
148: * lambda must be postive; otherwise an
149: * <code>IllegalArgumentException</code> is thrown.
150: *
151: * @param lambda poisson parameter
152: * @return a new Poisson distribution
153: * @throws IllegalArgumentException if lambda ≤ 0
154: */
155: public PoissonDistribution createPoissonDistribution(double lambda) {
156: return new PoissonDistributionImpl(lambda);
157: }
158:
159: }
|