Calculate how much a set of boxes is homogeneously distributed or contentrated within one dimension, returning the range_quintile of of the overlap counts per cell in a uniform partition of the extent of the dimension.
A uniform distribution of counts will have a small range and will require few cells in a selectivity histogram. A diverse distribution of counts will have a larger range and require more cells in a selectivity histogram (to distinguish between areas of feature density and areas of feature sparseness. This measurement should help us identify cases like X/Y/Z data where there is lots of variability in density in X/Y (diversely in a multi-kilometer range) and far less in Z (in a few-hundred meter range).
795 #if POSTGIS_DEBUG_LEVEL >= 3
796 double average, sdev, sdev_ratio;
802 counts = palloc0(num_bins *
sizeof(
int));
805 for ( d = 0; d < ndims; d++ )
808 memset(counts, 0, num_bins *
sizeof(
int));
811 smin = extent->
min[d];
812 smax = extent->
max[d];
813 swidth = smax - smin;
827 for ( i = 0; i < num_boxes; i++ )
829 double minoffset, maxoffset;
833 if ( ! ndb )
continue;
836 minoffset = ndb->
min[d] - smin;
837 maxoffset = ndb->
max[d] - smin;
840 if ( minoffset < 0 || minoffset > swidth ||
841 maxoffset < 0 || maxoffset > swidth )
847 bmin = floor(num_bins * minoffset / swidth);
848 bmax = floor(num_bins * maxoffset / swidth);
851 if (bmax >= num_bins)
854 POSTGIS_DEBUGF(4,
" dimension %d, feature %d: bin %d to bin %d", d, i, bmin, bmax);
857 for ( k = bmin; k <= bmax; k++ )
868 #if POSTGIS_DEBUG_LEVEL >= 3
869 average = avg(counts, num_bins);
870 sdev = stddev(counts, num_bins);
871 sdev_ratio = sdev/average;
873 POSTGIS_DEBUGF(3,
" dimension %d: range = %d", d, range);
874 POSTGIS_DEBUGF(3,
" dimension %d: average = %.6g", d, average);
875 POSTGIS_DEBUGF(3,
" dimension %d: stddev = %.6g", d, sdev);
876 POSTGIS_DEBUGF(3,
" dimension %d: stddev_ratio = %.6g", d, sdev_ratio);
879 distribution[d] = range;
static int range_full(int *vals, int nvals)
The difference between the fourth and first quintile values, the "inter-quintile range".
#define MAX_DIMENSION_WIDTH
Maximum width of a dimension that we'll bother trying to compute statistics on.
N-dimensional box type for calculations, to avoid doing explicit axis conversions from GBOX in all ca...