mirror of
https://github.com/gonum/gonum.git
synced 2025-10-20 05:54:41 +08:00
Fixed spelling of Kullback-Leibler.
This commit is contained in:
8
stat.go
8
stat.go
@@ -328,12 +328,12 @@ func Histogram(count, dividers, x, weights []float64) []float64 {
|
||||
return count
|
||||
}
|
||||
|
||||
// KulbeckLeibler computes the Kulbeck-Leibler distance between the
|
||||
// KullbackLeibler computes the Kullback-Leibler distance between the
|
||||
// distributions p and q. The natural logarithm is used.
|
||||
// sum_i(p_i * log(p_i / q_i))
|
||||
// Note that the Kulbeck-Leibler distance is not symmetric;
|
||||
// KulbeckLeibler(p,q) != KulbeckLeibler(q,p)
|
||||
func KulbeckLeibler(p, q []float64) float64 {
|
||||
// Note that the Kullback-Leibler distance is not symmetric;
|
||||
// KullbackLeibler(p,q) != KullbackLeibler(q,p)
|
||||
func KullbackLeibler(p, q []float64) float64 {
|
||||
if len(p) != len(q) {
|
||||
panic("stat: slice length mismatch")
|
||||
}
|
||||
|
12
stat_test.go
12
stat_test.go
@@ -320,24 +320,24 @@ the count field in order to avoid extra garbage`)
|
||||
// Weighted Hist = [77 175 275 375 423 627 675 775 783 1067]
|
||||
}
|
||||
|
||||
func ExampleKulbeckLiebler() {
|
||||
func ExampleKullbackLeibler() {
|
||||
|
||||
p := []float64{0.05, 0.1, 0.9, 0.05}
|
||||
q := []float64{0.2, 0.4, 0.25, 0.15}
|
||||
s := []float64{0, 0, 1, 0}
|
||||
|
||||
klPQ := KulbeckLeibler(p, q)
|
||||
klPS := KulbeckLeibler(p, s)
|
||||
klPP := KulbeckLeibler(p, p)
|
||||
klPQ := KullbackLeibler(p, q)
|
||||
klPS := KullbackLeibler(p, s)
|
||||
klPP := KullbackLeibler(p, p)
|
||||
|
||||
fmt.Println("Kulbeck-Liebler is one measure of the difference between two distributions")
|
||||
fmt.Println("Kullback-Leibler is one measure of the difference between two distributions")
|
||||
fmt.Printf("The K-L distance between p and q is %.4f\n", klPQ)
|
||||
fmt.Println("It is impossible for s and p to be the same distribution, because")
|
||||
fmt.Println("the first bucket has zero probability in s and non-zero in p. Thus,")
|
||||
fmt.Printf("the K-L distance between them is %.4f\n", klPS)
|
||||
fmt.Printf("The K-L distance between identical distributions is %.4f\n", klPP)
|
||||
|
||||
// Kulbeck-Liebler is one measure of the difference between two distributions
|
||||
// Kullback-Leibler is one measure of the difference between two distributions
|
||||
// The K-L distance between p and q is 0.8900
|
||||
// It is impossible for s and p to be the same distribution, because
|
||||
// the first bucket has zero probability in s and non-zero in p. Thus,
|
||||
|
Reference in New Issue
Block a user