Given a list of particle positions (and optional particle weights), bin sizes, and ranges,
creates a density image where the regions with fewer particles are sampled at larger bin sizes.
This can be used as a drop-in for HIST_ND_WEIGHT, but it divides by the bin area (or ND-volume).
Result = HIST_ND_ADAPTIVE(V, Bin)
V: An NDxN element array of the ND-dimensional positions of the N particles.
Bin: Size of highest-resolution pixels in output image.
MIN: ND-element array of minimum positions in final map. If a scalar, used for all dimensions.
Default is the minimum particle position in each dimension.
MAX: ND-element array of maximum positions in final map. If a scalar, used for all dimensions.
Default is the maximum particle position in each dimension.
WEIGHT: Array of weights for each particle.
LEVELMAX: Maximum number of lower-density levels to use (0=no smoothing). Default: 4.
NTHRESHOLD: Minimum number of particles within a pixel before going to the next level. Default: 3.
Result contains a density map of the points. The map has its highest effective
resolution in the regions with the most points, but degrades to factor-of-2 lower resolutions
when the number of particles per pixel drops below the threshold.
n = 100000
positions = 5*randomn(seed, 2, n)
image = hist_nd(positions, 0.5, min=-20, max=20) * 4
smthimage = hist_nd_adaptive(positions, 0.5, min=-20, max=20)
isurface, image, zrange=[0,3], title='Original'
isurface, smthimage, zrange=[0,3], title='Smooth'
Written by: Jeremy Bailin 20 June 2011