func JensenShannonF32(a, b []float32) float64 Both slices must have the same length.
Kullback-Leibler divergence and Jensen-Shannon distance for probability distributions.
package main
import (
"fmt"
nk "github.com/ashvardanian/NumKong/golang"
)
func main() {
p := []float64{0.25, 0.25, 0.25, 0.25}
q := []float64{0.1, 0.2, 0.3, 0.4}
fmt.Println(nk.KullbackLeiblerF64(p, q)) // KL divergence
fmt.Println(nk.JensenShannonF64(p, q)) // JS distance (symmetric)
}KullbackLeiblerF64 and JensenShannonF64 take []float64 and return float64. KullbackLeiblerF32 and JensenShannonF32 take []float32 and return float64 (widened).
JensenShannonF32JensenShannonF32 computes the Jensen-Shannon distance between two float32 distributions.func JensenShannonF32(a, b []float32) float64 Both slices must have the same length.
JensenShannonF64JensenShannonF64 computes the Jensen-Shannon distance between two float64 distributions.func JensenShannonF64(a, b []float64) float64 Both slices must have the same length.
KullbackLeiblerF32KullbackLeiblerF32 computes the Kullback-Leibler divergence between two float32 distributions.func KullbackLeiblerF32(a, b []float32) float64 Both slices must have the same length.
KullbackLeiblerF64KullbackLeiblerF64 computes the Kullback-Leibler divergence between two float64 distributions.func KullbackLeiblerF64(a, b []float64) float64 Both slices must have the same length.