@@ -11,14 +11,19 @@ struct Semicircle{T<:Real} <: ContinuousUnivariateDistribution
11
11
radius:: T
12
12
Semicircle {T} (μ:: T ,r:: T ) where T = new (μ,r)
13
13
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) :
15
15
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))
16
21
17
22
# Distribution function methods
18
23
# ##############################
19
24
20
25
# cumulative distribution function
21
- function cdf {T<:Real} (d:: Semicircle{T} , x:: T )
26
+ function cdf (d:: Semicircle{T} , x:: T ) where {T <: Real }
22
27
a, r = d. mean, d. radius
23
28
if insupport (d, x)
24
29
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)
30
35
end
31
36
32
37
# probability density function
33
- function pdf {T<:Real} (d:: Semicircle{T} , x:: T )
38
+ function pdf (d:: Semicircle{T} , x:: T ) where {T <: Real }
34
39
a, r = d. mean, d. radius
35
40
if insupport (d, x)
36
41
return 2 / (π* r^ 2 ) * √ (r^ 2 - (x- a)^ 2 )
@@ -40,7 +45,24 @@ function pdf{T<:Real}(d::Semicircle{T}, x::T)
40
45
end
41
46
42
47
# 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
44
66
45
67
# Entropy methods
46
68
# ###############
@@ -73,7 +95,7 @@ std(X::Semicircle)=X.radius/2
73
95
var (X:: Semicircle )= std (X)^ 2
74
96
75
97
# moment of distribution
76
- function moment {T<:Real} (X:: Semicircle{T} , order:: Integer )
98
+ function moment (X:: Semicircle{T} , order:: Integer ) where {T <: Real }
77
99
a, r = X. mean, X. radius
78
100
if X. mean != 0
79
101
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)
85
107
end
86
108
87
109
# cumulant of distribution
88
- function cumulant {T<:Real} (d:: Semicircle{T} , order:: Integer )
110
+ function cumulant (d:: Semicircle{T} , order:: Integer ) where {T <: Real }
89
111
if d. mean != 0
90
112
throw (ArgumentError (" Non-central Semicircle not supported" ))
91
113
end
@@ -100,7 +122,7 @@ function cumulant{T<:Real}(d::Semicircle{T}, order::Integer)
100
122
end
101
123
102
124
# 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 }
104
126
if order == 0
105
127
return one (T)
106
128
elseif order == 1
0 commit comments