floating point - Handling large numbers and precision of Ricean Fading PDF python -
i'm trying calculate ricean fading pdf using following equation. ricean fading pdf. 'y' normalized envelope , 'gamma' snr
if k value large,
math.exp(-((1.+_gamma)*pow(_y,2.) + _gamma))
exp results in big floating point (e.q. 1.01e-5088). in python shows '0.0' value
mpmath.besseli(0,2. * _y * np.sqrt(_gamma * (1. + _gamma)))
the value of bessel function shows big int value (e.q. 7.78e+5092). in python shows '**inf**' value
how can store big integer , floating point value in python , calculate pdf?
def rice_pdf(self, _y, _gamma): return 2. * _y * (1. + _gamma) * math.exp(-((1.+_gamma)*pow(_y,2.) + _gamma)) * special.i0(2. * _y * np.sqrt(_gamma * (1. + _gamma)))
thanks.
if have way compute logarithm of bessel function, can avoid multiplication of large , small numbers transforming summation subsequent exonentiation, should solve numerical problems (exploit fact exp(a) * exp(b) == exp(a + b)
).
def rice_pdf(_y, _gamma): = np.log(2. * _y * (1. + _gamma)) b = -((1.+_gamma)*pow(_y,2.) + _gamma) c = lni(2. * _y * np.sqrt(_gamma * (1. + _gamma))) return np.exp(a + b + c)
this function assumes there exist implementation of lni
computes log(i0(z))
. however, aware of no existing implementation of such function. can work around using mpmath
intermediate results:
def lni(z): i0 = mpmath.besseli(0, z) # may become big number logi0 = mpmath.log(i0) # logarithm brings big number sensible range return float(logi0) # convert normal floating point
Comments
Post a Comment