10

我试图重现实际参数和估计参数'tau'( for over a month :() 之间的均方误差。估计值'tau',即'tau_hat'通过最大似然估计 (MLE) 获得,如下所示。

在此处输入图像描述

联合概率密度函数f(y|x,tau)由下式给出

在此处输入图像描述

哪里u_i = x_i +TT~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

我得到的结果是

在此处输入图像描述

但是,我应该得到红色箭头所指的那个 在此处输入图像描述

我在代码中犯了什么错误?我不太确定我是如何计算的argmax。供您参考,我指的科学论文在这里

4

1 回答 1

5

我无法运行您的代码,因为它需要一些我没有的工具箱。也就是说,以下行:

tau_hat(ii)     =  max(Lkeh); 

会给你可能性的最大值。这不是你真正追求的,这是你获得最大可能性的tay_hat

对于给定的 tay_hat 值,您需要一个 tay 函数,它将 tay_hat 映射到可能性。假设这就是你在这里所做的,我不确定对 tay_hat 的依赖在哪里。假设 Lkeh 就是我刚才描述的

[maxLikelihoodValue, maxLikelihoodIndex] = max(Lkeh);

使用 max 函数的两个输出,您将获得最大似然值,最重要的是,该最大值出现的索引。如果您明确定义了 tay 向量,则 tay_hat 将由

tay_hat = tay (maxLikelihoodIndex) ;

所以基本上是你得到最大似然的 tay 值,而不是最大似然本身。

给你一个玩具例子,假设你的似然函数是 L(x) = -x^2 - 2*x,

假设它是离散的,因此

 x = linspace(-2,2,30);

那么 L 的离散版本将是

L_x = -x.^2 -2*x;

那么最大似然值将简单地由下式给出

max(L_x);

恰好是 0.9988(实际上接近准确值)

但你所追求的是the value of x at which this maximum occurs

因此,您首先通过以下方式提取获得最大值的序列中的索引:

[maximumLikelihood, maxLikIndex ] = max(L_x) ;

然后在该索引处找到 x 的估计值,只需使用 请求该索引处的 x 值:

x (maxLikIndex)

正如预期的那样,大约是-1.0。在你的例子中,你想估计你最有可能的 tau_hat (在常客框架中)由最大化你的函数的值给出(这不是函数本身的最大值)。

于 2018-09-29T11:19:29.080 回答