TransWikia.com

distributions.asy and Asymptote users

TeX - LaTeX Asked by Nguyen Van Justonly Chi on December 18, 2020

I have had a look at Common library of generic distributions in probabilities? before.

It cause me to do distributions.asy which is in the answer.

Preface,

  • I am not the person who have more knowledges about probability distribution.
  • It can still be updated by myself for the simple knowledges which I can do.

Suggestion:

I hope that anyone who have more knowledges about probability distribution and a little of Asymptote care about it.

Feel free to recheck, contribute, improve this package by adding an answer (your contribution).

I really appreciate your help with this package!

One Answer

distributions.asy

The current version is 0.2.

*** Version 0.2  8/26/2020 ***
- Add several new distributions (include PDF and CDF)
// Supported on a bounded interval
PERT distribution
Raised cosine distribution
Reciprocal distribution
Triangular distribution
Trapezoidal distribution
Truncated normal distribution
U-quadratic distribution
Wigner semicircle distribution
Continuous Bernoulli distribution
// Supported on intervals of length 2π – directional distributions
von Mises distribution              (incompleted)
Wrapped normal distribution
Wrapped exponential distribution
Wrapped Lévy distribution
Wrapped Cauchy distribution         (incompleted)
Wrapped asymmetric Laplace distribution
// Supported on semi-infinite intervals, usually [0,+infinity)
Inverse Gaussian distribution
Lévy distribution
Log-Cauchy distribution
Log-Laplace distribution
Log-logistic distribution
Lomax distribution
Mittag-Leffler distribution   (no data)
Nakagami distribution
Rice distribution           (incompleted)
Shifted Gompertz distribution
*** Version 0.1 8/23-24/2020 ***
- Rearrange the old distributions (NEW)
- Add several new distributions (include PDF and CDF)
The contents:
// Continuous distributions
// Supported on a bounded interval
- Arcsine distribution
- The Beta distribution
- The Logit normal Distribution
- The Flat (Uniform) Distribution
- Irwin–Hall distribution
- The Bates distribution
- Kumaraswamy distribution
// Supported on semi-infinite intervals, usually [0,+infinity)
- The Beta prime distribution
- Birnbaum–Saunders distribution (Fatigue Life Distribution)
- Chi distribution
- The Chi-squared distribution
- Dagum distribution
- The Exponential distribution
- Exponential-logarithmic distribution
- The F-distribution
- Folded normal distribution
- Fréchet distribution
- The Gamma distribution
- Generalized gamma distribution
- Generalized Pareto distribution
- Gamma/Gompertz distribution
- Gompertz distribution
- Half-normal distribution
- The Lognormal Distribution
- The Pareto (Type I) Distribution
- The Rayleigh distribution
- Type-2 Gumbel distribution
- The Weibull Distribution
// Supported on the whole real line
- The Cauchy distribution
- The Generalized Normal (version 1)
- The Generalized Normal (version 2)
- Gumbel distribution
- The Landau Distribution
- The Laplace distribution
- The Logistic distribution
- The Normal distribution (Gauss)
- The Student's t-distribution
- Type-1 Gumbel distribution
*** Version 0.0 8/21-22/2020 ***
This package has the following distributions (in gsl.cc): (include PDF and CDF)
- The Normal distribution (Gauss)
- The Cauchy distribution
- The Exponential distribution
- The Laplace distribution
- The Generalized Normal (version 1)
- The Generalized Normal (version 2)
- The Gamma distribution
- The Rayleigh distribution
- The Chi-squared distribution
- The Logistic distribution
- The Student's t-distribution
- The Beta distribution
- The Weibull Distribution
- The Pareto (Type I) Distribution
- The Flat (Uniform) Distribution
- The Lognormal Distribution
- The F-distribution
- Type-1 Gumbel distribution
- Type-2 Gumbel distribution
- Gumbel distribution
- Fréchet distribution
- The Landau Distribution
*/

The first example: (probability density function and cumulative distribution function for normal distribution)

usepackage("amsmath");
unitsize(x=3cm,y=5cm);
size(300);
import graph;
import distributions;

transform tr[]={
   identity(),
   shift(0,-1.5)
};
guide g1=graph(NormaldistributionPDF(sigma=.5),-2,2, n=300);
guide g2=graph(NormaldistributionCDF(sigma=.5),-2,2, n=300);

draw(tr[0]*g2,black+1bp);
draw(tr[1]*g1,red+1bp);

real marginx=0.02, marginy=0.02;
for (transform m : tr){
draw(Label("$x$",Relative(.99)),m*((-2,0)--(2,0)),Arrow);
draw(Label("$y$",Relative(.99)),m*((0,0)--(0,1.25)),Arrow);
for (real u=0.25; u <= 1.05; u=u+0.25){
draw(scale(0.6)*Label("$"+(string) u+"$",Relative(0)),m*((0,u)-(marginx,0)--(0,u)+(marginx,0)));
}
for (real u=-2; u<= 1; u=u+1){
draw(scale(0.6)*Label("$"+(string) u+"$",Relative(0)),m*((u,0)-(0,marginy)--(u,0)+(0,marginy)));
}
}
label(scale(.8)*Label("$f(x)=dfrac{1}{sigmasqrt{2pi}},e^{-dfrac{(x-mu)^2}{2sigma{}^2}}$"),
      tr[1]*(-1.4,0.5));
shipout(bbox(2mm,invisible));

enter image description here

And its animation!

import animate;
settings.tex="pdflatex"; 

import graph;
import distributions;
usepackage("amsmath");
unitsize(x=3cm,y=5cm);
size(300);
animation Ani;

transform tr[]={
   identity(),
   shift(0,-1.5)
};

guide g2=graph(NormaldistributionCDF(sigma=.5),-2,2, n=300);
guide g1=graph(NormaldistributionPDF(sigma=.5),-2,2, n=300);

for(real a=-1.9; a<= 1.9; a=a+0.1)
{
save();
path c1=tr[1]*(graph(NormaldistributionPDF(sigma=.5),-2,a, n=300)--(a,0)--cycle);
fill(c1,red+opacity(.3));
path c2=tr[1]*(a,0)--tr[0]*(a,NormaldistributionCDF(sigma=.5)(a))--tr[0]*(0,NormaldistributionCDF(sigma=.5)(a));
draw(c2,dashed);

draw(tr[0]*g2,black+1bp);
draw(tr[1]*g1,red+1bp);

real marginx=0.02, marginy=0.02;
for (transform m : tr){
draw(Label("$x$",Relative(.99)),m*((-2,0)--(2,0)),Arrow);
draw(Label("$y$",Relative(.99)),m*((0,0)--(0,1.25)),Arrow);
for (real u=0.25; u <= 1.05; u=u+0.25){
draw(scale(0.6)*Label("$"+(string) u+"$",Relative(0)),m*((0,u)-(marginx,0)--(0,u)+(marginx,0)));
}
for (real u=-2; u<= 1; u=u+1){
draw(scale(0.6)*Label("$"+(string) u+"$",Relative(0)),m*((u,0)-(0,marginy)--(u,0)+(0,marginy)));
}
}
label(scale(.8)*Label("$f(x)=dfrac{1}{sigmasqrt{2pi}},e^{-dfrac{(x-mu)^2}{2sigma{}^2}}$"),
      tr[1]*(-1.4,0.5));
Ani.add();
restore();
}
erase();
Ani.movie(BBox(2mm,Fill(white)));

enter image description here

The final example: The PDF of Weibull distribution.

import graph;
import distributions;
unitsize(2cm);

guide g1=graph(WeibulldistributionPDF(lambda=1,k=0.5),0,2.5, n=300);
guide g2=graph(WeibulldistributionPDF(lambda=1,k=1),0,2.5, n=300);
guide g3=graph(WeibulldistributionPDF(lambda=1,k=1.5),0,2.5, n=300);
guide g4=graph(WeibulldistributionPDF(lambda=1,k=5),0,2.5, n=300);

real marginx=0.05, marginy=0.05;
real xdistance=-0.1;

draw(g1,blue+0.7bp,"$lambda=1,,k=0.5$");
draw(g2,red+0.7bp,"$lambda=1,,k=1$");
draw(g3,orange+.7bp,"$lambda=1,,k=1.5$");
draw(g4,green+.7bp,"$lambda=1,,k=5$");

clip(box((0,0),(2.5,2.5)));
draw(box((0,0),(2.5,2.5)));

for (real u=0; u <= 2.5; u=u+0.5){
draw(scale(0.6)*Label("$"+(string) u+"$",Relative(0)),(0,u)--(0,u)+(marginx,0));
}
for (real u=0; u <= 2.5; u=u+0.5){
draw(scale(0.6)*Label("$"+(string) u+"$",Relative(0)),(u,0)--(u,0)+(0,marginy));
}
attach(scale(0.5)*legend(1),(2.5,2.5),align=(-1,-1));
shipout(bbox(2mm,invisible));

If you know more graph.asy, the code above may be shorter!

enter image description here

The remaining simple examples will be uploaded in https://github.com/user213378/distributions

Answered by Nguyen Van Justonly Chi on December 18, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP