How to create a Rician random variable?

前端 未结 2 389
[愿得一人]
[愿得一人] 2021-01-07 05:33

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 distribut

2条回答
  •  粉色の甜心
    2021-01-07 06:25

    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))
    

提交回复
热议问题