spm_kl_eig_normal.m.svn-base
来自「try the matlab scripts to do various com」· SVN-BASE 代码 · 共 33 行
SVN-BASE
33 行
function [d] = spm_kl_eig_normal (m_q,c_q,c_p)% KL divergence between normal densities using eigendecomposition % function [d] = spm_kl_eig_normal (m_q,c_q,c_p)%% Calculate the KL distance %% KL (Q||P) = <log Q/P> where avg is wrt Q%% between two Normal densities Q and P where P is% zero mean and has a diagonal covariance.%% m_q, c_q Mean and covariance of first Normal density% c_p Covariance of second (zero-mean) Normal density%___________________________________________________________________________% Copyright (C) 2007 Wellcome Department of Imaging Neuroscience% Will Penny % $Id$d=length(m_q);m_q=m_q(:);ldcp=0.5*sum(log(diag(c_p)));[v,eigvals]=eig(c_q);ldcq=-0.5*sum(log(diag(eigvals)));Term1=ldcp+ldcq;inv_c_p=diag(1./diag(c_p));Term2=0.5*trace(inv_c_p*c_q)+0.5*m_q'*inv_c_p*m_q;d=Term1+Term2-0.5*d;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?