Calculate how much a set of boxes is homogenously 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).
768{
769 int d, i, k, range;
771 double smin, smax;
772 double swidth;
773#if POSTGIS_DEBUG_LEVEL >= 3
774 double average, sdev, sdev_ratio;
775#endif
776 int bmin, bmax;
778
779
780 for ( d = 0; d < ndims; d++ )
781 {
782
783 memset(counts, 0, sizeof(counts));
784
785 smin = extent->
min[d];
786 smax = extent->
max[d];
787 swidth = smax - smin;
788
789
790
791
792
793
795 {
796 distribution[d] = 0;
797 continue;
798 }
799
800
801 for ( i = 0; i < num_boxes; i++ )
802 {
803 double minoffset, maxoffset;
804
805
806 ndb = nd_boxes[i];
807 if ( ! ndb ) continue;
808
809
810 minoffset = ndb->
min[d] - smin;
811 maxoffset = ndb->
max[d] - smin;
812
813
814 if ( minoffset < 0 || minoffset > swidth ||
815 maxoffset < 0 || maxoffset > swidth )
816 {
817 continue;
818 }
819
820
821 bmin = floor(
NUM_BINS * minoffset / swidth);
822 bmax = floor(
NUM_BINS * maxoffset / swidth);
823
824
827
828 POSTGIS_DEBUGF(4, " dimension %d, feature %d: bin %d to bin %d", d, i, bmin, bmax);
829
830
831 for ( k = bmin; k <= bmax; k++ )
832 {
833 counts[k] += 1;
834 }
835
836 }
837
838
840
841#if POSTGIS_DEBUG_LEVEL >= 3
844 sdev_ratio = sdev/average;
845
846 POSTGIS_DEBUGF(3, " dimension %d: range = %d", d, range);
847 POSTGIS_DEBUGF(3, " dimension %d: average = %.6g", d, average);
848 POSTGIS_DEBUGF(3, " dimension %d: stddev = %.6g", d, sdev);
849 POSTGIS_DEBUGF(3, " dimension %d: stddev_ratio = %.6g", d, sdev_ratio);
850#endif
851
852 distribution[d] = range;
853 }
854
855 return true;
856}
static int range_quintile(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...