我有一个随机变量的数据,我希望测试它是否符合 Tracy-Widom 分布。但是,TW 分布很难计算。是否有一个我可以下载的现成可用的值表?
Tracy-Widom 分布数据
计算科学
统计数据
2021-11-27 17:35:34
2个回答
实际上,仅从定义计算 Tracy-Widom CDF 并不那么复杂:请参阅Folkmar Bornemann的 On The Numerical Evaluation of Fredholm Determinants。维基百科页面给出的定义为 其中与内核 )上的积分运算符
从这里开始,您可以上获取任何好的正交规则和节点,例如出色的tanh-sinh 正交,并计算矩阵 这是有效的,因为内核是平滑的。
处有一点不准确,但否则没关系。大部分时间都花在计算 Airy 函数上,因此生成值表以供将来使用应该没问题。
module TracyWidom
using SpecialFunctions
using Base.Test
function K(x, y)
try
if x == y
airyaiprime(x)^2 - x * airyai(x)^2
else
(airyai(x)*airyaiprime(y) - airyaiprime(x)*airyai(y)) / (x - y)
end
catch ex # underflow is not an error here
if isa(ex, SpecialFunctions.AmosException) && ex.id == 4
return 0.0
else
rethrow(ex)
end
end
end
function tanhSinhNodes(s, n=64)
tf = 3.158587875883174 # fzero(t -> log1p(-tanh(pi/2*sinh(t))) - log(eps(typeof(s))), 3.1)
t = linspace(-tf, tf, 2n+1)
u = tanh.(pi/2*sinh.(t))
w = pi/2*cosh.(t)./cosh.(pi/2*sinh.(t)).^2
w * step(t) .* 2./(u-1).^2, s + (u+1) ./ (1-u)
end
function tanhSinh(f, s, n=64)
w, x = tanhSinhNodes(s, n)
dot(w, f.(x))
end
function F2(s, n=128)
w, x = tanhSinhNodes(s, n)
m = length(w)
det([Int(i==j) - sqrt(w[i])*sqrt(w[j])*K(x[i], x[j]) for i=1:m, j=1:m])
end
function test()
@testset "TracyWidom" begin
@testset "tanh-sinh" begin
@test tanhSinh(x -> 1/(1+x^2), 0., 32) ≈ π/2
@test tanhSinh(x -> 1/(1+x^2), 1., 32) ≈ π/2 - atan(1.)
@test tanhSinh(x -> (1+x^2)^-1.25, 2.0, 32) ≈ 0.20885622523501382
end
@testset "F2" begin
@test F2(0.1) ≈ 0.9754704606594619
@test F2(-0.1) ≈ 0.9620142937272265
@test F2(-1.0) ≈ 0.8072142419992853
@test F2(-2.0) ≈ 0.41322414250512257
@test F2(-3.0) ≈ 0.08031955293933454
@test F2(-4.0) ≈ 0.0035445535955092003
@test F2(-5.0) ≈ 2.135996984741116e-5
@test F2(-6.0) ≈ 1.062254674124451e-8
@test F2(-7.0) ≈ 2.639614767246062e-13
@test F2(-8.0) ≈ 1.9859004257636574e-19
@test F2(1.0) ≈ 0.9975054381493893
@test F2(2.0) ≈ 0.9998875536983092
@test F2(3.0) ≈ 0.9999970059566077
@test F2(4.0) ≈ 0.9999999504208784
@test F2(5.0) ≈ 0.9999999994682207
@test F2(6.0) ≈ 0.9999999999961827
@test F2(7.0) ≈ 0.9999999999999811
@test F2(8.0) ≈ 0.9999999999999999
end
end
nothing
end
end
Mathematica 具有 TW 分布:
http://reference.wolfram.com/language/ref/TracyWidomDistribution.html
其它你可能感兴趣的问题