KernelDensityEstimate.jl
KernelDensityEstimate.jl copied to clipboard
`bt` not defined in changeWeights!
Hi! I was trying to change the weights of a BallTreeDensity when I encountered this error.
Here's the relevant source code:
getIndexOf(bd::BallTreeDensity, i::Int) = getIndexOf(bd.bt, i)
function changeWeights!(bd::BallTreeDensity, newWeights::Array{Float64,1})
for i in (bd.bt.num_points+1):bd.bt.num_points*2
bd.bt.weights[i] = newWeights[ getIndexOf(bt, i) ]; # <--- error here
end
for i in bd.bt.num_points:-1:1
calcStats!(bd.bt.data,i)
end
calcStats!(bd.bt.data, root());
return nothing
end
It seems like maybe the getIndexOf(bt, i) call should instead be getIndexOf(bd, i)?
EDIT: I tried fixing it but got this:
BoundsError: attempt to access Tuple{typeof(+)} at index [2]
Stacktrace:
...
[2] getMiniMaxi(bt::BallTree, leftI::Int64, rightI::Int64, d::Int64, addop::Tuple{typeof(+)}, diffop::Tuple{typeof(-)})
@ KernelDensityEstimate [C:\Users\anton\.julia\dev\KernelDensityEstimate.jl\src\BallTree01.jl:261](file:///C:/Users/anton/.julia/dev/KernelDensityEstimate.jl/src/BallTree01.jl:261)
[3] calcStatsBall!(bt::BallTree, root::Int64, addop::Tuple{typeof(+)}, diffop::Tuple{typeof(-)})
@ KernelDensityEstimate [C:\Users\anton\.julia\dev\KernelDensityEstimate.jl\src\BallTree01.jl:306](file:///C:/Users/anton/.julia/dev/KernelDensityEstimate.jl/src/BallTree01.jl:306)
[4] calcStatsDensity!(bd::BallTreeDensity, root::Int64, addop::Tuple{typeof(+)}, diffop::Tuple{typeof(-)})
@ KernelDensityEstimate [C:\Users\anton\.julia\dev\KernelDensityEstimate.jl\src\BallTreeDensity01.jl:143](file:///C:/Users/anton/.julia/dev/KernelDensityEstimate.jl/src/BallTreeDensity01.jl:143)
[5] calcStats!(data::BallTreeDensity, root::Int64, addop::Tuple{typeof(+)}, diffop::Tuple{typeof(-)})
@ KernelDensityEstimate [C:\Users\anton\.julia\dev\KernelDensityEstimate.jl\src\BallTree01.jl:101](file:///C:/Users/anton/.julia/dev/KernelDensityEstimate.jl/src/BallTree01.jl:101)
[6] changeWeights!(bd::BallTreeDensity, newWeights::Vector{Float64})
@ KernelDensityEstimate [C:\Users\anton\.julia\dev\KernelDensityEstimate.jl\src\BallTreeDensity01.jl:305](file:///C:/Users/anton/.julia/dev/KernelDensityEstimate.jl/src/BallTreeDensity01.jl:305)
This might be a separate issue. I'm working with trivariate data. Could that be why? Should there be an addop/diffop for each dimension?
EDIT 2: It looks like this works, maybe?
function changeWeights!(bd::BallTreeDensity, newWeights::Array{Float64,1})
for i in (bd.bt.num_points+1):bd.bt.num_points*2
bd.bt.weights[i] = newWeights[ getIndexOf(bd, i) ];
end
addop = Tuple(fill(+, bd.bt.dims))
diffop = Tuple(fill(-, bd.bt.dims))
for i in bd.bt.num_points:-1:1
calcStats!(bd.bt.data, i, addop, diffop)
end
calcStats!(bd.bt.data, root(), addop, diffop);
return nothing
end
Hi, thanks for opening an issue. It looks like some functions might not be fully upgraded to use addop and doffp yet.
@dehann will be the best person to help you on this one.