jensenshannon(p, q, base=None, *, axis=0, keepdims=False)
The Jensen-Shannon distance between two probability vectors p
and q
is defined as,
where $m$ is the pointwise mean of $p$ and $q$ and $D$ is the Kullback-Leibler divergence.
This routine will normalize p
and q
if they don't sum to 1.0.
left probability vector
right probability vector
the base of the logarithm used to compute the output if not given, then the routine uses the default base of scipy.stats.entropy.
Axis along which the Jensen-Shannon distances are computed. The default is 0.
If this is set to :None:None:`True`
, the reduced axes are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. Default is False.
Compute the Jensen-Shannon distance (metric) between two probability arrays. This is the square root of the Jensen-Shannon divergence.
>>> from scipy.spatial import distance
... distance.jensenshannon([1.0, 0.0, 0.0], [0.0, 1.0, 0.0], 2.0) 1.0
>>> distance.jensenshannon([1.0, 0.0], [0.5, 0.5]) 0.46450140402245893
>>> distance.jensenshannon([1.0, 0.0, 0.0], [1.0, 0.0, 0.0]) 0.0
>>> a = np.array([[1, 2, 3, 4],
... [5, 6, 7, 8],
... [9, 10, 11, 12]])
... b = np.array([[13, 14, 15, 16],
... [17, 18, 19, 20],
... [21, 22, 23, 24]])
... distance.jensenshannon(a, b, axis=0) array([0.1954288, 0.1447697, 0.1138377, 0.0927636])
>>> distance.jensenshannon(a, b, axis=1) array([0.1402339, 0.0399106, 0.0201815])See :
The following pages refer to to this document either explicitly or contain code examples using this.
scipy.spatial.distance.jensenshannon
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them