You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2012/02/23 00:04:33 UTC
svn commit: r1292572 -
/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java
Author: erans
Date: Wed Feb 22 23:04:32 2012
New Revision: 1292572
URL: http://svn.apache.org/viewvc?rev=1292572&view=rev
Log:
MATH-746
Removed strict equality special case.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java?rev=1292572&r1=1292571&r2=1292572&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java Wed Feb 22 23:04:32 2012
@@ -251,20 +251,16 @@ public class TriangularDistribution exte
@Override
public double inverseCumulativeProbability(double p)
throws OutOfRangeException {
- if (p < 0.0 || p > 1.0) {
+ if (p < 0 || p > 1) {
throw new OutOfRangeException(p, 0, 1);
}
- if (p == 0.0) {
+ if (p == 0) {
return a;
}
- if (p == 1.0) {
+ if (p == 1) {
return b;
}
- final double pc = (c - a) / (b - a);
- if (p == pc) {
- return c;
- }
- if (p < pc) {
+ if (p <= (c - a) / (b - a)) {
return a + FastMath.sqrt(p * (b - a) * (c - a));
}
return b - FastMath.sqrt((1 - p) * (b - a) * (b - c));
Re: svn commit: r1292572 -
/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java
Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
On Thu, Feb 23, 2012 at 08:12:48AM +0100, Dennis Hendriks wrote:
> Hi all,
>
> Now that I look at this code again, should we not attempt to avoid
> divide by zero in case a == b, in this method, and perhaps other
> methods of this class?
>
> Also, looking that the Wikipedia article, at
> http://en.wikipedia.org/wiki/Triangular_distribution (which is
> referenced in the javadoc of this class), "if (p <= (c - a) / (b -
> a))" should become "if (p < (c - a) / (b - a)) " instead. Just to
> keep it consistent with the Wikipedia article...?
Done in revision 1292741.
Gilles
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1292572 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java
Posted by Dennis Hendriks <D....@tue.nl>.
Sébastien Brisard wrote:
> Hi Dennis,
>> Hi all,
>>
>> Now that I look at this code again, should we not attempt to avoid divide by
>> zero in case a == b, in this method, and perhaps other methods of this
>> class?
>>
> I think the constructor takes care of this special case.
>(...)
Yes, you're right.
Dennis
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1292572 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java
Posted by Sébastien Brisard <se...@m4x.org>.
Hi Dennis,
> Hi all,
>
> Now that I look at this code again, should we not attempt to avoid divide by
> zero in case a == b, in this method, and perhaps other methods of this
> class?
>
I think the constructor takes care of this special case.
>
> Also, looking that the Wikipedia article, at
> http://en.wikipedia.org/wiki/Triangular_distribution (which is referenced in
> the javadoc of this class), "if (p <= (c - a) / (b - a))" should become "if
> (p < (c - a) / (b - a)) " instead. Just to keep it consistent with the
> Wikipedia article...?
>
> Best regards,
> Dennis
>
I really have no opinion on this subject.
Sébastien
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1292572 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java
Posted by Dennis Hendriks <D....@tue.nl>.
Hi all,
Now that I look at this code again, should we not attempt to avoid divide
by zero in case a == b, in this method, and perhaps other methods of this
class?
Also, looking that the Wikipedia article, at
http://en.wikipedia.org/wiki/Triangular_distribution (which is referenced
in the javadoc of this class), "if (p <= (c - a) / (b - a))" should become
"if (p < (c - a) / (b - a)) " instead. Just to keep it consistent with the
Wikipedia article...?
Best regards,
Dennis
erans@apache.org wrote:
> Author: erans
> Date: Wed Feb 22 23:04:32 2012
> New Revision: 1292572
>
> URL: http://svn.apache.org/viewvc?rev=1292572&view=rev
> Log:
> MATH-746
> Removed strict equality special case.
>
> Modified:
> commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java
>
> Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java?rev=1292572&r1=1292571&r2=1292572&view=diff
> ==============================================================================
> --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java (original)
> +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/distribution/TriangularDistribution.java Wed Feb 22 23:04:32 2012
> @@ -251,20 +251,16 @@ public class TriangularDistribution exte
> @Override
> public double inverseCumulativeProbability(double p)
> throws OutOfRangeException {
> - if (p < 0.0 || p > 1.0) {
> + if (p < 0 || p > 1) {
> throw new OutOfRangeException(p, 0, 1);
> }
> - if (p == 0.0) {
> + if (p == 0) {
> return a;
> }
> - if (p == 1.0) {
> + if (p == 1) {
> return b;
> }
> - final double pc = (c - a) / (b - a);
> - if (p == pc) {
> - return c;
> - }
> - if (p < pc) {
> + if (p <= (c - a) / (b - a)) {
> return a + FastMath.sqrt(p * (b - a) * (c - a));
> }
> return b - FastMath.sqrt((1 - p) * (b - a) * (b - c));
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org