forked from JuliaStats/Distributions.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce naming consistencies for TriangularDist, Triweight
- Loading branch information
Showing
3 changed files
with
37 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,60 @@ | ||
immutable Triweight <: ContinuousUnivariateDistribution | ||
location::Float64 | ||
scale::Float64 | ||
function Triweight(l::Real, s::Real) | ||
s > zero(s) || error("scale must be positive") | ||
@compat new(Float64(l), Float64(s)) | ||
μ::Float64 | ||
σ::Float64 | ||
function Triweight(μ::Real, σ::Real) | ||
σ > zero(σ) || | ||
throw(ArgumentError("Triweight: σ must be positive.")) | ||
@compat new(Float64(μ), Float64(σ)) | ||
end | ||
end | ||
|
||
Triweight(location::Real) = Triweight(location, 1.0) | ||
Triweight(μ::Real) = Triweight(μ, 1.0) | ||
Triweight() = Triweight(0.0, 1.0) | ||
|
||
@distr_support Triweight d.location-d.scale d.location+d.scale | ||
@distr_support Triweight d.μ - d.σ d.μ + d.σ | ||
|
||
## Parameters | ||
params(d::Triweight) = (d.location, d.scale) | ||
|
||
location(d::Triweight) = d.μ | ||
scale(d::Triweight) = d.σ | ||
params(d::Triweight) = (d.μ, d.σ) | ||
|
||
|
||
## Properties | ||
mean(d::Triweight) = d.location | ||
median(d::Triweight) = d.location | ||
mode(d::Triweight) = d.location | ||
mean(d::Triweight) = d.μ | ||
median(d::Triweight) = d.μ | ||
mode(d::Triweight) = d.μ | ||
|
||
var(d::Triweight) = d.scale*d.scale/9.0 | ||
var(d::Triweight) = d.σ^2 / 9.0 | ||
skewness(d::Triweight) = 0.0 | ||
kurtosis(d::Triweight) = 1/33-3 | ||
kurtosis(d::Triweight) = -2.9696969696969697 # 1/33-3 | ||
|
||
## Functions | ||
function pdf(d::Triweight, x::Real) | ||
u = abs(x - d.location)/d.scale | ||
u >= 1 ? 0.0 : 1.09375*(1-u*u)^3/d.scale | ||
u = abs(x - d.μ)/d.σ | ||
u >= 1 ? 0.0 : 1.09375*(1-u*u)^3/d.σ | ||
end | ||
|
||
function cdf(d::Triweight, x::Real) | ||
u = (x - d.location)/d.scale | ||
u = (x - d.μ)/d.σ | ||
u <= -1 ? 0.0 : u >= 1 ? 1.0 : 0.03125*(1+u)^4*@horner(u,16.0,-29.0,20.0,-5.0) | ||
end | ||
|
||
function ccdf(d::Triweight, x::Real) | ||
u = (d.location - x)/d.scale | ||
u = (d.μ - x)/d.σ | ||
u <= -1 ? 1.0 : u >= 1 ? 0.0 : 0.03125*(1+u)^4*@horner(u,16.0,-29.0,20.0,-5.0) | ||
end | ||
|
||
@quantile_newton Triweight | ||
|
||
|
||
function mgf(d::Triweight, t::Real) | ||
a = d.scale*t | ||
function mgf(d::Triweight, t::Float64) | ||
a = d.σ*t | ||
a2 = a*a | ||
a == 0 ? one(a) : 105.0*exp(d.location*t)*((15.0/a2+1.0)*cosh(a)-(15.0/a2-6.0)/a*sinh(a))/(a2*a2) | ||
a == 0 ? one(a) : 105.0*exp(d.μ*t)*((15.0/a2+1.0)*cosh(a)-(15.0/a2-6.0)/a*sinh(a))/(a2*a2) | ||
end | ||
|
||
function cf(d::Triweight, t::Real) | ||
a = d.scale*t | ||
function cf(d::Triweight, t::Float64) | ||
a = d.σ*t | ||
a2 = a*a | ||
a == 0 ? complex(one(a)) : 105.0*cis(d.location*t)*((1.0-15.0/a2)*cos(a)+(15.0/a2-6.0)/a*sin(a))/(a2*a2) | ||
a == 0 ? complex(one(a)) : 105.0*cis(d.μ*t)*((1.0-15.0/a2)*cos(a)+(15.0/a2-6.0)/a*sin(a))/(a2*a2) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters