How to create a Rician random variable?

扶醉桌前 提交于 2019-12-01 01:00:21

If you know the pdf function, it's easy to create a new distribution with sympy.stats. Take a look at the existing distributions in the sympy source. You just need to subclass SingleContinuousDistribution and define some methods. For example, here is the normal distribution (with the docstrings removed):

class NormalDistribution(SingleContinuousDistribution):
    _argnames = ('mean', 'std')

    @staticmethod
    def check(mean, std):
        _value_check(std > 0, "Standard deviation must be positive")

    def pdf(self, x):
        return exp(-(x - self.mean)**2 / (2*self.std**2)) / (sqrt(2*pi)*self.std)

    def sample(self):
        return random.normalvariate(self.mean, self.std)


def Normal(name, mean, std):
    return rv(name, NormalDistribution, (mean, std))
Prune

Yes, you can generate the Rice from chi-squared and Poisson. See any thorough Rice discussion, such as https://en.wikipedia.org/wiki/Rice_distribution:

Another case where Rice(nu,sigma) comes from the following steps:

  1. Generate P having a Poisson distribution with parameter (also mean, for a Poisson) lambda = nu^2 / (2*sigma^2).
  2. Generate X having a chi-squared distribution with 2P + 2 degrees of freedom.
  3. Set R = sigma * sqrt(X).
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!