The package
AdaptiveHierarchicalRegularBinning.jl,
or AHRB (pronounced as "arb", with a silent "h") for short, is a Julia
package for binning data
point features.
The primary goal of AHRB is to support and facilitate multi-resolution analysis of
particle-particle relations or interactions, especially for near-neighbor location or search at
multiple spatial scales or for far-neighbor filtering. The bins of AHRB are thereby chosen to be
For further details, please see the attached manuscript.
In the base case, given a set of
] add https://github.com/pitsianis/AdaptiveHierarchicalRegularBinning.jl
using AdaptiveHierarchicalRegularBinning, AbstractTrees
n = 100_000
d = 20
X = rand(d, n)
maxL = 6
maxP = 32
tree = ahrb(X, maxL, maxP; QT=UInt128);
# Original points are permuted
@assert X[:, tree.info.perm] == points(tree)
# all leaves have up to p points except the ones at the maxL level
@assert all(size(points(node), 2) <= maxP
for node in PreOrderDFS(tree) if depth(node) < maxL && isleaf(node))
# all leaves are leaves
@assert all(isleaf.(Leaves(tree)))
# relationship of quantized and actual box centers and sides
@assert all(qbox(node) ≈ tree.info.scale * box(node) for node in PreOrderDFS(tree))
# each node represents a contiquous group of points, groups are ordered in preorder DFS
@assert all(minimum(low.(children(node))) == low(node) &&
maximum(high.(children(node))) == high(node)
for node in PreOrderDFS(tree) if !isleaf(node))
masses = rand(n);
getmass(node::SpatialTree) = getcontext(node)[:mass]
getcom(node::SpatialTree) = getcontext(node)[:com]
function populate_tree_ctx!(tree)
foreach(PostOrderDFS(tree)) do node
if isleaf(node)
vm = masses[ tree.info.perm[range(node)] ]
com = points(node) * vm
mass = sum( vm )
else
com = zeros(size(pos,1)); mass = 0.0;
for child in children(node)
com .+= getcom(child) .* getmass(child)
mass += getmass(child)
end
end
com ./= mass
setcontext!(node, (; com = com, mass = mass))
end
end
See examples
bh-animation.mp4
AHRB at JuliaCon 2023
26th July 2023, 15:30–16:00 (US/Eastern)