Skip to content

Commit

Permalink
docs:Added histograms.
Browse files Browse the repository at this point in the history
  • Loading branch information
antononcube committed Jul 31, 2024
1 parent b7a6d2c commit a8f39ef
Show file tree
Hide file tree
Showing 2 changed files with 262 additions and 120 deletions.
40 changes: 30 additions & 10 deletions docs/Random-variate-generation-examples-work.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ use Text::Plot;

```raku
my $beta = BetaDistribution.new(4, 4);
my @res = random-variate($beta, 12);
my @res = random-variate($beta, 200);

records-summary(@res);
```

```perl6
text-histogram(@res, title => 'Beta Distribution')
```


### Bernoulli Distribution

[Bernoulli distribution](https://en.wikipedia.org/wiki/Bernoulli_distribution) is a discrete probability distribution that takes the value 1 with probability p and the value 0 with probability 1-p.
Expand All @@ -47,33 +52,44 @@ records-summary(@res);

```raku
my $discrete_uniform = DiscreteUniformDistribution.new(:min(10), :max(20));
my @res = random-variate($discrete_uniform, 12);
my @res = random-variate($discrete_uniform, 200);

records-summary(@res);
```

```perl6
text-list-plot(@res.&tally.kv.rotor(2), title => 'Discrete Uniform Distribution tallies')
```

### Normal Distribution

[Normal distribution](https://en.wikipedia.org/wiki/Normal_distribution) is a continuous probability distribution that is defined by two parameters, the mean and the standard deviation. The normal distribution is also known as the Gaussian distribution.

```raku
my $normal = NormalDistribution.new(:mean(10), :sd(20));
my @res = random-variate($normal, 12);
my $normal = NormalDistribution.new(:mean(10), :sd(2));
my @res = random-variate($normal, 200);

records-summary(@res);
```

```perl6
text-histogram(@res, title => 'Normal Distribution')
```

### Uniform Distribution

[Uniform distribution](https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)) is a continuous probability distribution that is defined by two parameters, the minimum and the maximum. The uniform distribution is also known as the rectangular distribution.

```raku
my $uniform = UniformDistribution.new(:min(10), :max(20));
my @res = random-variate($uniform, 12);
my $uniform = UniformDistribution.new(:min(-10), :max(5));
my @res = random-variate($uniform, 200);

records-summary(@res);
```

```perl6
text-histogram(@res, title => 'Uniform Distribution')
```

----

Expand All @@ -92,7 +108,7 @@ records-summary(@res, field-names => ['0', '1']);
```

```perl6
text-list-plot(@res, width => 60, height => 20)
text-list-plot(@res, width => 60, height => 20, title => 'Binormal Distribution random variates')
```

-----
Expand All @@ -104,12 +120,16 @@ text-list-plot(@res, width => 60, height => 20)
[Mixture distribution](https://en.wikipedia.org/wiki/Mixture_distribution) is a probability distribution that is a weighted sum of two or more other probability distributions.

```raku
my $mixture = MixtureDistribution.new([2, 5], [NormalDistribution.new(3, 4), NormalDistribution.new(6, 5)]);
my @res = random-variate($mixture, 12);
my $mixture = MixtureDistribution.new([2, 5], [NormalDistribution.new(3, 4), NormalDistribution.new(16, 5)]);
my @res = random-variate($mixture, 300);

records-summary(@res);
```

```perl6
text-histogram(@res, title => 'Mixture Distribution', width => 80)
```

### Product Distribution

[Product distribution](https://en.wikipedia.org/wiki/Product_distribution) is a probability distribution that is the product of two or more other probability distributions.
Expand All @@ -122,7 +142,7 @@ records-summary(@res, field-names => ['0', '1']);
```

```perl6
text-list-plot(@res, width => 60, height => 20)
text-list-plot(@res, width => 60, height => 20, title => "Product Distribution random variates")
```

--------
Expand Down
Loading

0 comments on commit a8f39ef

Please sign in to comment.