You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2009/10/28 22:53:36 UTC

svn commit: r830771 - in /commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution: BinomialDistributionImpl.java HypergeometricDistributionImpl.java PoissonDistributionImpl.java SaddlePointExpansion.java

Author: luc
Date: Wed Oct 28 21:53:35 2009
New Revision: 830771

URL: http://svn.apache.org/viewvc?rev=830771&view=rev
Log:
fixed checkstyle errors

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/SaddlePointExpansion.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java?rev=830771&r1=830770&r2=830771&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java Wed Oct 28 21:53:35 2009
@@ -1,15 +1,18 @@
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 package org.apache.commons.math.distribution;
 
@@ -18,13 +21,11 @@
 import org.apache.commons.math.MathException;
 import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.special.Beta;
-import org.apache.commons.math.util.MathUtils;
 
 /**
  * The default implementation of {@link BinomialDistribution}.
- * 
- * @version $Revision$ $Date: 2009-09-05 12:36:48 -0500 (Sat, 05 Sep
- *          2009) $
+ *
+ * @version $Revision$ $Date$
  */
 public class BinomialDistributionImpl extends AbstractIntegerDistribution
         implements BinomialDistribution, Serializable {
@@ -41,7 +42,7 @@
     /**
      * Create a binomial distribution with the given number of trials and
      * probability of success.
-     * 
+     *
      * @param trials the number of trials.
      * @param p the probability of success.
      */
@@ -53,7 +54,7 @@
 
     /**
      * Access the number of trials for this distribution.
-     * 
+     *
      * @return the number of trials.
      */
     public int getNumberOfTrials() {
@@ -62,7 +63,7 @@
 
     /**
      * Access the probability of success for this distribution.
-     * 
+     *
      * @return the probability of success.
      */
     public double getProbabilityOfSuccess() {
@@ -71,7 +72,7 @@
 
     /**
      * Change the number of trials for this distribution.
-     * 
+     *
      * @param trials the new number of trials.
      * @throws IllegalArgumentException if <code>trials</code> is not a valid
      *             number of trials.
@@ -86,7 +87,7 @@
 
     /**
      * Change the probability of success for this distribution.
-     * 
+     *
      * @param p the new probability of success.
      * @throws IllegalArgumentException if <code>p</code> is not a valid
      *             probability.
@@ -102,7 +103,7 @@
     /**
      * Access the domain value lower bound, based on <code>p</code>, used to
      * bracket a PDF root.
-     * 
+     *
      * @param p the desired probability for the critical value
      * @return domain value lower bound, i.e. P(X &lt; <i>lower bound</i>) &lt;
      *         <code>p</code>
@@ -115,7 +116,7 @@
     /**
      * Access the domain value upper bound, based on <code>p</code>, used to
      * bracket a PDF root.
-     * 
+     *
      * @param p the desired probability for the critical value
      * @return domain value upper bound, i.e. P(X &lt; <i>upper bound</i>) &gt;
      *         <code>p</code>
@@ -127,7 +128,7 @@
 
     /**
      * For this distribution, X, this method returns P(X &le; x).
-     * 
+     *
      * @param x the value at which the PDF is evaluated.
      * @return PDF for this distribution.
      * @throws MathException if the cumulative probability can not be computed
@@ -149,7 +150,7 @@
 
     /**
      * For this distribution, X, this method returns P(X = x).
-     * 
+     *
      * @param x the value at which the PMF is evaluated.
      * @return PMF for this distribution.
      */
@@ -172,7 +173,7 @@
      * Returns <code>-1</code> for p=0 and <code>Integer.MAX_VALUE</code> for
      * p=1.
      * </p>
-     * 
+     *
      * @param p the desired probability
      * @return the largest x such that P(X &le; x) <= p
      * @throws MathException if the inverse cumulative probability can not be

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java?rev=830771&r1=830770&r2=830771&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java Wed Oct 28 21:53:35 2009
@@ -1,15 +1,18 @@
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 package org.apache.commons.math.distribution;
@@ -21,9 +24,8 @@
 
 /**
  * The default implementation of {@link HypergeometricDistribution}.
- * 
- * @version $Revision$ $Date: 2009-09-05 12:36:48 -0500 (Sat, 05 Sep
- *          2009) $
+ *
+ * @version $Revision$ $Date$
  */
 public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
         implements HypergeometricDistribution, Serializable {
@@ -43,7 +45,7 @@
     /**
      * Construct a new hypergeometric distribution with the given the population
      * size, the number of successes in the population, and the sample size.
-     * 
+     *
      * @param populationSize the population size.
      * @param numberOfSuccesses number of successes in the population.
      * @param sampleSize the sample size.
@@ -70,7 +72,7 @@
 
     /**
      * For this distribution, X, this method returns P(X &le; x).
-     * 
+     *
      * @param x the value at which the PDF is evaluated.
      * @return PDF for this distribution.
      */
@@ -96,7 +98,7 @@
 
     /**
      * Return the domain for the given hypergeometric distribution parameters.
-     * 
+     *
      * @param n the population size.
      * @param m number of successes in the population.
      * @param k the sample size.
@@ -110,7 +112,7 @@
     /**
      * Access the domain value lower bound, based on <code>p</code>, used to
      * bracket a PDF root.
-     * 
+     *
      * @param p the desired probability for the critical value
      * @return domain value lower bound, i.e. P(X &lt; <i>lower bound</i>) &lt;
      *         <code>p</code>
@@ -124,7 +126,7 @@
     /**
      * Access the domain value upper bound, based on <code>p</code>, used to
      * bracket a PDF root.
-     * 
+     *
      * @param p the desired probability for the critical value
      * @return domain value upper bound, i.e. P(X &lt; <i>upper bound</i>) &gt;
      *         <code>p</code>
@@ -137,7 +139,7 @@
     /**
      * Return the lowest domain value for the given hypergeometric distribution
      * parameters.
-     * 
+     *
      * @param n the population size.
      * @param m number of successes in the population.
      * @param k the sample size.
@@ -149,7 +151,7 @@
 
     /**
      * Access the number of successes.
-     * 
+     *
      * @return the number of successes.
      */
     public int getNumberOfSuccesses() {
@@ -158,7 +160,7 @@
 
     /**
      * Access the population size.
-     * 
+     *
      * @return the population size.
      */
     public int getPopulationSize() {
@@ -167,7 +169,7 @@
 
     /**
      * Access the sample size.
-     * 
+     *
      * @return the sample size.
      */
     public int getSampleSize() {
@@ -177,7 +179,7 @@
     /**
      * Return the highest domain value for the given hypergeometric distribution
      * parameters.
-     * 
+     *
      * @param m number of successes in the population.
      * @param k the sample size.
      * @return the highest domain value of the hypergeometric distribution.
@@ -188,7 +190,7 @@
 
     /**
      * For this distribution, X, this method returns P(X = x).
-     * 
+     *
      * @param x the value at which the PMF is evaluated.
      * @return PMF for this distribution.
      */
@@ -208,10 +210,10 @@
             double q = (double) (m - sampleSize) / (double) m;
             double p1 = SaddlePointExpansion.logBinomialProbability(x,
                     numberOfSuccesses, p, q);
-            double p2 = SaddlePointExpansion.logBinomialProbability(sampleSize
-                    - x, f, p, q);
-            double p3 = SaddlePointExpansion.logBinomialProbability(sampleSize,
-                    m, p, q);
+            double p2 =
+                SaddlePointExpansion.logBinomialProbability(sampleSize - x, f, p, q);
+            double p3 =
+                SaddlePointExpansion.logBinomialProbability(sampleSize, m, p, q);
             ret = Math.exp(p1 + p2 - p3);
         }
 
@@ -221,7 +223,7 @@
     /**
      * For the distribution, X, defined by the given hypergeometric distribution
      * parameters, this method returns P(X = x).
-     * 
+     *
      * @param n the population size.
      * @param m number of successes in the population.
      * @param k the sample size.
@@ -229,14 +231,14 @@
      * @return PMF for the distribution.
      */
     private double probability(int n, int m, int k, int x) {
-        return Math.exp(MathUtils.binomialCoefficientLog(m, x)
-                + MathUtils.binomialCoefficientLog(n - m, k - x)
-                - MathUtils.binomialCoefficientLog(n, k));
+        return Math.exp(MathUtils.binomialCoefficientLog(m, x) +
+               MathUtils.binomialCoefficientLog(n - m, k - x) -
+               MathUtils.binomialCoefficientLog(n, k));
     }
 
     /**
      * Modify the number of successes.
-     * 
+     *
      * @param num the new number of successes.
      * @throws IllegalArgumentException if <code>num</code> is negative.
      */
@@ -250,7 +252,7 @@
 
     /**
      * Modify the population size.
-     * 
+     *
      * @param size the new population size.
      * @throws IllegalArgumentException if <code>size</code> is not positive.
      */
@@ -264,7 +266,7 @@
 
     /**
      * Modify the sample size.
-     * 
+     *
      * @param size the new sample size.
      * @throws IllegalArgumentException if <code>size</code> is negative.
      */
@@ -278,7 +280,7 @@
 
     /**
      * For this distribution, X, this method returns P(X &ge; x).
-     * 
+     *
      * @param x the value at which the CDF is evaluated.
      * @return upper tail CDF for this distribution.
      * @since 1.1
@@ -306,7 +308,7 @@
      * For this distribution, X, this method returns P(x0 &le; X &le; x1). This
      * probability is computed by summing the point probabilities for the values
      * x0, x0 + 1, x0 + 2, ..., x1, in the order directed by dx.
-     * 
+     *
      * @param x0 the inclusive, lower bound
      * @param x1 the inclusive, upper bound
      * @param dx the direction of summation. 1 indicates summing from x0 to x1.

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java?rev=830771&r1=830770&r2=830771&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java Wed Oct 28 21:53:35 2009
@@ -1,15 +1,18 @@
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 package org.apache.commons.math.distribution;
 
@@ -22,9 +25,8 @@
 
 /**
  * Implementation for the {@link PoissonDistribution}.
- * 
- * @version $Revision$ $Date: 2009-09-05 12:36:48 -0500 (Sat, 05 Sep
- *          2009) $
+ *
+ * @version $Revision$ $Date$
  */
 public class PoissonDistributionImpl extends AbstractIntegerDistribution
         implements PoissonDistribution, Serializable {
@@ -43,7 +45,7 @@
     /**
      * Create a new Poisson distribution with the given the mean. The mean value
      * must be positive; otherwise an <code>IllegalArgument</code> is thrown.
-     * 
+     *
      * @param p the Poisson mean
      * @throws IllegalArgumentException if p &le; 0
      */
@@ -54,7 +56,7 @@
     /**
      * Create a new Poisson distribution with the given the mean. The mean value
      * must be positive; otherwise an <code>IllegalArgument</code> is thrown.
-     * 
+     *
      * @param p the Poisson mean
      * @param z a normal distribution used to compute normal approximations.
      * @throws IllegalArgumentException if p &le; 0
@@ -68,7 +70,7 @@
 
     /**
      * Get the Poisson mean for the distribution.
-     * 
+     *
      * @return the Poisson mean for the distribution.
      */
     public double getMean() {
@@ -78,7 +80,7 @@
     /**
      * Set the Poisson mean for the distribution. The mean value must be
      * positive; otherwise an <code>IllegalArgument</code> is thrown.
-     * 
+     *
      * @param p the Poisson mean value
      * @throws IllegalArgumentException if p &le; 0
      */
@@ -94,7 +96,7 @@
 
     /**
      * The probability mass function P(X = x) for a Poisson distribution.
-     * 
+     *
      * @param x the value at which the probability density function is
      *            evaluated.
      * @return the value of the probability mass function at x
@@ -106,10 +108,9 @@
         } else if (x == 0) {
             ret = Math.exp(-mean);
         } else {
-            ret = Math.exp(-SaddlePointExpansion.getStirlingError(x)
-                    - SaddlePointExpansion.getDeviancePart(x, mean))
-                    / Math.sqrt(2.0 * Math.PI * x); // TODO make MathUtils.PI
-                                                    // public
+            ret = Math.exp(-SaddlePointExpansion.getStirlingError(x) -
+                  SaddlePointExpansion.getDeviancePart(x, mean)) /
+                  Math.sqrt(MathUtils.TWO_PI * x);
         }
         return ret;
     }
@@ -117,7 +118,7 @@
     /**
      * The probability distribution function P(X <= x) for a Poisson
      * distribution.
-     * 
+     *
      * @param x the value at which the PDF is evaluated.
      * @return Poisson distribution function evaluated at x
      * @throws MathException if the cumulative probability can not be computed
@@ -143,7 +144,7 @@
      * The computation uses "half-correction" -- evaluating the normal
      * distribution function at <code>x + 0.5</code>
      * </p>
-     * 
+     *
      * @param x the upper bound, inclusive
      * @return the distribution function value calculated using a normal
      *         approximation
@@ -159,7 +160,7 @@
      * Access the domain value lower bound, based on <code>p</code>, used to
      * bracket a CDF root. This method is used by
      * {@link #inverseCumulativeProbability(double)} to find critical values.
-     * 
+     *
      * @param p the desired probability for the critical value
      * @return domain lower bound
      */
@@ -172,7 +173,7 @@
      * Access the domain value upper bound, based on <code>p</code>, used to
      * bracket a CDF root. This method is used by
      * {@link #inverseCumulativeProbability(double)} to find critical values.
-     * 
+     *
      * @param p the desired probability for the critical value
      * @return domain upper bound
      */
@@ -185,7 +186,7 @@
      * Modify the normal distribution used to compute normal approximations. The
      * caller is responsible for insuring the normal distribution has the proper
      * parameter settings.
-     * 
+     *
      * @param value the new distribution
      * @since 1.2
      */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/SaddlePointExpansion.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/SaddlePointExpansion.java?rev=830771&r1=830770&r2=830771&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/SaddlePointExpansion.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/SaddlePointExpansion.java Wed Oct 28 21:53:35 2009
@@ -1,6 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.commons.math.distribution;
 
 import org.apache.commons.math.special.Gamma;
+import org.apache.commons.math.util.MathUtils;
 
 /**
  * <p>
@@ -21,19 +38,16 @@
  * http://www.herine.net/stat/papers/dbinom.pdf</a></li>
  * </ol>
  * </p>
- * 
- * @since 1.2
- * @version $Revision: 1.3 $ $Date: 2007/11/18 23:51:21 $
+ *
+ * @since 2.1
+ * @version $Revision$ $Date$
  */
 final class SaddlePointExpansion {
 
-    /** 2 &#960;. */
-    private static double PI_2 = 2.0 * Math.PI;
-
     /** 1/2 * log(2 &#960;). */
-    private static double HALF_LOG_2_PI = 0.5 * Math.log(PI_2);
+    private static double HALF_LOG_2_PI = 0.5 * Math.log(MathUtils.TWO_PI);
 
-    /** exact striling expansion error for certain values. */
+    /** exact Stirling expansion error for certain values. */
     private static final double[] EXACT_STIRLING_ERRORS = { 0.0, /* 0.0 */
     0.1534264097200273452913848, /* 0.5 */
     0.0810614667953272582196702, /* 1.0 */
@@ -85,7 +99,7 @@
      * http://mathworld.wolfram.com/StirlingsSeries.html</a></li>
      * </ol>
      * </p>
-     * 
+     *
      * @param z the value.
      * @return the Striling's series error.
      */
@@ -96,16 +110,17 @@
             if (Math.floor(z2) == z2) {
                 ret = EXACT_STIRLING_ERRORS[(int) z2];
             } else {
-                ret = Gamma.logGamma(z + 1.0) - (z + 0.5) * Math.log(z) + z
-                        - HALF_LOG_2_PI;
+                ret = Gamma.logGamma(z + 1.0) - (z + 0.5) * Math.log(z) +
+                      z - HALF_LOG_2_PI;
             }
         } else {
             double z2 = z * z;
-            ret = (0.083333333333333333333 - (0.00277777777777777777778 - (0.00079365079365079365079365 - (0.000595238095238095238095238 - 0.0008417508417508417508417508 / z2)
-                    / z2)
-                    / z2)
-                    / z2)
-                    / z;
+            ret = (0.083333333333333333333 -
+                    (0.00277777777777777777778 -
+                            (0.00079365079365079365079365 -
+                                    (0.000595238095238095238095238 -
+                                            0.0008417508417508417508417508 /
+                                            z2) / z2) / z2) / z2) / z;
         }
         return ret;
     }
@@ -121,7 +136,7 @@
      * http://www.herine.net/stat/papers/dbinom.pdf</a></li>
      * </ol>
      * </p>
-     * 
+     *
      * @param x the x value.
      * @param mu the average.
      * @return a part of the deviance.
@@ -129,7 +144,7 @@
     static double getDeviancePart(double x, double mu) {
         double ret;
         if (Math.abs(x - mu) < 0.1 * (x + mu)) {
-            double d = (x - mu);
+            double d = x - mu;
             double v = d / (x + mu);
             double s1 = v * d;
             double s = Double.NaN;
@@ -152,7 +167,7 @@
     /**
      * Compute the PMF for a binomial distribution using the saddle point
      * expansion.
-     * 
+     *
      * @param x the value at which the probability is evaluated.
      * @param n the number of trials.
      * @param p the probability of success.
@@ -174,10 +189,10 @@
                 ret = n * Math.log(p);
             }
         } else {
-            ret = getStirlingError(n) - getStirlingError(x)
-                    - getStirlingError(n - x) - getDeviancePart(x, n * p)
-                    - getDeviancePart(n - x, n * q);
-            double f = (PI_2 * x * (n - x)) / n;
+            ret = getStirlingError(n) - getStirlingError(x) -
+                  getStirlingError(n - x) - getDeviancePart(x, n * p) -
+                  getDeviancePart(n - x, n * q);
+            double f = (MathUtils.TWO_PI * x * (n - x)) / n;
             ret = -0.5 * Math.log(f) + ret;
         }
         return ret;