Post Reply 
Distributions
02-19-2015, 03:58 PM (This post was last modified: 05-02-2015 04:57 PM by salvomic.)
Post: #7
RE: Distributions
Weibull and Weibull translated

Code:

EXPORT weibull(k, l, t)
// Weibull distribution: l=λ>0 scale param (characteristic lifetime), k>0 shape parameter t var (time)
// weibull(λ,1) = exponential(1/λ), weibull(λ,2) = Rayleigh(λ/sqrt(2))
BEGIN
local f;
f:= piecewise(t<0,0,  (k/l)*(t/l)^(k-1)*e^(-(t/l)^k));
return f;
END;

EXPORT weibull_cdf(k, l, t)
BEGIN
local f;
f:= piecewise(t<=0,0, 1-e^(-(t/l)^k)) ;
return f;
END ;

EXPORT weibull_translate(k, l, v, t)
// Weibull distribution translated: v (or θ theta) location parameter, normally 0
BEGIN
local f;
f:= piecewise(t<=v,0,  (k/l)*((t-v)/l)^(k-1)*e^(-((t-v)/l)^k));
return f;
END;

EXPORT weibull_translate_cdf(k, l, v, t)
BEGIN
local f;
f:= piecewise(t<=v,0, 1-e^(-((t-v)/l)^k)) ;
return f;
END ;

Cauchy
Code:

EXPORT cauchyd(x0,g,n)
// Cauchy distribution x0 location param, g=γ scale param, n var
BEGIN
local f;
f:= 1/ (pi*g*(1+((n-x0)/g)^2)) ;
return f;
END;

EXPORT cauchy_cdf(x0,g,n)
BEGIN
local f;
f:= (1/pi)*atan((n-x0)/g)+1/2 ;
return f;
END ;

EXPORT cauchy_icdf(x0,g,p)
// inverse x0, g=γ, p probability
BEGIN
local f;
f:= x0+g*tan(pi*(p-(1/2)));
return f;
END;

Beta
Code:

EXPORT betad(a, b, n)
// Beta distribution: a=α>0, b=β>0 shape param, n var (0<=n<=1)
BEGIN
local f;
f:= piecewise(n<0 ,0, n>=1, 0, (1/Beta(a,b))*(n^(a-1))*(1-n)^(b-1));
return f;
END;

EXPORT betad_cdf(a, b, n)
BEGIN
local f, b1;
b1:= int((X^(a-1))*(1-X)^(b-1),X,0,n);
// incomplete beta function
f:=piecewise(n<0,0,n>=1, 0,  b1/Beta(a,b));
return f;

END;

Gamma
Code:

EXPORT gammad(a,l,n)
// Gamma distribution 1st form a=α>0 shape param
//  l=λ>0 rate param, n var
// gammad::gamma2d α=k, β=1/θ
// gamma(1,1/λ) = expon(λ), gamma(n/2,1/2) = chi2(n)
BEGIN
local f;
f:= piecewise( n<0,0, (l*e^(-l*n)*(l*n)^(a-1))/Gamma(a)  );
END;

EXPORT gammad_cdf(a,l,n)
BEGIN
local f;
f:= int(X^(a-1)*e^(-X),X,0,l*n)/Gamma(a);
return f;
END ;

EXPORT gammad2(k,t,n)
// Gamma distribution 2nd form  k>0 shape param,
// t=θ>0 scale param, n var
// if k is N (natural) -> Erlang distribution (k=1 -> exponential)
BEGIN
local f;
f:=piecewise(n<0,0,  (n^(k-1)*e^(-n/t)) / ((t^k) * Gamma(k)) );
return f;
END;

EXPORT gammad2_cdf(k,t,n)
BEGIN
local f;
f:= int(X^(k-1)*e^(-X),X,0,n/t)/Gamma(k);
return f;
END ;

Zeta (Zpif)
Code:

EXPORT Zetazipf(s, k)
// Zeta (Zipf) distribution, not defined in s=1
BEGIN
local f;
IF s=1 THEN return "Not defined in s=1";  ELSE
f:= (k^(-s))/Zeta(s);
return f;
END;  //if
END;

EXPORT Zetazipf_cdf(s,k)
BEGIN
local f, hks;
hks:= sum(1/(X^s), X, 1, k);
// nth generalized armonic number
f:= hks/Zeta(s);
return f;

END;

Laplace
Code:

EXPORT laplaced(m,b,n)
// Laplace distribution m=μ location param, b scale param,  n var
// if m=0 and b=1 -> expond scaled by 1/2 (λ=1/b)
BEGIN
local f;
f:= (1/(2*b))*e^(-(ABS(n-m))/b);
return f;
END;

EXPORT laplaced_cdf(m,b,n)
BEGIN
local f;
f := piecewise(n<m, (1/2)*e^((n-m)/b), 1-(1/2)*e^(-(n-m)/b));
return f;
END ;

∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Distributions - salvomic - 02-18-2015, 11:10 PM
RE: Distributions - walter b - 02-19-2015, 06:18 AM
RE: Distributions - parisse - 02-19-2015, 07:35 AM
RE: Distributions - salvomic - 02-19-2015, 08:28 AM
RE: Distributions - Offroad - 02-19-2015, 11:58 AM
RE: Distributions - salvomic - 02-19-2015, 12:38 PM
RE: Distributions - salvomic - 02-19-2015 03:58 PM
RE: Distributions - salvomic - 02-19-2015, 08:27 PM
RE: Distributions - salvomic - 02-22-2015, 06:49 PM
RE: Distributions - salvomic - 03-01-2015, 05:05 PM
RE: Distributions - salvomic - 03-04-2015, 02:37 PM
RE: Distributions - salvomic - 04-08-2015, 11:00 AM
RE: Distributions - DrD - 04-08-2015, 01:22 PM
RE: Distributions - salvomic - 04-08-2015, 01:37 PM
RE: Distributions - Claudio L. - 04-08-2015, 10:04 PM
RE: Distributions - salvomic - 04-09-2015, 04:35 AM
RE: Distributions - Gerald H - 04-09-2015, 09:34 AM
RE: Distributions - Paul Dale - 04-08-2015, 09:33 PM
RE: Distributions - debrouxl - 04-09-2015, 05:53 PM



User(s) browsing this thread: 1 Guest(s)