I am trying to simulate a signal detection problem using Sympy and need two random variables. One with Rayleigh distribution for modeling noise and one with Rician distribution for modeling signal + noise. Sympy provides a Rayleigh distribution , but not a Rician - or at least not one of them.
What is the best way to create it? Does it exist under a different name? Is there a way to manipulate existing distributions in Rician?
Following @asmeurer's advice, I implemented my own Rice distribution, for example:
from sympy.stats.crv_types import rv from sympy.stats.crv import SingleContinuousDistribution class RicianDistribution(SingleContinuousDistribution): _argnames=('nu','sigma') @property def set(self): return Interval(0,oo) def pdf(self,x): nu,sigma=self.nu, self.sigma return (x/sigma**2)*exp(-(x**2+nu**2)/(2*sigma**2))*besseli(0,x*nu/sigma**2) def Rician(name,nu,sigma): return rv(name,RicianDistribution,(nu,sigma))
The distribution is similar to Wikipedia and Scipy , but it is strange that I have different results than Scipy. I will ask this question separately ( asked and answered ).
As an additional note, the following line allows you to go around the density function, which includes the Bessel function:
printing.lambdarepr.LambdaPrinter._print_besseli=(lambda self,expr: 'i0(%s)'%expr.argument)
It is not generalized to all Bessel functions, but works for a modified first-order Bessel of the first type used in the Rich distribution.