def pointer_to_jensenshannon(
dtype: _FloatTypeName | _MiniFloatType,
/,
) -> int | Symbol |
|---|
pointer_to_jensenshannon |
pointer_to_kullbackleibler |
Probability divergences deserve their own section because they are not just “one more distance”.
import numpy as np
import numkong as nk
p = np.array([0.2, 0.3, 0.5], dtype=np.float32)
q = np.array([0.1, 0.3, 0.6], dtype=np.float32)
kl_forward, kl_reverse = nk.kullbackleibler(p, q), nk.kullbackleibler(q, p)
assert kl_forward != kl_reverse, "KLD is asymmetric"
js_forward, js_reverse = nk.jensenshannon(p, q), nk.jensenshannon(q, p)
np.testing.assert_allclose(js_forward, js_reverse, atol=1e-6) # JSD is symmetricpointer_to_*× 2Return the address of the jensenshannon kernel for dtype, as an integer.def pointer_to_jensenshannon(
dtype: _FloatTypeName | _MiniFloatType,
/,
) -> int | Symbol |
|---|
pointer_to_jensenshannon |
pointer_to_kullbackleibler |
jensenshannonCompute the Jensen-Shannon distance between two probability distributions.def jensenshannon(
a: _BufferType,
b: _BufferType,
/,
dtype: _FloatTypeName | _MiniFloatType | None = None,
*,
out: _BufferType | None = None,
out_dtype: _FloatTypeName | _MiniFloatType | None = None,
capabilities: Capability | int | None = ...,
stream: int | None = ...,
) -> float | Tensor | None Similar to scipy.spatial.distance.jensenshannon. Two vectors give a scalar. Matrices pair row
i of a with row i of b, a single row pairing with every row of the other, into a new Tensor
of one result per pair, or into out, returning None.
a_BufferType | First probability vector or matrix. | |
|---|---|---|
b_BufferType | Second probability vector or matrix, of the dtype of a. | |
dtype_FloatTypeName | _MiniFloatType | None | Input dtype to read both buffers as, overriding the one they report. | |
out_BufferType | None | Output vector for the results. | |
out_dtype_FloatTypeName | _MiniFloatType | None | Result dtype, by default that of out, else float64. | |
capabilitiesCapability | int | None | Capabilities to run within: every CPU one by default, or for packed operands the mask that packed them. | |
streamint | None | A GPU stream pointer, left None on the CPU. |
jsdAlias of jensenshannon.def jsd(
a: _BufferType,
b: _BufferType,
/,
dtype: _FloatTypeName | _MiniFloatType | None = None,
*,
out: _BufferType | None = None,
out_dtype: _FloatTypeName | _MiniFloatType | None = None,
capabilities: Capability | int | None = ...,
stream: int | None = ...,
) -> float | Tensor | None capabilitiesCapability | int | None | Capabilities to run within: every CPU one by default, or for packed operands the mask that packed them. | |
|---|---|---|
streamint | None | A GPU stream pointer, left None on the CPU. |
kullbackleiblerCompute the Kullback-Leibler divergence between two probability distributions.def kullbackleibler(
a: _BufferType,
b: _BufferType,
/,
dtype: _FloatTypeName | _MiniFloatType | None = None,
*,
out: _BufferType | None = None,
out_dtype: _FloatTypeName | _MiniFloatType | None = None,
capabilities: Capability | int | None = ...,
stream: int | None = ...,
) -> float | Tensor | None Similar to scipy.special.kl_div. Two vectors give a scalar. Matrices pair row i of a with
row i of b, a single row pairing with every row of the other, into a new Tensor of one result
per pair, or into out, returning None.
a_BufferType | First probability vector or matrix. | |
|---|---|---|
b_BufferType | Second probability vector or matrix, of the dtype of a. | |
dtype_FloatTypeName | _MiniFloatType | None | Input dtype to read both buffers as, overriding the one they report. | |
out_BufferType | None | Output vector for the results. | |
out_dtype_FloatTypeName | _MiniFloatType | None | Result dtype, by default that of out, else float64. | |
capabilitiesCapability | int | None | Capabilities to run within: every CPU one by default, or for packed operands the mask that packed them. | |
streamint | None | A GPU stream pointer, left None on the CPU. |
kldAlias of kullbackleibler.def kld(
a: _BufferType,
b: _BufferType,
/,
dtype: _FloatTypeName | _MiniFloatType | None = None,
*,
out: _BufferType | None = None,
out_dtype: _FloatTypeName | _MiniFloatType | None = None,
capabilities: Capability | int | None = ...,
stream: int | None = ...,
) -> float | Tensor | None capabilitiesCapability | int | None | Capabilities to run within: every CPU one by default, or for packed operands the mask that packed them. | |
|---|---|---|
streamint | None | A GPU stream pointer, left None on the CPU. |