nas*_*ash 10 statistics matlab max maximize log-likelihood
我试图重现实际和估计参数'tau'(for over a month :()之间的均方误差.估计'tau',即'tau_hat'通过最大似然估计(MLE)获得,如下所示.
联合概率密度函数f(y|x,tau)由下式给出
在哪里u_i = x_i +T和T~IG(mu,lambda).IG:逆高斯.u是期望值y.PDF格式由.f_T(t)给出
我根据这个网站编写的代码是
clear
lambda = 8.1955;
mu = 10;
N = 128; % max number of molecules
x = zeros(N,1); % transmission time of the molecules from the Tx; for K = 1
tau = .5; % arbitrary initital tau
simN = 1000 ; % # runs per N
no_molecules_per_simN = [4, 8, 32, 64, N];
tau_hat = zeros(size(no_molecules_per_simN));
for ii=1: length(no_molecules_per_simN)
Lkeh = zeros(1,length(no_molecules_per_simN(ii))); % inititalize likelihood array
for jj=1: simN
T = random('InverseGaussian', mu,lambda, [no_molecules_per_simN(ii),1]); % random delay
y_prime = x(1:no_molecules_per_simN(ii)) + T + tau; % arrival time of the molecules seen by the Rx
y_prime_sort = sort(y_prime); % to arrange them in the ascending order of arrival
u = y_prime_sort; % assign to u variable
t = u - x(1:no_molecules_per_simN(ii)) - tau;
for kk = 1: length(u)
% applying the likelihood function to eq. 3 and ignoring the constant terms
%linear likelihood
% Lkeh(jj,kk) = prod(t(kk).^-1.5).*exp(-sum((t(kk) - mean(t)).^2./t(kk)).*(lambda./(2.*mean(t).^2 )));
% [UPDATE to the code]
% log likelihood
Lkeh(jj,kk) = -1.5*sum(t(kk))-(lambda./(2.*mu.^2 )).*sum((t(kk) - mu).^2./t(kk));
end
end
Lkeh_mean = mean(Lkeh,1); % averging the values
% [UPDATE to the code]
[maxL,index] = max(Lkeh_mean);
t_hat(ii) = T(index) ; % this will give the likelihood value of the propagation delay
tau_hat(ii) = mean(u - x(1:no_molecules_per_simN(ii)) - t_hat(ii)); % reverse substitution
end
MSE = zeros(size(tau_hat)); % initializing the array for MSE
for ii=1:length(tau_hat)
MSE(ii) = immse(tau,tau_hat(ii)); % mean squared error
end
figure
loglog(no_molecules_per_simN,MSE,'-o')
xlabel('n_{1}(quantity of molecules)')
ylabel('MSE(sec^{2})')
grid on
Run Code Online (Sandbox Code Playgroud)
我得到的结果是
我在代码中犯的错误是什么?我不太清楚我是如何计算的argmax.供你参考,我所指的科学论文就在这里.
我无法运行你的代码,因为它需要一些我没有的工具箱.那说,以下行:
tau_hat(ii) = max(Lkeh);
Run Code Online (Sandbox Code Playgroud)
会给你最大可能性的值.这不是你的真实意图,这是tay_hat 在其达到您的最大可能性.
对于tay_hat的给定值,您需要tay函数将tay_hat映射到似然值.假设这就是你在这里做的,我不确定对tay_hat的依赖性在哪里.假设Lkeh是我刚才描述的
[maxLikelihoodValue, maxLikelihoodIndex] = max(Lkeh);
Run Code Online (Sandbox Code Playgroud)
使用max函数的两个输出,您将获得最大似然值,最重要的是,最大似然值的索引.如果你已经明确定义了tay向量,那么tay_hat将简单地给出
tay_hat = tay(maxLikelihoodIndex);
所以基本上是你获得最大可能性的tay值,而不是最大似然本身.
为了给你一个玩具示例,假设你的似然函数是L(x)= -x ^ 2 - 2*x,
假设它是离散的,以便
x = linspace(-2,2,30);
Run Code Online (Sandbox Code Playgroud)
那么L的离散版本将是
L_x = -x.^2 -2*x;
Run Code Online (Sandbox Code Playgroud)
那么最大似然值将简单地给出
max(L_x);
Run Code Online (Sandbox Code Playgroud)
恰好是0.9988(事实上接近确切的值)
但你追求的是什么the value of x at which this maximum occurs.
因此,您首先在获得最大值的序列中提取索引,通过:
[maximumLikelihood, maxLikIndex ] = max(L_x) ;
Run Code Online (Sandbox Code Playgroud)
然后在该索引处找到x的估计值,只需在该索引处请求x的值:
x (maxLikIndex)
Run Code Online (Sandbox Code Playgroud)
如预期的那样,大约是-1.0.在您的示例中,您希望估计最有可能的tau_hat(在频率框架中)由最大化函数的值(这不是函数本身的最大值)给出.