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.
Merge pull request JuliaStats#400 from JuliaStats/dh/paramsym
Enforce consistency of parameter naming
- Loading branch information
Showing
53 changed files
with
635 additions
and
708 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
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
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
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
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,53 +1,58 @@ | ||
immutable Biweight <: ContinuousUnivariateDistribution | ||
location::Float64 | ||
scale::Float64 | ||
function Biweight(l::Real, s::Real) | ||
s > zero(s) || error("scale must be positive") | ||
@compat new(Float64(l), Float64(s)) | ||
end | ||
end | ||
μ::Float64 | ||
σ::Float64 | ||
|
||
Biweight(location::Real) = Biweight(location, 1.0) | ||
Biweight() = Biweight(0.0, 1.0) | ||
Biweight(μ::Real, σ::Real) = (@check_args(Biweight, σ > zero(σ)); new(μ, σ)) | ||
Biweight(μ::Real) = new(μ, 1.0) | ||
Biweight() = new(0.0, 1.0) | ||
end | ||
|
||
@distr_support Biweight d.location-d.scale d.location+d.scale | ||
@distr_support Biweight d.μ - d.σ d.μ + d.σ | ||
|
||
## Parameters | ||
params(d::Biweight) = (d.location, d.scale) | ||
params(d::Biweight) = (d.μ, d.σ) | ||
|
||
## Properties | ||
mean(d::Biweight) = d.location | ||
median(d::Biweight) = d.location | ||
mode(d::Biweight) = d.location | ||
mean(d::Biweight) = d.μ | ||
median(d::Biweight) = d.μ | ||
mode(d::Biweight) = d.μ | ||
|
||
var(d::Biweight) = d.scale*d.scale/7.0 | ||
var(d::Biweight) = d.σ^2 / 7.0 | ||
skewness(d::Biweight) = 0.0 | ||
kurtosis(d::Biweight) = 1/21-3 | ||
kurtosis(d::Biweight) = -2.9523809523809526 # = 1/21-3 | ||
|
||
## Functions | ||
function pdf(d::Biweight, x::Real) | ||
u = abs(x - d.location)/d.scale | ||
u >= 1 ? 0.0 : 0.9375*(1-u*u)^2/d.scale | ||
function pdf(d::Biweight, x::Float64) | ||
u = abs(x - d.μ) / d.σ | ||
u >= 1.0 ? 0.0 : 0.9375 * (1 - u^2)^2 / d.σ | ||
end | ||
|
||
function cdf(d::Biweight, x::Real) | ||
u = (x - d.location)/d.scale | ||
u <= -1 ? 0.0 : u >= 1 ? 1.0 : 0.0625*(1+u)^3*@horner(u,8.0,-9.0,3.0) | ||
function cdf(d::Biweight, x::Float64) | ||
u = (x - d.μ) / d.σ | ||
u <= -1.0 ? 0.0 : | ||
u >= 1.0 ? 1.0 : | ||
0.0625 * (u + 1.0)^3 * @horner(u,8.0,-9.0,3.0) | ||
end | ||
function ccdf(d::Biweight, x::Real) | ||
u = (d.location - x)/d.scale | ||
u <= -1 ? 1.0 : u >= 1 ? 0.0 : 0.0625*(1+u)^3*@horner(u,8.0,-9.0,3.0) | ||
|
||
function ccdf(d::Biweight, x::Float64) | ||
u = (d.μ - x) / d.σ | ||
u <= -1.0 ? 1.0 : | ||
u >= 1.0 ? 0.0 : | ||
0.0625 * (u + 1.0)^3 * @horner(u,8.0,-9.0,3.0) | ||
end | ||
|
||
@quantile_newton Biweight | ||
|
||
function mgf(d::Biweight, t::Real) | ||
a = d.scale*t | ||
a2 = a*a | ||
a == 0 ? one(a) : 15.0*exp(d.location*t)*(-3.0*cosh(a)+(a+3.0/a)*sinh(a))/(a2*a2) | ||
function mgf(d::Biweight, t::Float64) | ||
a = d.σ*t | ||
a2 = a^2 | ||
a == 0 ? 1.0 : | ||
15.0 * exp(d.μ * t) * (-3.0 * cosh(a) + (a + 3.0/a) * sinh(a)) / (a2^2) | ||
end | ||
function cf(d::Biweight, t::Real) | ||
a = d.scale*t | ||
a2 = a*a | ||
a == 0 ? complex(one(a)) : -15.0*cis(d.location*t)*(3.0*cos(a)+(a-3.0/a)*sin(a))/(a2*a2) | ||
|
||
function cf(d::Biweight, t::Float64) | ||
a = d.σ * t | ||
a2 = a^2 | ||
a == 0 ? 1.0+0.0im : | ||
-15.0 * cis(d.μ * t) * (3.0 * cos(a) + (a - 3.0/a) * sin(a)) / (a2^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
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,59 +1,55 @@ | ||
immutable Chisq <: ContinuousUnivariateDistribution | ||
df::Float64 | ||
ν::Float64 | ||
|
||
function Chisq(k::Real) | ||
k > zero(k) || error("The degree of freedom k must be positive") | ||
@compat new(Float64(k)) | ||
end | ||
Chisq(ν::Real) = (@check_args(Chisq, ν > zero(ν)); new(ν)) | ||
end | ||
|
||
@distr_support Chisq 0.0 Inf | ||
|
||
#### Parameters | ||
|
||
dof(d::Chisq) = d.df | ||
params(d::Chisq) = (d.df,) | ||
dof(d::Chisq) = d.ν | ||
params(d::Chisq) = (d.ν,) | ||
|
||
|
||
#### Statistics | ||
|
||
mean(d::Chisq) = dof(d) | ||
mean(d::Chisq) = d.ν | ||
|
||
var(d::Chisq) = 2.0 * dof(d) | ||
var(d::Chisq) = 2.0 * d.ν | ||
|
||
skewness(d::Chisq) = sqrt(8.0 / dof(d)) | ||
skewness(d::Chisq) = sqrt(8.0 / d.ν) | ||
|
||
kurtosis(d::Chisq) = 12.0 / dof(d) | ||
kurtosis(d::Chisq) = 12.0 / d.ν | ||
|
||
mode(d::Chisq) = d.df > 2.0 ? d.df - 2.0 : 0.0 | ||
mode(d::Chisq) = d.ν > 2.0 ? d.ν - 2.0 : 0.0 | ||
|
||
function median(d::Chisq; approx::Bool=false) | ||
if approx | ||
k = dof(d) | ||
return k * (1.0 - 2.0 / (9.0 * k))^3 | ||
return d.ν * (1.0 - 2.0 / (9.0 * d.ν))^3 | ||
else | ||
return quantile(d, 0.5) | ||
end | ||
end | ||
|
||
function entropy(d::Chisq) | ||
hk = 0.5 * dof(d) | ||
hk + logtwo + lgamma(hk) + (1.0 - hk) * digamma(hk) | ||
hν = 0.5 * d.ν | ||
hν + logtwo + lgamma(hν) + (1.0 - hν) * digamma(hν) | ||
end | ||
|
||
|
||
#### Evaluation | ||
|
||
@_delegate_statsfuns Chisq chisq df | ||
@_delegate_statsfuns Chisq chisq ν | ||
|
||
mgf(d::Chisq, t::Real) = (1.0 - 2.0 * t)^(-dof(d) / 2.0) | ||
mgf(d::Chisq, t::Real) = (1.0 - 2.0 * t)^(-d.ν * 0.5) | ||
|
||
cf(d::Chisq, t::Real) = (1.0 - 2.0 * im * t)^(-dof(d) / 2.0) | ||
cf(d::Chisq, t::Real) = (1.0 - 2.0 * im * t)^(-d.ν * 0.5) | ||
|
||
gradlogpdf(d::Chisq, x::Float64) = x >= 0.0 ? (dof(d) / 2.0 - 1) / x - 0.5 : 0.0 | ||
gradlogpdf(d::Chisq, x::Float64) = x > 0.0 ? (d.ν * 0.5 - 1) / x - 0.5 : 0.0 | ||
|
||
|
||
#### Sampling | ||
|
||
_chisq_rand(ν::Float64) = StatsFuns.Rmath.chisqrand(ν) | ||
rand(d::Chisq) = _chisq_rand(d.df) | ||
rand(d::Chisq) = _chisq_rand(d.ν) |
Oops, something went wrong.