scipy stats.rv_continuous() | Python
scipy.stats.rv_continuous()
是一个连续随机变量类,用于子分类。它是从连续随机变量构造特定分布的基类。此类不能直接用作分发。
Parameters :
moment : [int] moment calculation to use: 0 for pdf, 1 for ppf. Default = 1
a : [float] Lower bound for distribution. Default is -ve infinity.
b : [float] Upper bound for distribution. Default is +ve infinity.
xtol : [float] tolerance for fixed point calculation for ppf
name : [str] Name of the instance. Used to construct the default e.g. for distributions
badvalue : [object] Default is np.nan. Value in a result arrays that indicates a value that for which some argument restriction is violated.
logname : [str] Used as part of theFirst line of the docstring.
extradoc : [str] Used as the last part of the docstring
shapes : [str] Shape of the distribution.
Return : Continuous Random Variable Distribution.
代码 #1:使用“rv_continuous 类”。
def sample(self, size = 1, random_state = None):
"""
Return a sample from PDF - Probability Distribution Function.
calling - rv_continuous class.
"""
return self._rv.rvs(size = size, random_state = random_state)
代码 #2:从 rv_continuous 创建高斯分布。
from scipy.stats import rv_continuous
import numpy as np
class gaussian_gen(rv_continuous):
'''Gaussian distribution'''
def _pdf(self, x):
return np.exp(-x**2 / 2.) / np.sqrt(2.0 * np.pi)
gaussian = gaussian_gen(name = 'gaussian')
x = 2.0
gaussian._pdf(x)
输出 :
0.05399096651318806