KL-distance of X and Y KL = vb_kl_distance(X,Y) X and Y are normalized before calculation Zero value component is replaced by eps 2006-8-11 M. Sato Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function kld = vb_kl_distance(x,y) 0002 % KL-distance of X and Y 0003 % KL = vb_kl_distance(X,Y) 0004 % X and Y are normalized before calculation 0005 % Zero value component is replaced by eps 0006 % 0007 % 2006-8-11 M. Sato 0008 % 0009 % Copyright (C) 2011, ATR All Rights Reserved. 0010 % License : New BSD License(see VBMEG_LICENSE.txt) 0011 0012 x = max(x,eps); 0013 y = max(y,eps); 0014 0015 x = x/sum(x); 0016 y = y/sum(y); 0017 0018 % KL-divergence 0019 kld = sum( x.*log(x./y) );