commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Neidhart <thomas.neidh...@gmail.com>
Subject Re: svn commit: r1533990 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java
Date Mon, 21 Oct 2013 11:01:00 GMT
Ok np, there are other cases where the code could be simplified, I will do
the necessary changes.

Thomas


On Mon, Oct 21, 2013 at 12:05 AM, Phil Steitz <phil.steitz@gmail.com> wrote:

> On 10/20/13 2:27 PM, Thomas Neidhart wrote:
> > On 10/20/2013 11:24 PM, tn@apache.org wrote:
> >> Author: tn
> >> Date: Sun Oct 20 21:24:45 2013
> >> New Revision: 1533990
> >>
> >> URL: http://svn.apache.org/r1533990
> >> Log:
> >> [MATH-1039] Avoid code duplication by calling logDensity itself.
> >>
> >> Modified:
> >>
> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java
> >>
> >> Modified:
> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java
> >> URL:
> http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java?rev=1533990&r1=1533989&r2=1533990&view=diff
> >>
> ==============================================================================
> >> ---
> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java
> (original)
> >> +++
> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java
> Sun Oct 20 21:24:45 2013
> >> @@ -136,24 +136,8 @@ public class BetaDistribution extends Ab
> >>
> >>      /** {@inheritDoc} */
> >>      public double density(double x) {
> >> -        recomputeZ();
> >> -        if (x < 0 || x > 1) {
> >> -            return 0;
> >> -        } else if (x == 0) {
> >> -            if (alpha < 1) {
> >> -                throw new
> NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_0_FOR_SOME_ALPHA,
> alpha, 1, false);
> >> -            }
> >> -            return 0;
> >> -        } else if (x == 1) {
> >> -            if (beta < 1) {
> >> -                throw new
> NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_1_FOR_SOME_BETA,
> beta, 1, false);
> >> -            }
> >> -            return 0;
> >> -        } else {
> >> -            double logX = FastMath.log(x);
> >> -            double log1mX = FastMath.log1p(-x);
> >> -            return FastMath.exp((alpha - 1) * logX + (beta - 1) *
> log1mX - z);
> >> -        }
> >> +        final double logDensity = logDensity(x);
> >> +        return logDensity == Double.NEGATIVE_INFINITY ? 0 :
> FastMath.exp(logDensity);
> >>      }
> >>
> >>      /** {@inheritDoc} **/
> > I did this change for one class, but I propose to do this whereever
> > applicable to avoid code duplication in the distribution classes.
> >
> > WDYT?
>
> Nice catch.  By all means, when code is actually duplicated.  Sorry
> I missed this.
>
> Phil
> >
> > Thomas
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > For additional commands, e-mail: dev-help@commons.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message