1 |
|
2 |
|
3 | # Function kldivergence
|
4 |
|
5 | Calculate the Kullback-Leibler (KL) divergence between two distributions
|
6 |
|
7 |
|
8 | ## Syntax
|
9 |
|
10 | ```js
|
11 | math.kldivergence(x, y)
|
12 | ```
|
13 |
|
14 | ### Parameters
|
15 |
|
16 | Parameter | Type | Description
|
17 | --------- | ---- | -----------
|
18 | `q` | Array | Matrix | First vector
|
19 | `p` | Array | Matrix | Second vector
|
20 |
|
21 | ### Returns
|
22 |
|
23 | Type | Description
|
24 | ---- | -----------
|
25 | number | Returns distance between q and p
|
26 |
|
27 |
|
28 | ## Examples
|
29 |
|
30 | ```js
|
31 | math.kldivergence([0.7,0.5,0.4], [0.2,0.9,0.5]) //returns 0.24376698773121153
|
32 |
|
33 | ```
|
34 |
|
35 |
|