Skip to content

Commit

Permalink
Merge branch 'amerberg-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheehan Olver committed Mar 20, 2018
2 parents f8841ae + 3625f8e commit e0db743
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Combinatorics 0.2
Distributions 0.8.10
OrdinaryDiffEq 3.0.0
GSL 0.3.1
Compat 0.60
2 changes: 1 addition & 1 deletion src/RandomMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using GSL
using OrdinaryDiffEq
using DiffEqBase # This line is only needed on v0.5, and comes free from OrdinaryDiffEq on v0.6

import Base: isinf, rand
import Base: isinf, rand, convert
import Distributions: ContinuousUnivariateDistribution,
ContinuousMatrixDistribution,
Beta, Chi,
Expand Down
36 changes: 29 additions & 7 deletions src/densities/Semicircle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ struct Semicircle{T<:Real} <: ContinuousUnivariateDistribution
radius::T
Semicircle{T}::T,r::T) where T = new(μ,r)
end
Semicircle{T<:Real}::T=0.0, r::T=2.0) = r > 0 ? Semicircle{T}(μ, r) :
Semicircle::T=0.0, r::T=2.0) where {T<:Real} = r > 0 ? Semicircle{T}(μ, r) :
throw(ArgumentError("radius r must be positive, got $r"))

Semicircle{T}(d::Semicircle) where T = Semicircle{T}(convert(T, d.mean), convert(T, d.radius))
convert(::Type{Semicircle{T}}, d::Semicircle{T}) where T = d
convert(::Type{Semicircle}, d::Semicircle) = d
convert(::Type{Semicircle{T}}, d::Semicircle) where T = Semicircle{T}(convert(T, d.mean), convert(T, d.radius))

# Distribution function methods
###############################

# cumulative distribution function
function cdf{T<:Real}(d::Semicircle{T}, x::T)
function cdf(d::Semicircle{T}, x::T) where {T<:Real}
a, r = d.mean, d.radius
if insupport(d, x)
return 0.5 + (x-a)/*r^2) * (r^2 - (x-a)^2) + asin((x-a)/r)/π
Expand All @@ -30,7 +35,7 @@ function cdf{T<:Real}(d::Semicircle{T}, x::T)
end

# probability density function
function pdf{T<:Real}(d::Semicircle{T}, x::T)
function pdf(d::Semicircle{T}, x::T) where {T<:Real}
a, r = d.mean, d.radius
if insupport(d, x)
return 2/*r^2) * (r^2 - (x-a)^2)
Expand All @@ -40,7 +45,24 @@ function pdf{T<:Real}(d::Semicircle{T}, x::T)
end

# predicate is x in the support of the distribution?
insupport{T<:Real}(d::Semicircle{T}, x::T)=abs(x)<d.radius
insupport{T<:Real}(d::Semicircle{T}, x::T) = abs(x-d.mean) < d.radius

function cdf(X::Semicircle{T}, x::V) where {T<:Real,V<:Real}
TV = promote_type(T,V)
cdf(convert(Semicircle{TV},X), convert(TV,x))
end

# probability density function
function pdf(X::Semicircle{T}, x::V) where {T<:Real,V<:Real}
TV = promote_type(T,V)
pdf(convert(Semicircle{TV},X), convert(TV,x))
end

# predicate is x in the support of the distribution?
function insupport(X::Semicircle{T}, x::V) where {T<:Real,V<:Real}
TV = promote_type(T,V)
insupport(convert(Semicircle{TV},X), convert(TV,x))
end

#Entropy methods
################
Expand Down Expand Up @@ -73,7 +95,7 @@ std(X::Semicircle)=X.radius/2
var(X::Semicircle)=std(X)^2

# moment of distribution
function moment{T<:Real}(X::Semicircle{T}, order::Integer)
function moment(X::Semicircle{T}, order::Integer) where {T<:Real}
a, r = X.mean, X.radius
if X.mean != 0
return a^n*hypergeom([(1-n)/2, -n/2], 2, (r/a)^2)
Expand All @@ -85,7 +107,7 @@ function moment{T<:Real}(X::Semicircle{T}, order::Integer)
end

# cumulant of distribution
function cumulant{T<:Real}(d::Semicircle{T}, order::Integer)
function cumulant(d::Semicircle{T}, order::Integer) where {T<:Real}
if d.mean != 0
throw(ArgumentError("Non-central Semicircle not supported"))
end
Expand All @@ -100,7 +122,7 @@ function cumulant{T<:Real}(d::Semicircle{T}, order::Integer)
end

# free cumulant of distribution
function freecumulant{T<:Real}(d::Semicircle{T}, order::Int)
function freecumulant(d::Semicircle{T}, order::Int) where {T<:Real}
if order == 0
return one(T)
elseif order == 1
Expand Down
2 changes: 1 addition & 1 deletion src/densities/TracyWidom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Painlevé II equation using the Vern8 numerical integrator
* `t::Real`: The point at which to evaluate the pdf
* `t0::Real = -8.0`: The point at which to start integrating
"""
function pdf{S<:Real}(d::TracyWidom, t::S, t0::S = convert(S, -8.0))
function pdf(d::TracyWidom, t::S, t0::S = convert(S, -8.0)) where {S<:Real}
tt0 && return 0.0
t5 && return 0.0

Expand Down
2 changes: 1 addition & 1 deletion test/densities/TracyWidom.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using RandomMatrices
using Base.Test
using Compat.Test

#Test far outside support
#Tracy-Widom has support on all x>0, but the integration won't pick it up
Expand Down

0 comments on commit e0db743

Please sign in to comment.