【发布时间】:2019-10-24 15:33:33
【问题描述】:
我正在尝试在 MATLAB 中使用 mle() 函数来估计 6 参数自定义分布的参数。
自定义分发的PDF是
CDF 是
其中Γ(x,y)和Γ(x)是上不完全伽马函数和伽马函数,分别。 α、θ、β、a、b、c 是自定义分布的参数。 K 由
给出给定一个数据向量'data',我想估计参数α,θ,β,a,b,和 c.
所以,到目前为止我已经想出了这个代码:
data = rand(20000,1); % Since I cannot upload the acutal data, we may use this
t = 0:0.0001:0.5;
fun = @(w,a,b,c) w^(a-1)*(1-w)^(b-1)*exp^(-c*w);
% to estimate the parameters
custpdf = @(data,myalpha,mybeta,mytheta,a,b,c)...
((integral(@(t)fun(t,a,b,c),0,1)^-1)*...
mybeta*...
igamma(myalpha,((mytheta/t)^mybeta)^(a-1))*...
(mytheta/t)^(myalpha*mybeta+1)*...
exp(-(mytheta/t)^mybeta-(c*(igamma(myalpha,(mytheta/t)^mybeta)/gamma(myalpha)))))...
/...
(mytheta*...
gamma(myalpha)^(a+b-1)*...
(gamma(myalpha)-igamma(myalpha,(mytheta/t)^mybeta))^(1-b));
custcdf = @(data,myalpha,mybeta,mytheta,a,b,c)...
(integral(@(t)fun(t,a,b,c),0,1)^-1)*...
integral(@(t)fun(t,a,b,c),0,igamma(myalpha,(mytheta/t)^mybeta)^mybeta/gamma(myalpha));
phat = mle(data,'pdf',custpdf,'cdf',custcdf,'start',0.0);
但我收到以下错误:
Error using mlecustom (line 166)
Error evaluating the user-supplied pdf function
'@(data,myalpha,mybeta,mytheta,a,b,c)((integral(@(t)fun(t,a,b,c),0,1)^-1)*mybeta*igamma(myalpha,((mytheta/t)^mybeta)^(a-1))*(mytheta/t)^(myalpha*mybeta+1)*exp(-(mytheta/t)^mybeta-(c*(igamma(myalpha,(mytheta/t)^mybeta)/gamma(myalpha)))))/(mytheta*gamma(myalpha)^(a+b-1)*(gamma(myalpha)-igamma(myalpha,(mytheta/t)^mybeta))^(1-b))'.
Error in mle (line 245)
phat = mlecustom(data,varargin{:});
Caused by:
Not enough input arguments.
我试图查看错误行,但无法确定错误的实际位置。
哪个函数缺少更少的输入?是指fun吗?为什么mle 在尝试估计参数时会缺少更少的输入?
有人可以帮我调试错误吗?
提前致谢。
【问题讨论】:
-
请将错误粘贴为代码(而不是图像),以便可以搜索。另外,标题中不需要matlab。
-
@Dev-iL 我按要求进行了更改。
-
我很确定问题在于使用您的
custpdf作为pdf的mle,因为mle仅提供2 个输入(请参阅docs)-“此自定义函数接受向量data和一个或多个单独的分布参数作为输入参数,并返回一个累积概率值向量。"。如果您想将超过 2 个变量传递给您的函数,您应该执行类似what's shown here 的操作。custcdf也是如此。 -
@Dev-iL 你的意思是说
mle(data,'pdf',custpdf,'cdf',custcdf,'start',0.0);应该是mle(data,'pdf',@data custpdf(data,myalpha,mybeta,mytheta,a,b,c),'cdf',@data custcdf(data,myalpha,mybeta,mytheta,a,b,c),'start',0.0); -
大概是的(但有 2 个输入和正确的语法)。无论如何 - 至少在调试阶段,我建议使用更少的匿名函数和更多的函数句柄来命名函数(例如
function out = custpdf(...))。调试多行匿名函数并不十分方便。
标签: matlab debugging distribution mle