function [nec] = NEC(data,allmodel) % NEC - % % The mathematical definition of this function is given on Epage 163-164 % % Inputs: % allmodel = the output from the EDA toolbox function mbclust.m % % Written by: % -- % John L. Weatherwax 2009-03-24 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- nec = zeros(length(allmodel),length(allmodel(end).clus)); for mi=1:length(allmodel) L = zeros(1,length(allmodel(mi).clus)); for ki=1:length(allmodel(mi).clus) pies = allmodel(mi).clus(ki).pies; mus = allmodel(mi).clus(ki).mus; vars = allmodel(mi).clus(ki).vars; [clabs3,unc,all_posts,den_estimate] = mixclass( data, pies, mus, vars ); % calculate C(K): pi_times_f_hat = pies(:) * den_estimate.'; tau_times_ln = all_posts .* log( pi_times_f_hat.' ); C_k = sum(tau_times_ln(:)); % calculate E(K): tau_times_ln = all_posts .* log( all_posts+1e-6 ); E_k = -sum(tau_times_ln(:)); % calculate L(K): L(ki) = C_k + E_k; if( ki==1 ) nec(mi,ki) = 1; else nec(mi,ki) = E_k / ( L(ki) - L(1) ); end end end