八度:“'ncx2cdf' 未定义”错误
Octave: "'ncx2cdf' undefined" error
我正在尝试 运行 来自 Octave 的 M 文件,但出现此错误:
Octave evaluation error: 'ncx2cdf' undefined
显然这个函数的非中心卡方分布是simply defined as 1 minus the Marcum Q function. The signal package at octave-forge provides an implementation(貌似与matlab兼容)。
因此您大概可以编写自己的 ncx2cdf
函数,如下所示:
function Out = myncx2cdf (X, V, Delta)
Out = 1 - marcumq (sqrt (Delta), sqrt (X), V/2);
end
在matlab中确认:
>> X = randi(100, [1,20]); V = 4; Delta = 10;
>> ncx2cdf(X, V, Delta)
ans =
1.0000 0.9410 0.9999 1.0000 1.0000 1.0000 1.0000 0.5549 0.6093 0.9410 1.0000 0.9410 1.0000 0.9279 1.0000 0.9920 0.8183 0.9410 1.0000 0.9997
>> 1 - marcumq(sqrt(Delta), sqrt(X), V/2)
ans =
1.0000 0.9410 0.9999 1.0000 1.0000 1.0000 1.0000 0.5549 0.6093 0.9410 1.0000 0.9410 1.0000 0.9279 1.0000 0.9920 0.8183 0.9410 1.0000 0.9997
相同 X、V 和 Delta 的八度会话:
octave:34> pkg load signal
octave:35> 1 - marcumq(sqrt(Delta), sqrt(X), V/2)
ans =
1.00000 0.94105 0.99988 1.00000 1.00000 1.00000 0.99996 0.55492 0.60929 0.94105 1.00000 0.94105 1.00000 0.92793 1.00000 0.99203 0.81831 0.94105 1.00000 0.99972
请注意,在此实现中,自由度参数 V 被限制为偶数;如果你也想使用奇数自由度,例如5,这可以从 V=4 和 V=6 的结果中进行插值(这在实践中似乎很有效)。
下面是非中心卡方分布的简单实现:
function f = ncx2pdf(x, n, lambda, term = 32)
f = exp(-lambda/2) * arrayfun(@(x) sum_expression([0:term],x,n,lambda), x);
function t = sum_expression(j,v,n,l)
# j is vector, v is scalar.
numerator = (l/2).^j .* v.^(n/2+j-1) * exp(-v/2);
denominator = factorial(j) .* 2.^(n/2+j) .* gamma(n/2+j);
t = sum(numerator ./ denominator);
end
end
here is the function file ,把它放在你的八度路径中。
我正在尝试 运行 来自 Octave 的 M 文件,但出现此错误:
Octave evaluation error: 'ncx2cdf' undefined
显然这个函数的非中心卡方分布是simply defined as 1 minus the Marcum Q function. The signal package at octave-forge provides an implementation(貌似与matlab兼容)。
因此您大概可以编写自己的 ncx2cdf
函数,如下所示:
function Out = myncx2cdf (X, V, Delta)
Out = 1 - marcumq (sqrt (Delta), sqrt (X), V/2);
end
在matlab中确认:
>> X = randi(100, [1,20]); V = 4; Delta = 10;
>> ncx2cdf(X, V, Delta)
ans =
1.0000 0.9410 0.9999 1.0000 1.0000 1.0000 1.0000 0.5549 0.6093 0.9410 1.0000 0.9410 1.0000 0.9279 1.0000 0.9920 0.8183 0.9410 1.0000 0.9997
>> 1 - marcumq(sqrt(Delta), sqrt(X), V/2)
ans =
1.0000 0.9410 0.9999 1.0000 1.0000 1.0000 1.0000 0.5549 0.6093 0.9410 1.0000 0.9410 1.0000 0.9279 1.0000 0.9920 0.8183 0.9410 1.0000 0.9997
相同 X、V 和 Delta 的八度会话:
octave:34> pkg load signal
octave:35> 1 - marcumq(sqrt(Delta), sqrt(X), V/2)
ans =
1.00000 0.94105 0.99988 1.00000 1.00000 1.00000 0.99996 0.55492 0.60929 0.94105 1.00000 0.94105 1.00000 0.92793 1.00000 0.99203 0.81831 0.94105 1.00000 0.99972
请注意,在此实现中,自由度参数 V 被限制为偶数;如果你也想使用奇数自由度,例如5,这可以从 V=4 和 V=6 的结果中进行插值(这在实践中似乎很有效)。
下面是非中心卡方分布的简单实现:
function f = ncx2pdf(x, n, lambda, term = 32)
f = exp(-lambda/2) * arrayfun(@(x) sum_expression([0:term],x,n,lambda), x);
function t = sum_expression(j,v,n,l)
# j is vector, v is scalar.
numerator = (l/2).^j .* v.^(n/2+j-1) * exp(-v/2);
denominator = factorial(j) .* 2.^(n/2+j) .* gamma(n/2+j);
t = sum(numerator ./ denominator);
end
end
here is the function file ,把它放在你的八度路径中。