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  package org.apache.commons.math.distribution;
    17
    18  /***
    19   * A concrete distribution factory.  This is the default factory used by
    20   * Commons-Math.
    21   *
    22   * @version $Revision: 1.21 $ $Date: 2004/11/07 03:32:48 $
    23   */
    24  public class DistributionFactoryImpl extends DistributionFactory {
    25
    26      /***
    27       * Default constructor.  Package scope to prevent unwanted instantiation.
    28       */
    29      public DistributionFactoryImpl() {
    30          super();
    31      }
    32
    33      /***
    34       * Create a new chi-square distribution with the given degrees of freedom.
    35       *
    36       * @param degreesOfFreedom degrees of freedom
    37       * @return a new chi-square distribution
    38       */
    39      public ChiSquaredDistribution createChiSquareDistribution(
    40          final double degreesOfFreedom) {
    41
    42          return new ChiSquaredDistributionImpl(degreesOfFreedom);
    43      }
    44
    45      /***
    46       * Create a new gamma distribution the given shape and scale parameters.
    47       *
    48       * @param alpha the shape parameter
    49       * @param beta the scale parameter
    50       * @return a new gamma distribution
    51       */
    52      public GammaDistribution createGammaDistribution(
    53          double alpha, double beta) {
    54
    55          return new GammaDistributionImpl(alpha, beta);
    56      }
    57
    58      /***
    59       * Create a new t distribution with the given degrees of freedom.
    60       *
    61       * @param degreesOfFreedom degrees of freedom
    62       * @return a new t distribution.
    63       */
    64      public TDistribution createTDistribution(double degreesOfFreedom) {
    65          return new TDistributionImpl(degreesOfFreedom);
    66      }
    67
    68      /***
    69       * Create a new F-distribution with the given degrees of freedom.
    70       *
    71       * @param numeratorDegreesOfFreedom numerator degrees of freedom
    72       * @param denominatorDegreesOfFreedom denominator degrees of freedom
    73       * @return a new F-distribution
    74       */
    75      public FDistribution createFDistribution(
    76          double numeratorDegreesOfFreedom,
    77          double denominatorDegreesOfFreedom) {
    78          return new FDistributionImpl(numeratorDegreesOfFreedom,
    79              denominatorDegreesOfFreedom);
    80      }
    81
    82      /***
    83       * Create a new exponential distribution with the given degrees of freedom.
    84       *
    85       * @param mean mean
    86       * @return a new exponential distribution
    87       */
    88      public ExponentialDistribution createExponentialDistribution(double mean) {
    89          return new ExponentialDistributionImpl(mean);
    90      }
    91
    92      /***
    93       * Create a binomial distribution with the given number of trials and
    94       * probability of success.
    95       *
    96       * @param numberOfTrials the number of trials
    97       * @param probabilityOfSuccess the probability of success
    98       * @return a new binomial distribution
    99       */
    100     public BinomialDistribution createBinomialDistribution(
    101         int numberOfTrials, double probabilityOfSuccess) {
    102         return new BinomialDistributionImpl(numberOfTrials,
    103             probabilityOfSuccess);
    104     }
    105
    106     /***
    107      * Create a new hypergeometric distribution with the given the population
    108      * size, the number of successes in the population, and the sample size.
    109      *
    110      * @param populationSize the population size
    111      * @param numberOfSuccesses number of successes in the population
    112      * @param sampleSize the sample size
    113      * @return a new hypergeometric desitribution
    114      */
    115     public HypergeometricDistribution createHypergeometricDistribution(
    116         int populationSize, int numberOfSuccesses, int sampleSize) {
    117         return new HypergeometricDistributionImpl(populationSize,
    118             numberOfSuccesses, sampleSize);
    119     }
    120
    121 	/***
    122 	 * Create a new normal distribution with the given mean and standard
    123 	 * deviation.
    124      *
    125 	 * @param mean the mean of the distribution
    126 	 * @param sd standard deviation
    127 	 * @return a new normal distribution
    128 	 */
    129 	public NormalDistribution createNormalDistribution(double mean, double sd) {
    130 		return new NormalDistributionImpl(mean, sd);
    131 	}
    132
    133 	/***
    134 	 * Create a new normal distribution with the mean zero and standard
    135 	 * deviation one.
    136      *
    137 	 * @return a new normal distribution
    138 	 */
    139 	public NormalDistribution createNormalDistribution() {
    140 		return new NormalDistributionImpl();
    141 	}
    142
    143     /***
    144      * Create a new Poisson distribution with poisson parameter lambda.
    145      * <p>
    146      * lambda must be postive; otherwise an
    147      * <code>IllegalArgumentException</code> is thrown.
    148      *
    149      * @param lambda poisson parameter
    150      * @return a new Poisson distribution
    151      * @throws IllegalArgumentException if lambda &le; 0
    152      */
    153     public PoissonDistribution  createPoissonDistribution(double lambda) {
    154         return new PoissonDistributionImpl(lambda);
    155     }
    156
    157 }