No BSD License  

Highlights from
Jensen-Shannon divergence

Be the first to rate this file! 11 Downloads (last 30 days) File Size: 1.1 KB File ID: #20689

Jensen-Shannon divergence

by Nima Razavi

 

13 Jul 2008 (Updated 15 Jul 2008)

Calculates the Jensen-Shannon divergence between two probability distributions

| Watch this File

File Information
Description

The .zip file contains two functions naming JSDiv.m and KLDiv.m

JSDiv.m uses KLDiv.m for calculation of the KL-divergence.

For more information on the divergence you can take a look at the following:

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
15 Sep 2009 Kimberly

Hi ... thanks very much for writing this code and taking the time to post it! I had some trouble in the case where at least one of the entries of P and Q are both 0. In this case the last line of KLdiv.m:

% resolving the case when P(i)==0
dist(isnan(dist))=0;

sets the divergence to 0, which is clearly not the case e.g. if P = [1 0 1], Q = [0 0 1].

I would suggest changing the last few lines to:

   
    Q = Q ./repmat(sum(Q,2),[1 size(Q,2)]);
    P = P ./repmat(sum(P,2),[1 size(P,2)]);
    M=log(P./Q);
    M(isnan(M))=0;
    dist = sum(P.*M,2);
end

which seems to work for me.

Please login to add a comment or rating.
Updates
15 Jul 2008

BUG_FIXED

Tag Activity for this File
Tag Applied By Date/Time
statistics Nima Razavi 22 Oct 2008 10:10:02
probability Nima Razavi 22 Oct 2008 10:10:02
jensenshannon divergence Nima Razavi 22 Oct 2008 10:10:02
information radius irad Nima Razavi 22 Oct 2008 10:10:02
total divergence Nima Razavi 22 Oct 2008 10:10:02

Contact us at files@mathworks.com