@@ -5,20 +5,26 @@ type BivariateKDE{Rx<:Range,Ry<:Range}
5
5
density:: Matrix{Float64}
6
6
end
7
7
8
- function kernel_dist {D<:UnivariateDistribution} (:: Type{D} ,w:: (Real,Real) )
8
+ function kernel_dist {D<:UnivariateDistribution} (:: Type{D} ,w:: (@compat Tuple{ Real,Real} ) )
9
9
kernel_dist (D,w[1 ]), kernel_dist (D,w[2 ])
10
10
end
11
- function kernel_dist {Dx<:UnivariateDistribution,Dy<:UnivariateDistribution} (:: Type{(Dx,Dy )} ,w:: (Real,Real) )
11
+ function kernel_dist {Dx<:UnivariateDistribution,Dy<:UnivariateDistribution} (:: Type{(@compat Tuple{ Dx, Dy} )} ,w:: (@compat Tuple{ Real,Real} ) )
12
12
kernel_dist (Dx,w[1 ]), kernel_dist (Dy,w[2 ])
13
13
end
14
14
15
+ # this function provided for backwards compatibility, though it doesn't have the type restrictions
16
+ # to ensure that the given tuple only contains univariate distributions
17
+ function kernel_dist (d:: (@compat Tuple{DataType, DataType}) ,w:: (@compat Tuple{Real,Real}) )
18
+ kernel_dist (d[1 ],w[1 ]), kernel_dist (d[2 ],w[2 ])
19
+ end
20
+
15
21
# TODO : there are probably better choices.
16
- function default_bandwidth (data:: (RealVector,RealVector) )
22
+ function default_bandwidth (data:: (@compat Tuple{ RealVector,RealVector} ) )
17
23
default_bandwidth (data[1 ]), default_bandwidth (data[2 ])
18
24
end
19
25
20
26
# tabulate data for kde
21
- function tabulate (data:: (RealVector, RealVector) , midpoints:: (Range, Range) )
27
+ function tabulate (data:: (@compat Tuple{ RealVector, RealVector} ) , midpoints:: (@compat Tuple{ Range, Range} ) )
22
28
xdata, ydata = data
23
29
ndata = length (xdata)
24
30
length (ydata) == ndata || error (" data vectors must be of same length" )
@@ -48,7 +54,7 @@ function tabulate(data::(RealVector, RealVector), midpoints::(Range, Range))
48
54
end
49
55
50
56
# convolution with product distribution of two univariates distributions
51
- function conv (k:: BivariateKDE , dist:: (UnivariateDistribution,UnivariateDistribution) )
57
+ function conv (k:: BivariateKDE , dist:: (@compat Tuple{ UnivariateDistribution,UnivariateDistribution} ) )
52
58
# Transform to Fourier basis
53
59
Kx, Ky = size (k. density)
54
60
ft = rfft (k. density)
@@ -73,37 +79,37 @@ function conv(k::BivariateKDE, dist::(UnivariateDistribution,UnivariateDistribut
73
79
BivariateKDE (k. x, k. y, dens)
74
80
end
75
81
76
- typealias BivariateDistribution Union (MultivariateDistribution,(UnivariateDistribution,UnivariateDistribution))
82
+ typealias BivariateDistribution Union (MultivariateDistribution,(@compat Tuple{ UnivariateDistribution,UnivariateDistribution} ))
77
83
78
- function kde (data:: (RealVector, RealVector) , midpoints:: (Range, Range) , dist:: BivariateDistribution )
84
+ function kde (data:: (@compat Tuple{ RealVector, RealVector} ) , midpoints:: (@compat Tuple{ Range, Range} ) , dist:: BivariateDistribution )
79
85
k = tabulate (data,midpoints)
80
86
conv (k,dist)
81
87
end
82
88
83
- function kde (data:: (RealVector, RealVector) , dist:: BivariateDistribution ;
84
- boundary:: (( Real,Real) ,(Real,Real) ) = (kde_boundary (data[1 ],std (dist[1 ])),
89
+ function kde (data:: (@compat Tuple{ RealVector, RealVector} ) , dist:: BivariateDistribution ;
90
+ boundary:: (@compat Tuple{(@compat Tuple{ Real,Real} ) ,(@compat Tuple{ Real,Real})} ) = (kde_boundary (data[1 ],std (dist[1 ])),
85
91
kde_boundary (data[2 ],std (dist[2 ]))),
86
- npoints:: (Int,Int) = (256 ,256 ))
92
+ npoints:: (@compat Tuple{ Int,Int} ) = (256 ,256 ))
87
93
88
94
xmid = kde_range (boundary[1 ],npoints[1 ])
89
95
ymid = kde_range (boundary[2 ],npoints[2 ])
90
96
91
97
kde (data,(xmid,ymid),dist)
92
98
end
93
99
94
- function kde (data:: (RealVector, RealVector) , midpoints:: (Range, Range) ;
100
+ function kde (data:: (@compat Tuple{ RealVector, RealVector} ) , midpoints:: (@compat Tuple{ Range, Range} ) ;
95
101
bandwidth= default_bandwidth (data), kernel= Normal)
96
102
97
103
dist = kernel_dist (kernel,bandwidth)
98
104
kde (data,midpoints,dist)
99
105
end
100
106
101
- function kde (data:: (RealVector, RealVector) ;
107
+ function kde (data:: (@compat Tuple{ RealVector, RealVector} ) ;
102
108
bandwidth= default_bandwidth (data),
103
109
kernel= Normal,
104
- boundary:: (( Real,Real) ,(Real,Real) ) = (kde_boundary (data[1 ],bandwidth[1 ]),
110
+ boundary:: (@compat Tuple{(@compat Tuple{ Real,Real} ) ,(@compat Tuple{ Real,Real})} ) = (kde_boundary (data[1 ],bandwidth[1 ]),
105
111
kde_boundary (data[2 ],bandwidth[2 ])),
106
- npoints:: (Int,Int) = (256 ,256 ))
112
+ npoints:: (@compat Tuple{ Int,Int} ) = (256 ,256 ))
107
113
108
114
dist = kernel_dist (kernel,bandwidth)
109
115
xmid = kde_range (boundary[1 ],npoints[1 ])
0 commit comments