deno.land / x / simplestatistic@v7.7.1 / src / bernoulli_distribution.js

bernoulli_distribution.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/** * The [Bernoulli distribution](http://en.wikipedia.org/wiki/Bernoulli_distribution) * is the probability discrete * distribution of a random variable which takes value 1 with success * probability `p` and value 0 with failure * probability `q` = 1 - `p`. It can be used, for example, to represent the * toss of a coin, where "1" is defined to mean "heads" and "0" is defined * to mean "tails" (or vice versa). It is * a special case of a Binomial Distribution * where `n` = 1. * * @param {number} p input value, between 0 and 1 inclusive * @returns {number[]} values of bernoulli distribution at this point * @throws {Error} if p is outside 0 and 1 * @example * bernoulliDistribution(0.3); // => [0.7, 0.3] */function bernoulliDistribution(p) /*: number[] */ { // Check that `p` is a valid probability (0 ≤ p ≤ 1) if (p < 0 || p > 1) { throw new Error( "bernoulliDistribution requires probability to be between 0 and 1 inclusive" ); }
return [1 - p, p];}
export default bernoulliDistribution;
simplestatistic

Version Info

Tagged at
2 years ago