function kullbackleibler(
a: Float64Array | Float32Array,
b: Float64Array | Float32Array,
): number function kullbackleibler(
a: Float64Array | Float32Array | Uint16Array,
b: Float64Array | Float32Array | Uint16Array,
dtype: DType,
): number function kullbackleibler(a: TensorBase, b: TensorBase): number Both vectors must represent valid probability distributions, non-negative and summing to 1. Supports f64 and f32, auto-detected, and f16 and bf16 with an explicit dtype.
Parameters
a | The first probability distribution, as Float32Array, Float64Array, or TensorBase. | |
|---|---|---|
b | The second probability distribution, matching the type and length of a. | |
dtypeDType | Optional dtype string for custom types, e.g. 'f16', 'bf16'. |
Returns
The Kullback-Leibler divergence KL(a || b) = Σ a[i] · log(a[i] / b[i]).