matlab - 使用 MLE 函数估计自定义分布的参数
问题描述
我正在尝试使用mle()
MATLAB 中的函数来估计 6 参数自定义分布的参数。
自定义分布的PDF是
CDF是_
其中Γ (x,y) 和Γ (x) 分别是上不完全 gamma 函数和gamma 函数。α、θ、β、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
在尝试估计参数时会缺少更少的输入?
有人可以帮我调试错误吗?
提前致谢。
解决方案
exp()
是一个函数,而不是一个变量,精确的参数
exp^(-c*w) ---> exp(-c*w)
- 出发点
6 parameters
不仅是一个0.1*ones(1,6)
- 在 custcdf
mle
要求积分的上限是标量,我做了一些试验和错误,范围是 [2~9]
。对于试验,一些值导致负 cdf 或小于 1 丢弃它们。 - 然后使用正确的计算上限,看看它是否与您预定义的相同。
我重写了所有函数,检查出来
代码如下
Censored = ones(5,1);% All data could be trusted
data = rand(5,1); % Since I cannot upload the acutal data, we may use this
f = @(w,a,b,c) (w.^(a-1)).*((1-w).^(b-1)).*exp(-c.*w);
% to estimate the parameters
custpdf = @(t,alpha,theta,beta, a,b,c)...
(((integral(@(w)f(w,a,b,c), 0,1)).^-1).*...
beta.*...
((igamma(alpha, (theta./t).^beta)).^(a-1)).*...
((theta./t).^(alpha.*beta + 1 )).*...
exp(-(((theta./t).^beta)+...
c.*igamma(alpha, (theta./t).^beta)./gamma(alpha))))./...
(theta.*...
((gamma(alpha)).^(a+b-1)).*...
((gamma(alpha)-...
igamma(alpha, (theta./t).^beta)).^(1-b)));
custcdf = @(t,alpha,theta,beta, a,b,c)...
((integral(@(w)f(w,a,b,c), 0,1)).^-1).*...
(integral(@(w)f(w,a,b,c), 0,2));
phat = mle(data,'pdf',custpdf,'cdf',custcdf,'start', 0.1.*ones(1,6),'Censoring',Censored);
结果
phat = 0.1017 0.1223 0.1153 0.1493 -0.0377 0.0902
推荐阅读
- javascript - 如何在每行前面生成序列号以及如何保存多行数据
- python - 如何有效地删除仅包含 0 作为值的前导行?
- angular - 通过函数进行角度动态属性绑定
- javascript - 我可以将 web worker 用于 ui 组件吗?
- jenkins - Jenkins 似乎停止在 Ubuntu 16.04.4 上监听端口 8080
- javascript - FullCalendar 点击时自动填充事件
- c - 这是打开 .txt 文件的正确方法吗
- yacc - 这个 yacc 语法有什么问题?
- javascript - Firebase 推送通知不显示为弹出消息 - c#
- azure - 获取 Microsoft.Azure.CognitiveServices.Language.LUIS.Runtime.Models.APIErrorException:操作返回无效状态代码“禁止”