# kullbackLeiblerDivergence

> **kullbackLeiblerDivergence**(`first`, `second`): `number`

Defined in: [packages/distance/src/kullback-leibler.ts:34](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/distance/src/kullback-leibler.ts#L34)

Directional relative entropy D(first || second) in nats. The vectors describe the same ordered outcomes. Entries must be probabilities and each total must be within the distribution module’s probability-table tolerance of one. Accepted vectors are normalized by their totals. A positive first mass paired with zero second mass returns Infinity. Takes O(n) time and O(1) space.

## Parameters

### first

[`NumericVector`](/reference/knotkit/distance/type-aliases/numericvector/)

### second

[`NumericVector`](/reference/knotkit/distance/type-aliases/numericvector/)

## Returns

`number`

## Throws

With `INVALID_DIMENSION` or `INVALID_PROBABILITIES`.
