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 consistent naming for Epanechnikov & Exponential
- Loading branch information
Showing
2 changed files
with
56 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,63 @@ | ||
immutable Epanechnikov <: ContinuousUnivariateDistribution | ||
location::Float64 | ||
scale::Float64 | ||
function Epanechnikov(l::Real, s::Real) | ||
s > zero(s) || error("scale must be positive") | ||
@compat new(Float64(l), Float64(s)) | ||
μ::Float64 | ||
σ::Float64 | ||
function Epanechnikov(μ::Real, σ::Real) | ||
σ > zero(σ) || | ||
throw(ArgumentError("Epanechnikov: σ must be positive.")) | ||
@compat new(Float64(μ), Float64(σ)) | ||
end | ||
end | ||
|
||
Epanechnikov(location::Real) = Epanechnikov(location, 1.0) | ||
Epanechnikov() = Epanechnikov(0.0, 1.0) | ||
Epanechnikov(μ::Real) = @compat new(Float64(μ), 1.0) | ||
Epanechnikov() = new(0.0, 1.0) | ||
end | ||
|
||
@distr_support Epanechnikov d.location-d.scale d.location+d.scale | ||
@distr_support Epanechnikov d.μ - d.σ d.μ + d.σ | ||
|
||
## Parameters | ||
params(d::Epanechnikov) = (d.location, d.scale) | ||
|
||
location(d::Epanechnikov) = d.μ | ||
scale(d::Epanechnikov) = d.σ | ||
params(d::Epanechnikov) = (d.μ, d.σ) | ||
|
||
## Properties | ||
mean(d::Epanechnikov) = d.location | ||
median(d::Epanechnikov) = d.location | ||
mode(d::Epanechnikov) = d.location | ||
mean(d::Epanechnikov) = d.μ | ||
median(d::Epanechnikov) = d.μ | ||
mode(d::Epanechnikov) = d.μ | ||
|
||
var(d::Epanechnikov) = d.scale*d.scale/5 | ||
var(d::Epanechnikov) = d.σ^2 / 5 | ||
skewness(d::Epanechnikov) = 0.0 | ||
kurtosis(d::Epanechnikov) = 3/35-3 | ||
kurtosis(d::Epanechnikov) = -2.914285714285714 # 3/35-3 | ||
|
||
## Functions | ||
function pdf(d::Epanechnikov, x::Real) | ||
u = abs(x - d.location)/d.scale | ||
u >= 1 ? 0.0 : 0.75*(1-u*u)/d.scale | ||
function pdf(d::Epanechnikov, x::Float64) | ||
u = abs(x - d.μ) / d.σ | ||
u >= 1 ? 0.0 : 0.75 * (1 - u^2) / d.σ | ||
end | ||
function cdf(d::Epanechnikov, x::Real) | ||
u = (x - d.location)/d.scale | ||
u <= -1 ? 0.0 : u >= 1 ? 1.0 : 0.5+u*(0.75-0.25*u*u) | ||
|
||
function cdf(d::Epanechnikov, x::Float64) | ||
u = (x - d.μ) / d.σ | ||
u <= -1 ? 0.0 : | ||
u >= 1 ? 1.0 : | ||
0.5 + u * (0.75 - 0.25 * u^2) | ||
end | ||
function ccdf(d::Epanechnikov, x::Real) | ||
u = (d.location - x)/d.scale | ||
u <= -1 ? 1.0 : u >= 1 ? 0.0 : 0.5+u*(0.75-0.25*u*u) | ||
|
||
function ccdf(d::Epanechnikov, x::Float64) | ||
u = (d.μ - x) / d.σ | ||
u <= -1 ? 1.0 : | ||
u >= 1 ? 0.0 : | ||
0.5 + u * (0.75 - 0.25 * u^2) | ||
end | ||
|
||
@quantile_newton Epanechnikov | ||
|
||
function mgf(d::Epanechnikov, t::Real) | ||
a = d.scale*t | ||
a == 0 ? one(a) : 3.0*exp(d.location*t)*(cosh(a)-sinh(a)/a)/(a*a) | ||
function mgf(d::Epanechnikov, t::Float64) | ||
a = d.σ * t | ||
a == 0 ? 1.0 : | ||
3.0 * exp(d.μ * t) * (cosh(a) - sinh(a) / a) / a^2 | ||
end | ||
|
||
function cf(d::Epanechnikov, t::Real) | ||
a = d.scale*t | ||
a == 0 ? complex(one(a)) : -3.0*exp(im*d.location*t)*(cos(a)-sin(a)/a)/(a*a) | ||
function cf(d::Epanechnikov, t::Float64) | ||
a = d.σ * t | ||
a == 0 ? 1.0+0.0im : | ||
-3.0 * exp(im * d.μ * t) * (cos(a) - sin(a) / a) / a^2 | ||
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