About largestExponentArgument

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

About largestExponentArgument

Nicolas Cellier
DhbFloatingPointMachine new largestExponentArgument usage is questionable.

Thanks to gradual underflow, there is a dissymetry between the exponent of smallest Float we can represent and that of the largest Float.

Float fmin -> 5.0e-324.
Float fmax -> 1.7976931348623157e308.

Float fmin exponent -> -1074 (that is Float emin - Float precision + 1)
Float fmax exponent -> 1023 (that is Float emax)

Thus we can find a Float x smaller than
DhbFloatingPointMachine new largestExponentArgument negated
for which the exponent is still not zero.
For example:

self deny: DhbFloatingPointMachine new largestExponentArgument negated predecessor exp isZero

We could eventually use:

DhbFloatingPointMachine new smallestExponentArgument
computed as Float fmin ln ->  -744.4400719213812

But are we going to need it?

This is used for example in:

DhbFisherTippettDistribution>>distributionValue: aNumber
        "Answers the probability of observing a random variable distributed according to
         the receiver with a value lower than or equal to aNumber."
    | arg |
    arg := ( aNumber - alpha) / beta.
    arg := arg < DhbFloatingPointMachine new largestExponentArgument negated
                    ifTrue: [ ^0]
                    ifFalse:[arg negated exp].
    ^arg negated exp

But this code is false... It should return 1 not 0 !
So even better is to not bother at all and let the floating point underflow take care of it:

DhbFisherTippettDistribution>>distributionValue: aNumber
        "Answers the probability of observing a random variable distributed according to
         the receiver with a value lower than or equal to aNumber."
    | arg |
    arg := ( aNumber - alpha) / beta.
    ^arg negated exp negated exp

for the density, we should simply write:

value: aNumber
        "Answers the probability that a random variable distributed according to the receiver
         gives a value between aNumber and aNumber + espilon (infinitesimal interval)."
    | arg |
    arg := ( aNumber - alpha) / beta.
    ^(arg negated exp + arg) negated exp : beta

--
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: About largestExponentArgument

Nicolas Cellier


2016-05-04 15:30 GMT+02:00 Nicolas Cellier <[hidden email]>:
DhbFloatingPointMachine new largestExponentArgument usage is questionable.

Thanks to gradual underflow, there is a dissymetry between the exponent of smallest Float we can represent and that of the largest Float.

Float fmin -> 5.0e-324.
Float fmax -> 1.7976931348623157e308.

Float fmin exponent -> -1074 (that is Float emin - Float precision + 1)
Float fmax exponent -> 1023 (that is Float emax)

Thus we can find a Float x smaller than
DhbFloatingPointMachine new largestExponentArgument negated
for which the exponent is still not zero.
For example:

self deny: DhbFloatingPointMachine new largestExponentArgument negated predecessor exp isZero

We could eventually use:

DhbFloatingPointMachine new smallestExponentArgument
computed as Float fmin ln ->  -744.4400719213812

But are we going to need it?

This is used for example in:

DhbFisherTippettDistribution>>distributionValue: aNumber
        "Answers the probability of observing a random variable distributed according to
         the receiver with a value lower than or equal to aNumber."
    | arg |
    arg := ( aNumber - alpha) / beta.
    arg := arg < DhbFloatingPointMachine new largestExponentArgument negated
                    ifTrue: [ ^0]
                    ifFalse:[arg negated exp].
    ^arg negated exp
 
But this code is false... It should return 1 not 0 !
So even better is to not bother at all and let the floating point underflow take care of it:

DhbFisherTippettDistribution>>distributionValue: aNumber
        "Answers the probability of observing a random variable distributed according to
         the receiver with a value lower than or equal to aNumber."
    | arg |
    arg := ( aNumber - alpha) / beta.
    ^arg negated exp negated exp
 
for the density, we should simply write:

value: aNumber
        "Answers the probability that a random variable distributed according to the receiver
         gives a value between aNumber and aNumber + espilon (infinitesimal interval)."
    | arg |
    arg := ( aNumber - alpha) / beta.
    ^(arg negated exp + arg) negated exp : beta



Ah my bad, sorry, it sounds like I completely miss-understood the code.
arg negated exp negated exp may indeed fail when arg is very negative, so the code was perfectly correct.
Just throw this message in the trash bin :)

--
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: About largestExponentArgument

Nicolas Cellier
Nonetheless, on Smalltalk dialects that handle floatint point overflow the IEEE 754 way by answering infinity like Squeak/Pharo, we can use simple formula.

-1000 negated exp negated exp -> 0 (thru Float infinity negated exp)

Maybe the guard is only for old versions of VisualWorks which triggered a floating point exception on overflow...

2016-05-04 15:59 GMT+02:00 Nicolas Cellier <[hidden email]>:


2016-05-04 15:30 GMT+02:00 Nicolas Cellier <[hidden email]>:
DhbFloatingPointMachine new largestExponentArgument usage is questionable.

Thanks to gradual underflow, there is a dissymetry between the exponent of smallest Float we can represent and that of the largest Float.

Float fmin -> 5.0e-324.
Float fmax -> 1.7976931348623157e308.

Float fmin exponent -> -1074 (that is Float emin - Float precision + 1)
Float fmax exponent -> 1023 (that is Float emax)

Thus we can find a Float x smaller than
DhbFloatingPointMachine new largestExponentArgument negated
for which the exponent is still not zero.
For example:

self deny: DhbFloatingPointMachine new largestExponentArgument negated predecessor exp isZero

We could eventually use:

DhbFloatingPointMachine new smallestExponentArgument
computed as Float fmin ln ->  -744.4400719213812

But are we going to need it?

This is used for example in:

DhbFisherTippettDistribution>>distributionValue: aNumber
        "Answers the probability of observing a random variable distributed according to
         the receiver with a value lower than or equal to aNumber."
    | arg |
    arg := ( aNumber - alpha) / beta.
    arg := arg < DhbFloatingPointMachine new largestExponentArgument negated
                    ifTrue: [ ^0]
                    ifFalse:[arg negated exp].
    ^arg negated exp
 
But this code is false... It should return 1 not 0 !
So even better is to not bother at all and let the floating point underflow take care of it:

DhbFisherTippettDistribution>>distributionValue: aNumber
        "Answers the probability of observing a random variable distributed according to
         the receiver with a value lower than or equal to aNumber."
    | arg |
    arg := ( aNumber - alpha) / beta.
    ^arg negated exp negated exp
 
for the density, we should simply write:

value: aNumber
        "Answers the probability that a random variable distributed according to the receiver
         gives a value between aNumber and aNumber + espilon (infinitesimal interval)."
    | arg |
    arg := ( aNumber - alpha) / beta.
    ^(arg negated exp + arg) negated exp : beta



Ah my bad, sorry, it sounds like I completely miss-understood the code.
arg negated exp negated exp may indeed fail when arg is very negative, so the code was perfectly correct.
Just throw this message in the trash bin :)

--
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: About largestExponentArgument

stepharo
In reply to this post by Nicolas Cellier

Hi nicolas


I do not understand what you are saying but I trust you :).

Can you publish a fixed version so that we improve Polymath.

My participation to Polymath is at the meta level (package, QA) but I cannot fix what I do not understand.

Stef

Le 4/5/16 à 15:30, Nicolas Cellier a écrit :
DhbFloatingPointMachine new largestExponentArgument usage is questionable.

Thanks to gradual underflow, there is a dissymetry between the exponent of smallest Float we can represent and that of the largest Float.

Float fmin -> 5.0e-324.
Float fmax -> 1.7976931348623157e308.

Float fmin exponent -> -1074 (that is Float emin - Float precision + 1)
Float fmax exponent -> 1023 (that is Float emax)

Thus we can find a Float x smaller than
DhbFloatingPointMachine new largestExponentArgument negated
for which the exponent is still not zero.
For example:

self deny: DhbFloatingPointMachine new largestExponentArgument negated predecessor exp isZero

We could eventually use:

DhbFloatingPointMachine new smallestExponentArgument
computed as Float fmin ln ->  -744.4400719213812

But are we going to need it?

This is used for example in:

DhbFisherTippettDistribution>>distributionValue: aNumber
        "Answers the probability of observing a random variable distributed according to
         the receiver with a value lower than or equal to aNumber."
    | arg |
    arg := ( aNumber - alpha) / beta.
    arg := arg < DhbFloatingPointMachine new largestExponentArgument negated
                    ifTrue: [ ^0]
                    ifFalse:[arg negated exp].
    ^arg negated exp

But this code is false... It should return 1 not 0 !
So even better is to not bother at all and let the floating point underflow take care of it:

DhbFisherTippettDistribution>>distributionValue: aNumber
        "Answers the probability of observing a random variable distributed according to
         the receiver with a value lower than or equal to aNumber."
    | arg |
    arg := ( aNumber - alpha) / beta.
    ^arg negated exp negated exp

for the density, we should simply write:

value: aNumber
        "Answers the probability that a random variable distributed according to the receiver
         gives a value between aNumber and aNumber + espilon (infinitesimal interval)."
    | arg |
    arg := ( aNumber - alpha) / beta.
    ^(arg negated exp + arg) negated exp : beta

--
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.