#set term postscript eps enhanced
set term pstex monochrome
set samples 300
#set size 0.8,0.88  # paperback 6x9  #CHANGE THESE LATER IN FILE ALSO 
set size 1,1.1      # us letter      #IF MODIFIED 
set border 31 lw 0.5
set tics out
set ticscale 0.5 0.25
set xtics border nomirror norotate
set ytics border nomirror norotate
set format x "%g"

# Continuous distributions

set xlabel "$x$"
set ylabel "$p(x)$"

set xrange [-5:5]
set yrange [0:0.5]
set ytics 0.1
set xtics 1
set output "rand-gaussian.tex"
set title "Gaussian Distribution"
p(x)=1/sqrt(2*pi*sigma**2)*exp(-x**2/(2*sigma**2))
plot sigma=1.0, p(x) title "$\\sigma=1$", \
	sigma=2.0, p(x) title "$\\sigma=2$"

set xrange [0:5]
set yrange [0:2]
set ytics 0.5
set xtics 1
set output "rand-gaussian-tail.tex"
set title "Gaussian Tail Distribution"
p(x)= x > a ? 1/(0.5*erfc(a/sqrt(2*sigma**2))*sqrt(2*pi*sigma**2))*exp(-x**2/(2*sigma**2)) : 0
plot a=1.5, sigma=1.0, p(x) title "$\\sigma=1,a=1.5$"

set xrange [0:5]
set yrange [0:1.09]
set ytics 0.5
set xtics 1
set output "rand-rayleigh-tail.tex"
set title "Rayleigh Tail Distribution"
p(x)= x > a ? (x/sigma**2)*exp((a**2 - x**2)/(2*sigma**2)) : 0
plot a=1.0, sigma=1.0, p(x) title "$a=1,\\sigma=1$", \
	a=0.5, sigma=2.0, p(x) title "$a=0.5,\\sigma=2$"

set size ratio -1 0.8,1.143
set xlabel "$x$"
set ylabel "$y$"
set xrange [-2:2]
set yrange [-2:2]
set ytics 1
set xtics 1
set output "rand-bivariate-gaussian.tex"
set title "Bivariate Gaussian Distribution"
set isosamples 30
p(x,y)=1/sqrt(2*pi*sqrt(1-rho**2))*exp(-(x**2 + y**2 - 2*rho*x*y)/(2*(1-rho**2)))
#set cntrparam cspline
set noclabel
set contour
set view 0,0
set nosurface
splot rho=0.9, p(x,y) title "$\\sigma_x=1, \\sigma_y=1, \\rho=0.9$"
set size noratio 1,1.1  # us letter

set xlabel "$x$"
set ylabel "$p(x)$"
set ytics 0.1
set xrange [-5:5]
set yrange [0:0.4]
set output "rand-cauchy.tex"
set title "Cauchy Distribution"
p(x)=1/(pi*a*(1+(x/a)**2))
plot a=1.0, p(x) title "$a=1$", \
	a=2.0, p(x) title "$a=2$"

set ytics 0.5
set yrange [0:1]
set xrange [0:3]
set output "rand-exponential.tex"
set title "Exponential Distribution"
p(x)=exp(-x/mu)/mu
plot mu=1.0, p(x) title "$\\mu=1$", \
	mu=2.0, p(x) title "$\\mu=2$"

set yrange [0:1]
set xrange [0:3]
set output "rand-chisq.tex"
set title "Chi-squared Distribution"
p(x)=(x/2)**(nu/2.0-1.0) *exp(-x/2)/ (2*gamma(nu/2.0))
plot nu=1.0, p(x) title "$\\nu=1$", \
      nu=2.0, p(x) title "$\\nu=2$", \
	nu=3.0, p(x) title "$\\nu=3$"

set yrange [0:1]
set xrange [0:5]
set output "rand-erlang.tex"
set title "Erlang Distribution"
p(x)=x**(n-1) *exp(-x/a)/ (gamma(n)*a**n)
plot n=1.0, a=1, p(x) title "$n=1$", \
      n=2.0, a=1.0, p(x) title "$n=2$", \
	n=3.0, a=1.0, p(x) title "$n=3$"

set xrange [0:2]
set xtics 1
set output "rand-fdist.tex"
set title "F-Distribution"
p(x)=gamma((v1+v2)/2.0)*v1**(v1/2.0)*v2**(v2/2.0)\
	/gamma(v1/2.0)/gamma(v2/2.0) * \
	x**(v1/2.0-1)*(v2+v1*x)**-(v1/2.0+v2/2.0)
plot v1=1.0, v2=1.0, p(x) title "$\\nu_1=1, \\nu_2=1$", \
      v1=3.0, v2=1.0, p(x) title "$\\nu_1=3, \\nu_2=2$"

set xrange [0:5]
set output "rand-flat.tex"
set title "Flat Distribution"
p(x)= (x<b && x>a) ? 1/(b-a) : 0
plot a=0.5, b=2.5, p(x) title "$a=0.5,b=2.5$" with step, \
      a=1.2, b=4.8, p(x) title "$a=1.2,b=4.8$" with step

set xrange [0:5]
set yrange [0:1]
set ytics 0.5
set output "rand-gamma.tex"
set title "Gamma Distribution"
p(x)= x**(a-1)* exp(-x) / gamma(a)
plot a=1.0, p(x) title "$a=1$", \
      a=2.0, p(x) title "$a=2$", \
      a=3.0, p(x) title "$a=3$"

set xrange [0:1]
set yrange [0:4]
set xtics 0.25
set ytics 1
set output "rand-beta.tex"
set title "Beta Distribution"
p(x)= gamma(a+b)/(gamma(a)*gamma(b))*x**(a-1)*(1-x)**(b-1)
plot a=2.0, b=2.0, p(x) title "$a=2,b=2$", \
      a=4.0, b=1.0, p(x) title "$a=4,b=1$", \
      a=1.0, b=4.0, p(x) title "$a=1,b=4$"


set xrange [-5:5]
set yrange [0:0.3]
set ytics 0.1
set xtics 1
set output "rand-logistic.tex"
set title "Logistic Distribution"
p(x)= exp(-x/a)/a/(1+exp(-x/a))**2
plot a=1.0, p(x) title "$a=1$", \
	a=2.0, p(x) title "$a=2$"

set xrange [0:3]
set yrange [0:0.7]
set xtics 1
set ytics 0.5
set output "rand-lognormal.tex"
set title "Lognormal Distribution"
p(x)= exp(-(log(x)-zeta)**2/2/sigma**2)/sqrt(2*pi*sigma**2)/x
plot zeta=0.0, sigma=1.0, p(x) title "$\\zeta=0, \\sigma=1$", \
	zeta=1.0, sigma=1.0, p(x) title "$\\zeta=1, \\sigma=1$"

set xrange [0:5]
set yrange [0:2]
set ytics 0.5
set xtics 1
set output "rand-pareto.tex"
set title "Pareto Distribution"
p(x)= x>b ? a*b**a/x**(a+1) : 0
plot a=1.0, b=1, p(x) title "$a=1, b=1$", \
	a=3.0, b=2, p(x) title "$a=3, b=2 $"

set xrange [0:5]
set yrange [0:0.7]
set ytics 0.1
set xtics 1
set output "rand-rayleigh.tex"
set title "Rayleigh Distribution"
p(x)= (x/sigma**2)*exp(-x**2/(2*sigma**2))
plot sigma=1.0, p(x) title "$\\sigma=1$", \
	sigma=2.0, p(x) title "$\\sigma=2$"

set xrange [0:5]
set yrange [0:1.09]
set ytics 0.5
set xtics 1
set output "rand-rayleigh-tail.tex"
set title "Rayleigh Tail Distribution"
p(x)= x > a ? (x/sigma**2)*exp((a**2 - x**2)/(2*sigma**2)) : 0
plot a=1.0, sigma=1.0, p(x) title "$a=1,\\sigma=1$", \
	a=0.5, sigma=2.0, p(x) title "$a=0.5,\\sigma=2$"

set xrange [-4:4]
set yrange [0:0.5]
set ytics 0.1
set output "rand-tdist.tex"
set title "Student's t distribution"
p(x)=gamma((v+1.0)/2)/sqrt(pi*v)/gamma(v/2)*(1+(x**2)/v)**-((v+1.0)/2)
plot v=1.0, p(x) title "$\\nu_1=1$", \
      v=5.0, p(x) title "$\\nu_1=5$"

set xrange [-5:5]
set yrange [0:0.55]
set ytics 0.1
set output "rand-laplace.tex"
set title "Laplace Distribution (Two-sided Exponential)"
p(x)=exp(-abs(x)/a)/2/a
plot a=1.0, p(x) title "$a=1$", \
	a=2.0, p(x) title "$a=2$"

set xrange [-5:5]
set yrange [0:0.8]
set ytics 0.2
set output "rand-exppow.tex"
set title "Exponential Power Distribution"
p(x)=exp(-(abs(x/a))**b)/2/a/gamma(1.0+1.0/b)
plot a=1.0, b=2.5, p(x) title "$a=1, b=2.5$", \
	a=1.0, b=0.5, p(x) title "$a=1, b=0.5$"

set xrange [-5:10]
set yrange [0:0.2]
set ytics 0.1
set output "rand-landau.tex"
set title "Landau Distribution"
plot 'landau.dat' notitle w lines

set xrange [-5:5]
set yrange [0:0.45]
set ytics 0.1
set output "rand-levy.tex"
set title "Levy Distribution"
p1(x)=1/(pi*mu*(1+(x/mu)**2))
p2(x)=1/sqrt(2*pi*2*mu**2)*exp(-x**2/(4*mu**2)) 
plot mu=1.0, a=1, p1(x) title "$c=1, \\alpha=1.0$", \
	mu=1.0, a=2, p2(x) title "$c=1, \\alpha=2.0$"

set xrange [-5:5]
set yrange [0:0.35]
set ytics 0.05
set output "rand-levyskew.tex"
set title "Levy Skew Distribution"
logp(x)= -1.34229+x*(-0.354314+x*(-0.322538+x*(0.205603+x*(-0.0518879+x*(0.00569502+x*-0.000224843)))))
p1(x)=exp(logp(x))
plot mu=1.0, a=1, p1(x) title "$c=1, \\alpha=1.0, \\beta=1.0$"


set xrange [0:2]
set yrange [0:1.5]
set ytics 0.5
set xtics 0.5
set output "rand-weibull.tex"
set title "Weibull Distribution"
p(x)=(b/a) * (x/a)**(b-1) * exp(-(x/a)**b)
plot a=1.0, b=1.0, p(x) title "$a=1,b=1$", \
       a=1.0, b=2.0, p(x) title "$a=1,b=2$", \
	 a=2.0, b=3.0, p(x) title "$a=2,b=3$"

set xrange [-2:5]
set yrange [0:0.5]
set ytics 0.1
set xtics 1.0
set output "rand-gumbel1.tex"
set title "Type 1 Gumbel Distribution"
p1(x)=a*b*exp(-(b*exp(-a*x)+a*x))
plot a=1.0, b=1.0, p1(x) title "Type 1, $a=1,b=1$"

set xrange [0:2]
set yrange [0:0.7]
set ytics 0.1
set xtics 0.5
set output "rand-gumbel2.tex"
set title "Type 2 Gumbel Distribution"
p2(x)=x > 0 ? a*b*x**(-a-1)*exp(-b*x**-a) : 0
plot a=1.0, b=1.0, p2(x) title "Type 2, $a=1,b=1$"

# Discrete distributions

set xlabel "$k$"
set ylabel "$p(k)$"
set ticscale 0.5 1
set mxtics 2

set xrange [-0.5:10.5]
set yrange [0:0.3]
set ytics 0.1
set xtics 1
set function style step
set output "rand-poisson.tex"
set title "Poisson Distribution"
p(x)=mu**int(x)/(int(x)!) * exp(-mu)
plot mu=2.5, p(x+0.5) title "$\\mu=2.5$"

set xrange [:1.5]
set yrange [0:1]
set ytics 0.5
set xtics 1
set function style step
set output "rand-bernoulli.tex"
set title "Bernoulli Trial"
p(x)= (int(x) == 0) ? 1-p : p
plot p = 0.7, p(x+0.5) title "$p=0.7$"

set xrange [:10.5]
set yrange [0:0.3]
set xtics 1
set ytics 0.1
set output "rand-binomial.tex"
set title "Binomial Distribution"
p(x)= P**int(x)*(1-P)**(n-int(x))*gamma(n+1.0)/gamma(int(x)+1.0)/gamma(n-int(x)+1.0) + 1e-5
plot P=0.5,n=9.99999999, p(x+0.5) title "$p=0.5,n=9$"

set xrange [:5.5]
set yrange [0:0.7]
set ytics 0.1
set xtics 1
set output "rand-geometric.tex"
set title "Geometric Distribution"
p(x)=int(x) ? P*(1-P)**int(x-1) : 0
plot P=0.5, p(x+0.5) title "$p=0.5$"

set xrange [:10.5]
set yrange [0:0.7]
set ytics 0.1
set xtics 1
set output "rand-logarithmic.tex"
set title "Logarithmic Distribution"
p(x)=int(x) ? (-1/log(1-P))*(P**int(x))/int(x) : 0
plot P=0.7, p(x+0.5) title "$p=0.7$"

set xrange [:10.5]
set yrange [0:0.7]
set ytics 0.1
set xtics 1
set output "rand-hypergeometric.tex"
set title "Hypergeometric Distribution"
choose(a,b)=gamma(a+1)/(gamma(b+1)*gamma(a-b+1))
p(x)=choose(n1,int(x))*choose(n2,t-int(x))/choose(n1+n2,t)
plot n1=5, n2=20, t=3, p(x+0.5) title "$n1=5, n2=20, t=3$"

set xrange [:10.5]
set yrange [0:0.3]
set xtics 1
set ytics 0.1
set output "rand-nbinomial.tex"
set title "Negative Binomial Distribution"
p(x)= (P**n)*((1-P)**(int(x)))*gamma(n+int(x))/gamma(n)/gamma(int(x)+1.0) + 1e-5
plot P=0.5,n=3.5, p(x+0.5) title "$p=0.5,n=3.5$"

set xrange [:10.5]
set yrange [0:0.3]
set xtics 1
set ytics 0.1
set output "rand-pascal.tex"
set title "Pascal Distribution"
p(x)= (P**n)*((1-P)**(int(x)))*gamma(n+int(x))/gamma(n)/gamma(int(x)+1.0) + 1e-5
plot P=0.5,n=3, p(x+0.5) title "$p=0.5,n=3$"

######################################################################

set ticscale 1 0
set xrange [-5:5]
set yrange [-5:5]
set xtics 1
set ytics 1
set size 0.8,1.143
set size square
set output "random-walk.tex"
set title "Random walks"
set xzeroaxis
set yzeroaxis
set nokey
set noxlabel
set noylabel
plot "rand-walk.dat" using 1:2 with linesp


