How to write the function (or any other methods) to calculate Jensen-Shannon divergence (JSD) for two (p and q) discrete probability distributions? I need to calculate JSD for too many different (over 1000) probability distributions so it should be run able by for loop. Thank you for your help. I wrote the below code but it is not working. You can see the part of the probability distribution (PD) of p and q. There are a lot 0 in the both p and q PD.
p={0.13253, 0.0361446, 0.0120482, 0.0240964, 0., 0., 0., 0., 0., 0.,0., 0., 0.,0,0}
q={0.0282448, 0.0163522, 0.010406, 0.0163522, 0.0208119, 0.0118925,
0.00891941, 0.00297314, 0.0044597, 0.00148657, 0., 0., 0., 0.,0.00148657}
Function[{p, q},
N[1/2 (p*Log2 p + q*Log2 q) - ((p + q)/2*Log2 (p + q)/2)]][
p@DjointProbaility, q@DmarjinalProbaility]
p
andq
, how can we know what "it is not working" means. $\endgroup$p/q
andq/p
must exists (without division by zero). Your example vectors just don't satisfy this, so it takes no wonder that this does not "work". This metric is just not applicable to your data. $\endgroup$