我将我的概率密度函数定义如下:
怎样从PDF中获取样本,以便在绘制直方图时呈现梯形的形状?
我尝试使用`np.random.random`,但我觉得那不是我想要的。
def trapezoidal_pdf(x, a, b, c, d):
const = (2 / (d + c - a - b))
if a <= x < b:
probability = const * (x - a) / (b - a)
return probability
elif b <= x < c:
probability = const
return probability
elif c <= x < d:
probability = const * (d - x) / (d - c)
return probability
else:
return 0.0 # Outside the defined range, probability is 0
怎样从PDF中获取样本,以便在绘制直方图时呈现梯形的形状?
我尝试使用`np.random.random`,但我觉得那不是我想要的。