laziness, impatience, and hubris PerlMonks

### Re^2: Calculate log of matrix values

by BillKSmith (Priest)
 on Aug 09, 2013 at 18:07 UTC ( #1048815=note: print w/replies, xml ) Need Help??

in reply to Re: Calculate log of matrix values
in thread Calculate log of matrix values

The POSIX HUGE_VAL would be closer to the mathamatical concept. It would never be mistaken for "unassigned". Attempts to use it in an expression would always throw an exception. A huge negative would be even better, but we do not seem to have that option.
Bill

Replies are listed 'Best First'.
Re^3: Calculate log of matrix values
by BrowserUk (Pope) on Aug 09, 2013 at 19:04 UTC
Attempts to use it in an expression would always throw an exception.

I think you've misunderstood my post. If I wanted to causes exceptions, I'd leave the zeros in place. or replace them with #NaN.

My point was that by replacing the zeros with a very, very small number, you can avoid exceptions, or the need for conditional tests to avoid exceptions, as it will allow most calculations to operate correctly whilst introducing negligible changes to the final results.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
I did misunderstand your intention. However I still do not understand your solution. If I assume that the zero data is really a small positive number that displays as '0.00', its log should be a negative number whose magnatude exceeds any of the other logs. (e.g. log(0.001) = -6.9) Setting the log to zero assumes that the raw value is e (2.71...). Note: All other values are between .001 (log(.01) = -4.6) and .99 (log(.99) = -.01).
Bill
Setting the log to zero ...

I didn't suggest setting the log to zero. Or mention doing anything to the logs.

its log should be a negative number whose magnatude exceeds any of the other logs.

And if you set values that are 0(.00000) to 1e-308, then when their logs are taken, they become

```say log(1e-308);;
-709.196208642166

which fulfills your "negative number whose magnatude exceeds any of the other logs." in spades.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Calculate log of matrix values
by choroba (Chancellor) on Aug 09, 2013 at 18:13 UTC
HUGE_VAL does not help here, we need kind of a TINY_VAL. 1 / HUGE_VAL does not work:
```
\$ perl -MPOSIX=HUGE_VAL -e 'print log(1 / HUGE_VAL)'
Can't take log of 0 at -e line 1.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Create A New User
Node Status?
node history
Node Type: note [id://1048815]
help
Chatterbox?
 [Corion]: LanX: Then the problem should persist without encoding to base64 too ;) [LanX]: I think it's a flag problem ... I'll produce a reprodocable example for SOPW [Corion]: "flag problem" to me sounds like "contains UTF-8 bytes but was never properly decoded to an UTF-8 string" [LanX]: not my code ... [choroba]: yeah, sounds like one of the strings is not flagged as UTF-8 [choroba]: which usually means its input wasn't handled correctly [Corion]: choroba: Yeah, I think that would be the good solution [LanX]: I suspect the first string which comes from the DB ... [LanX]: ... but this part is already in production for a year now [Corion]: LanX: The "good" approach here would be to use the appropriate DBI parameters to make the driver decode strings properly. But that will have a ripple-on effect of messing up all the places where manual decoding happens ;)

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2017-01-16 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Do you watch meteor showers?

Results (150 votes). Check out past polls.