Skip to content

Commit e0db743

Browse files
author
Sheehan Olver
committed
Merge branch 'amerberg-master'
2 parents f8841ae + 3625f8e commit e0db743

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

REQUIRE

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Combinatorics 0.2
33
Distributions 0.8.10
44
OrdinaryDiffEq 3.0.0
55
GSL 0.3.1
6+
Compat 0.60

src/RandomMatrices.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using GSL
55
using OrdinaryDiffEq
66
using DiffEqBase # This line is only needed on v0.5, and comes free from OrdinaryDiffEq on v0.6
77

8-
import Base: isinf, rand
8+
import Base: isinf, rand, convert
99
import Distributions: ContinuousUnivariateDistribution,
1010
ContinuousMatrixDistribution,
1111
Beta, Chi,

src/densities/Semicircle.jl

+29-7
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ struct Semicircle{T<:Real} <: ContinuousUnivariateDistribution
1111
radius::T
1212
Semicircle{T}::T,r::T) where T = new(μ,r)
1313
end
14-
Semicircle{T<:Real}::T=0.0, r::T=2.0) = r > 0 ? Semicircle{T}(μ, r) :
14+
Semicircle::T=0.0, r::T=2.0) where {T<:Real} = r > 0 ? Semicircle{T}(μ, r) :
1515
throw(ArgumentError("radius r must be positive, got $r"))
16+
17+
Semicircle{T}(d::Semicircle) where T = Semicircle{T}(convert(T, d.mean), convert(T, d.radius))
18+
convert(::Type{Semicircle{T}}, d::Semicircle{T}) where T = d
19+
convert(::Type{Semicircle}, d::Semicircle) = d
20+
convert(::Type{Semicircle{T}}, d::Semicircle) where T = Semicircle{T}(convert(T, d.mean), convert(T, d.radius))
1621

1722
# Distribution function methods
1823
###############################
1924

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

3237
# probability density function
33-
function pdf{T<:Real}(d::Semicircle{T}, x::T)
38+
function pdf(d::Semicircle{T}, x::T) where {T<:Real}
3439
a, r = d.mean, d.radius
3540
if insupport(d, x)
3641
return 2/*r^2) * (r^2 - (x-a)^2)
@@ -40,7 +45,24 @@ function pdf{T<:Real}(d::Semicircle{T}, x::T)
4045
end
4146

4247
# predicate is x in the support of the distribution?
43-
insupport{T<:Real}(d::Semicircle{T}, x::T)=abs(x)<d.radius
48+
insupport{T<:Real}(d::Semicircle{T}, x::T) = abs(x-d.mean) < d.radius
49+
50+
function cdf(X::Semicircle{T}, x::V) where {T<:Real,V<:Real}
51+
TV = promote_type(T,V)
52+
cdf(convert(Semicircle{TV},X), convert(TV,x))
53+
end
54+
55+
# probability density function
56+
function pdf(X::Semicircle{T}, x::V) where {T<:Real,V<:Real}
57+
TV = promote_type(T,V)
58+
pdf(convert(Semicircle{TV},X), convert(TV,x))
59+
end
60+
61+
# predicate is x in the support of the distribution?
62+
function insupport(X::Semicircle{T}, x::V) where {T<:Real,V<:Real}
63+
TV = promote_type(T,V)
64+
insupport(convert(Semicircle{TV},X), convert(TV,x))
65+
end
4466

4567
#Entropy methods
4668
################
@@ -73,7 +95,7 @@ std(X::Semicircle)=X.radius/2
7395
var(X::Semicircle)=std(X)^2
7496

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

87109
# cumulant of distribution
88-
function cumulant{T<:Real}(d::Semicircle{T}, order::Integer)
110+
function cumulant(d::Semicircle{T}, order::Integer) where {T<:Real}
89111
if d.mean != 0
90112
throw(ArgumentError("Non-central Semicircle not supported"))
91113
end
@@ -100,7 +122,7 @@ function cumulant{T<:Real}(d::Semicircle{T}, order::Integer)
100122
end
101123

102124
# free cumulant of distribution
103-
function freecumulant{T<:Real}(d::Semicircle{T}, order::Int)
125+
function freecumulant(d::Semicircle{T}, order::Int) where {T<:Real}
104126
if order == 0
105127
return one(T)
106128
elseif order == 1

src/densities/TracyWidom.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Painlevé II equation using the Vern8 numerical integrator
3434
* `t::Real`: The point at which to evaluate the pdf
3535
* `t0::Real = -8.0`: The point at which to start integrating
3636
"""
37-
function pdf{S<:Real}(d::TracyWidom, t::S, t0::S = convert(S, -8.0))
37+
function pdf(d::TracyWidom, t::S, t0::S = convert(S, -8.0)) where {S<:Real}
3838
tt0 && return 0.0
3939
t5 && return 0.0
4040

test/densities/TracyWidom.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using RandomMatrices
2-
using Base.Test
2+
using Compat.Test
33

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

0 commit comments

Comments
 (0)