# Probability Metrics

> NumKong for Go

Kullback-Leibler divergence and Jensen-Shannon distance for probability distributions.

```go
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).

`import "github.com/ashvardanian/NumKong"`

## JensenShannonF32

JensenShannonF32 computes the Jensen-Shannon distance between two float32 distributions.

```go
func JensenShannonF32(a, b []float32) float64
```

Both slices must have the same length.

## JensenShannonF64

JensenShannonF64 computes the Jensen-Shannon distance between two float64 distributions.

```go
func JensenShannonF64(a, b []float64) float64
```

Both slices must have the same length.

## KullbackLeiblerF32

KullbackLeiblerF32 computes the Kullback-Leibler divergence between two float32 distributions.

```go
func KullbackLeiblerF32(a, b []float32) float64
```

Both slices must have the same length.

## KullbackLeiblerF64

KullbackLeiblerF64 computes the Kullback-Leibler divergence between two float64 distributions.

```go
func KullbackLeiblerF64(a, b []float64) float64
```

Both slices must have the same length.

