1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.commons.math.distribution; 18 19 /** 20 * A concrete distribution factory. This is the default factory used by 21 * Commons-Math. 22 * 23 * @version $Revision: 545192 $ $Date: 2007-06-07 07:35:04 -0700 (Thu, 07 Jun 2007) $ 24 * @deprecated pluggability of distribution instances is now provided through 25 * constructors and setters. 26 */ 27 public class DistributionFactoryImpl extends DistributionFactory { 28 29 /** 30 * Default constructor. Package scope to prevent unwanted instantiation. 31 */ 32 public DistributionFactoryImpl() { 33 super(); 34 } 35 36 /** 37 * Create a new chi-square distribution with the given degrees of freedom. 38 * 39 * @param degreesOfFreedom degrees of freedom 40 * @return a new chi-square distribution 41 */ 42 public ChiSquaredDistribution createChiSquareDistribution( 43 final double degreesOfFreedom) { 44 45 return new ChiSquaredDistributionImpl(degreesOfFreedom); 46 } 47 48 /** 49 * Create a new gamma distribution the given shape and scale parameters. 50 * 51 * @param alpha the shape parameter 52 * @param beta the scale parameter 53 * @return a new gamma distribution 54 */ 55 public GammaDistribution createGammaDistribution( 56 double alpha, double beta) { 57 58 return new GammaDistributionImpl(alpha, beta); 59 } 60 61 /** 62 * Create a new t distribution with the given degrees of freedom. 63 * 64 * @param degreesOfFreedom degrees of freedom 65 * @return a new t distribution. 66 */ 67 public TDistribution createTDistribution(double degreesOfFreedom) { 68 return new TDistributionImpl(degreesOfFreedom); 69 } 70 71 /** 72 * Create a new F-distribution with the given degrees of freedom. 73 * 74 * @param numeratorDegreesOfFreedom numerator degrees of freedom 75 * @param denominatorDegreesOfFreedom denominator degrees of freedom 76 * @return a new F-distribution 77 */ 78 public FDistribution createFDistribution( 79 double numeratorDegreesOfFreedom, 80 double denominatorDegreesOfFreedom) { 81 return new FDistributionImpl(numeratorDegreesOfFreedom, 82 denominatorDegreesOfFreedom); 83 } 84 85 /** 86 * Create a new exponential distribution with the given degrees of freedom. 87 * 88 * @param mean mean 89 * @return a new exponential distribution 90 */ 91 public ExponentialDistribution createExponentialDistribution(double mean) { 92 return new ExponentialDistributionImpl(mean); 93 } 94 95 /** 96 * Create a binomial distribution with the given number of trials and 97 * probability of success. 98 * 99 * @param numberOfTrials the number of trials 100 * @param probabilityOfSuccess the probability of success 101 * @return a new binomial distribution 102 */ 103 public BinomialDistribution createBinomialDistribution( 104 int numberOfTrials, double probabilityOfSuccess) { 105 return new BinomialDistributionImpl(numberOfTrials, 106 probabilityOfSuccess); 107 } 108 109 /** 110 * Create a new hypergeometric distribution with the given the population 111 * size, the number of successes in the population, and the sample size. 112 * 113 * @param populationSize the population size 114 * @param numberOfSuccesses number of successes in the population 115 * @param sampleSize the sample size 116 * @return a new hypergeometric desitribution 117 */ 118 public HypergeometricDistribution createHypergeometricDistribution( 119 int populationSize, int numberOfSuccesses, int sampleSize) { 120 return new HypergeometricDistributionImpl(populationSize, 121 numberOfSuccesses, sampleSize); 122 } 123 124 /** 125 * Create a new normal distribution with the given mean and standard 126 * deviation. 127 * 128 * @param mean the mean of the distribution 129 * @param sd standard deviation 130 * @return a new normal distribution 131 */ 132 public NormalDistribution createNormalDistribution(double mean, double sd) { 133 return new NormalDistributionImpl(mean, sd); 134 } 135 136 /** 137 * Create a new normal distribution with the mean zero and standard 138 * deviation one. 139 * 140 * @return a new normal distribution 141 */ 142 public NormalDistribution createNormalDistribution() { 143 return new NormalDistributionImpl(); 144 } 145 146 /** 147 * Create a new Poisson distribution with poisson parameter lambda. 148 * <p> 149 * lambda must be postive; otherwise an 150 * <code>IllegalArgumentException</code> is thrown. 151 * 152 * @param lambda poisson parameter 153 * @return a new Poisson distribution 154 * @throws IllegalArgumentException if lambda ≤ 0 155 */ 156 public PoissonDistribution createPoissonDistribution(double lambda) { 157 return new PoissonDistributionImpl(lambda); 158 } 159 }