@@ -144,7 +144,7 @@ function bwlcv(xdata::RealVector, kernel::Function)
144144 return Optim. minimizer (Optim. optimize (h-> lcv (xdata,kernel,h,w,n), hlb, hub, iterations= 200 ,abs_tol= h0/ n^ 2 ))
145145end
146146
147- function lcv (xdata:: RealMatrix , kernel:: Array{Function, 1} , h:: RealVector , w:: Vector , n:: Int )
147+ function lcv (xdata:: RealMatrix , kernel:: Vector , h:: RealVector , w:: Vector , n:: Int )
148148# -mean(kerneldensity(xdata,xdata,kernel,h)) + mean(map(kernel, xdata, xdata, h))
149149 if any (h .<= 0.0 )
150150 return Inf
@@ -170,7 +170,7 @@ function lcv(xdata::RealMatrix, kernel::Array{Function, 1}, h::RealVector, w::Ve
170170 end
171171 - ll
172172end
173- function bwlcv (xdata:: RealMatrix , kernel:: Array{Function, 1} )
173+ function bwlcv (xdata:: RealMatrix , kernel:: Vector )
174174 n, p = size (xdata)
175175 w = ones (n)
176176 h0 = zeros (p)
@@ -191,7 +191,12 @@ function bwlcv(xdata::RealMatrix, kernel::Array{Function, 1})
191191 hub[j] = h0[j]
192192 end
193193 end
194- Optim. minimizer (Optim. optimize (h-> lcv (xdata, kernel, h, w, n), h0))
194+ h = Optim. minimizer (Optim. optimize (h-> lcv (xdata, kernel, h, w, n), h0))
195+ if all (hlb .<= h .<= hub)
196+ return h
197+ else
198+ return h0
199+ end
195200end
196201
197202
0 commit comments