dit/dit — pull request #26 by Autoplectic (2013-10-01 21:37:03+00:00)
Title: Add the Jensen-Shannon Divergence

Depends on #25

```python
def JSD(dists, weights=None):
"""
The Jensen-Shannon Divergence: H( sum(w_i*P_i) ) - sum(w_i*H(P_i)).

Parameters
----------
dists: [Distribution]
The distributions, P_i, to take the Jensen-Shannon Divergence of.

weights: [float]
The weights, w_i, to give the distributions.

Returns
-------
jsd: float
The Jensen-Shannon Divergence

Raises
------
CMPyException:
Raised if the mixture distribution can not be formed.
"""
if weights is None:
weights = [ 1/len(dists) ] * len(dists)

return mixture_distribution(dists, weights).entropy() - sum( w*d.entropy() for w, d in zip(weights, dists) )
```