Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bt not defined in changeWeights! #101

Open
AntonOresten opened this issue Apr 11, 2024 · 1 comment
Open

bt not defined in changeWeights! #101

AntonOresten opened this issue Apr 11, 2024 · 1 comment

Comments

@AntonOresten
Copy link

AntonOresten commented Apr 11, 2024

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
@Affie
Copy link
Member

Affie commented Apr 18, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants