title: How to create a Rician random variable?
body: <p>I'm trying to model a signal detection problem using Sympy, and need two random variables.  One with a Rayleigh distribution to model noise, and one with a Rician distribution to model signal+noise.  Sympy <a href="http://docs.sympy.org/latest/modules/stats.html" rel="nofollow noreferrer">provides a Rayleigh distribution</a>, but not a Rician-- or at least not one by that name.</p>
  
  <p>What's the best way of creating one?  Does it exist under a different name?  Is there a way to manipulate existing distributions into a Rician?</p>
  
  <hr>
  
  <p>Following advice from @asmeurer, I've implemented my own Rice distribution, like so:</p>
  
  <pre><code>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))
  </code></pre>
  
  <p>The distribution seems to match both <a href="https://en.wikipedia.org/wiki/Rice_distribution" rel="nofollow noreferrer">Wikipedia</a> and <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rice.html#scipy.stats.rice" rel="nofollow noreferrer">Scipy</a>, but oddly I'm getting different results than Scipy.  I'll ask that question separately (<a href="https://stackoverflow.com/q/33049370/2571165">asked and answered</a>).</p>
  
  <p>As a side note, the following line makes it possible to lambdify the density function, which includes a Bessel function:</p>
  
  <pre><code>printing.lambdarepr.LambdaPrinter._print_besseli=(lambda self,expr: 'i0(%s)'%expr.argument)
  </code></pre>
  
  <p>It's not generalized to all Bessel functions, but works for the zero order modified Bessel of the first kind used in the Rician distribution.</p>