Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

I have problem with this code

1 visualizzazione (ultimi 30 giorni)
mutah
mutah il 29 Set 2013
Chiuso: Jan il 30 Set 2013
italic rho=0.000001:0.03:3; kappa=1; N_gau=10; N_iteration=1000; serror=0.001; ini_mean=rand(1,10); ini_sigma=rand(1,10); for g=1:10 w_i(g)=(0.1); end ini_W=w_i; for mu= 0.5
X=(2*mu.*(1+kappa).^((mu+1)./2)./kappa.^((mu-1)./2)./exp(mu.*kappa)).* rho.^(mu).*exp(-mu.*(1+kappa).*rho.^2).*besseli(mu-1, 2*mu.*sqrt(kappa.*(kappa+1)).*rho); end
function [Post_old, mean_old,sigma_old,W_old,log_lik_list]=Gaumix_EM(X,N_gau,N_iteration,serror,ini_mean,ini_sigma,ini_W)
%Gaumix_EM: EM Algorithm Applicated to Parameter Estimation for Gaussian Mixture % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % OUTPUT % % % Post_old = Posterior % % % mean_old = estimated means for each gaussian % % % sigma_old = estimated varances for each gaussian % % % W_old = estimated Weights for each gaussian % % % log_lik_list = Likelihood list for each iteration % % % % % % INPUT % % % X = random vector % % % N_gau = number of gaussian % % % N_iteration= number of maxiun iteration % % % serror = iteration stopped under the error % % % ini_mean = initial means of gaussians % % % ini_sigma = initial varances of gaussians % % % ini_W = initial Weights of gaussians % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %2007/3/30 [r,c]=size(X); if r>c X=X'; end
mX=ones(N_gau,1)*X; %[X;X;.....;X], length(X)*N_gau numX=length(X);
% switch nargin % case 3 % % end
mean_old=ini_mean; sigma_old=ini_sigma; W_old=ini_W;
log_lik_list=zeros(1,1000); N=0; % number of processing iteration sqr2pi=sqrt(2*pi); B=zeros(N_gau,numX);
while N<N_iteration N=N+1; for i=1:N_gau B(i,:)=W_old(i)*(1/(sqr2pi*sqrt(sigma_old(i))))*exp(-0.5*(X-mean_old(i)).*(X-mean_old(i))/sigma_old(i)); end
Allgau_B=sum(B); %summation al gaussian, size = 1*length(X)
%%%%%%%%%%%%%%%%%%%%%%% compute loglikelihhod %%%%%%%%%%%%%%%%%%%%%%%%% log_lik_list(N)=sum(log(Allgau_B)); % Likelihood list for each iteration %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Allgau_B=ones(N_gau,1)*Allgau_B; % size = N_gau*length(X) Post_old= B./Allgau_B;
%%%%%%%% update means and stds weights for each gaussian %%%%%%%%%%%%%% W_old=sum(Post_old,2); mean_old=sum(Post_old.*mX,2)./W_old; sigma_old= sum(Post_old.*mX.*mX,2)./W_old-mean_old.*mean_old;
W_old=W_old/numX; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if N>1&log_lik_list(N)<log_lik_list(N-1) fprintf('EM Algorithm Applicated to Parameter Estimation for Gaussian Mixture\n'); fprintf('µo´²!\n'); return; end; if N>1 & log_lik_list(N)-log_lik_list(N-1)<serror fprintf('EM Algorithm Applicated to Parameter Estimation for Gaussian Mixture\n'); str=['number of iteration = ',int2str(N),' \n']; fprintf(str); fprintf('Done. \n'); return; end;
end fprintf('EM Algorithm Applicated to Parameter Estimation for Gaussian Mixture\n'); fprintf('number of maxiun iteration reached \n');
  3 Commenti
Jan
Jan il 30 Set 2013
You forgot to ask a question. How could we guess, what the problem is? Therefore I've closed this question. You can re-open it by adding further details.

Risposte (0)

Questa domanda è chiusa.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by