如何在 Matlab 中准确计算风险率?
How to do I calculate the hazard rate accurately in Matlab?
我需要计算 x
上瑞利函数的风险率 PDF/(1-CDF)。
x = 0:0.001:2.5;
HR = pdf('rayl',x,sqrt(1/18))./(1-cdf('rayl',x,sqrt(1/18)));
plot(x,HR)
这里的情节大约在 x = 2
变得有趣。如何提高 HR 的准确性?
您 运行 陷入了数值问题,特别是 catastrophic cancellation. Try plotting just the denominator of your hazard rate function, the complementary CDF, on a semilogy
情节:
x = 0:0.001:2.5;
semilogy(x,1-cdf('rayl',x,sqrt(1/18)))
如您所见,当分母约为 machine epsilon, eps
时,在 x = 2 之前有点问题。这是 cdf('rayl',x,sqrt(1/18))
大约为 1 的时候。
幸运的是,Matlab 提供了一种解决此问题的方法,可以直接通过 cdf
的 'upper'
选项计算互补 CDF 或 CDF 的尾概率:
x = 0:0.001:2.5;
HR = pdf('rayl',x,sqrt(1/18))./cdf('rayl',x,sqrt(1/18),'upper');
plot(x,HR)
现在 returns 一条斜率为 18 的直线,正如预期的那样。 raylcdf
函数也支持这个选项。
我需要计算 x
上瑞利函数的风险率 PDF/(1-CDF)。
x = 0:0.001:2.5;
HR = pdf('rayl',x,sqrt(1/18))./(1-cdf('rayl',x,sqrt(1/18)));
plot(x,HR)
这里的情节大约在 x = 2
变得有趣。如何提高 HR 的准确性?
您 运行 陷入了数值问题,特别是 catastrophic cancellation. Try plotting just the denominator of your hazard rate function, the complementary CDF, on a semilogy
情节:
x = 0:0.001:2.5;
semilogy(x,1-cdf('rayl',x,sqrt(1/18)))
如您所见,当分母约为 machine epsilon, eps
时,在 x = 2 之前有点问题。这是 cdf('rayl',x,sqrt(1/18))
大约为 1 的时候。
幸运的是,Matlab 提供了一种解决此问题的方法,可以直接通过 cdf
的 'upper'
选项计算互补 CDF 或 CDF 的尾概率:
x = 0:0.001:2.5;
HR = pdf('rayl',x,sqrt(1/18))./cdf('rayl',x,sqrt(1/18),'upper');
plot(x,HR)
现在 returns 一条斜率为 18 的直线,正如预期的那样。 raylcdf
函数也支持这个选项。