numerical-stability

Weird numpy.sum behavior when adding zeros

一曲冷凌霜 提交于 2019-12-04 08:56:13
问题 I understand how mathematically-equivalent arithmentic operations can result in different results due to numerical errors (e.g. summing floats in different orders). However, it surprises me that adding zeros to sum can change the result. I thought that this always holds for floats, no matter what: x + 0. == x . Here's an example. I expected all the lines to be exactly zero. Can anybody please explain why this happens? M = 4 # number of random values Z = 4 # number of additional zeros for i in

Robust atan(y,x) on GLSL for converting XY coordinate to angle

僤鯓⒐⒋嵵緔 提交于 2019-12-03 07:25:12
问题 In GLSL (specifically 3.00 that I'm using), there are two versions of atan() : atan(y_over_x) can only return angles between -PI/2, PI/2, while atan(y/x) can take all 4 quadrants into account so the angle range covers everything from -PI, PI, much like atan2() in C++. I would like to use the second atan to convert XY coordinates to angle. However, atan() in GLSL, besides not able to handle when x = 0 , is not very stable. Especially where x is close to zero, the division can overflow

Weird numpy.sum behavior when adding zeros

ぐ巨炮叔叔 提交于 2019-12-03 01:23:33
I understand how mathematically-equivalent arithmentic operations can result in different results due to numerical errors (e.g. summing floats in different orders). However, it surprises me that adding zeros to sum can change the result. I thought that this always holds for floats, no matter what: x + 0. == x . Here's an example. I expected all the lines to be exactly zero. Can anybody please explain why this happens? M = 4 # number of random values Z = 4 # number of additional zeros for i in range(20): a = np.random.rand(M) b = np.zeros(M+Z) b[:M] = a print a.sum() - b.sum() -4.4408920985e-16

Testing for “double” equality in javascript

懵懂的女人 提交于 2019-11-30 23:21:36
I have translated the experimental C# "float" version of Clipper library to javascript. In the newest sandbox version there is a function IsAlmostEqual which seems to be hard to translate. Double equality cannot be compared using == operator due to numerical stability issues, so this function is needed to handle those issues. -9223372036854775808 - aInt and -9223372036854775808 - bInt are easy to calculate using e.g. BigInteger library, but BitConverter.DoubleToInt64Bits is harder. Any idea how to translate IsAlmostEqual function to javascript? Or specifically how to implement BitConverter

Testing for “double” equality in javascript

落花浮王杯 提交于 2019-11-30 18:11:37
问题 I have translated the experimental C# "float" version of Clipper library to javascript. In the newest sandbox version there is a function IsAlmostEqual which seems to be hard to translate. Double equality cannot be compared using == operator due to numerical stability issues, so this function is needed to handle those issues. -9223372036854775808 - aInt and -9223372036854775808 - bInt are easy to calculate using e.g. BigInteger library, but BitConverter.DoubleToInt64Bits is harder. Any idea

In Python small floats tending to zero

荒凉一梦 提交于 2019-11-29 09:07:22
I have a Bayesian Classifier programmed in Python, the problem is that when I multiply the features probabilities I get VERY small float values like 2.5e-320 or something like that, and suddenly it turns into 0.0. The 0.0 is obviously of no use to me since I must find the "best" class based on which class returns the MAX value (greater value). What would be the best way to deal with this? I thought about finding the exponential portion of the number (-320) and, if it goes too low, multiplying the value by 1e20 or some value like that. But maybe there is a better way? Muhammad Alkarouri What

In Python small floats tending to zero

六月ゝ 毕业季﹏ 提交于 2019-11-28 02:28:09
问题 I have a Bayesian Classifier programmed in Python, the problem is that when I multiply the features probabilities I get VERY small float values like 2.5e-320 or something like that, and suddenly it turns into 0.0. The 0.0 is obviously of no use to me since I must find the "best" class based on which class returns the MAX value (greater value). What would be the best way to deal with this? I thought about finding the exponential portion of the number (-320) and, if it goes too low, multiplying