https://github.com/oelin/surprisal
Compute the surprisal of an event given its probability.
https://github.com/oelin/surprisal
probability statistics suprisal
Last synced: 3 months ago
JSON representation
Compute the surprisal of an event given its probability.
- Host: GitHub
- URL: https://github.com/oelin/surprisal
- Owner: oelin
- License: mit
- Created: 2023-02-03T12:02:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-03T13:57:58.000Z (over 2 years ago)
- Last Synced: 2024-04-26T15:03:09.038Z (about 1 year ago)
- Topics: probability, statistics, suprisal
- Language: JavaScript
- Homepage: https://npmjs.com/surprisal
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# surprisal
Compute the surprisal of an event given its probability.
## Installation
```sh
npm i surprisal
```## Usage
```js
import surprisal from 'surprisal'surprisal(0.5) // returns 1.0
surprisal(1.0) // returns 0.0
surprisal(0.0) // returns Infinity
```Suprisal is given in bits (base 2) by default, however you can also specify other bases via the second argument. For example, to compute surprisal in nats (base 10):
```js
surprisal(0.5, base=10) // returns 0.301
```