2.3 Kernel Weights

Kernel Weights applies kernel function to determine the distance decay in the derived continuous weights kernel. The kernel weights are defined as a function K(z) of the ratio between the distance dij from i to j, and the bandwidth hi, with z=dij/hi. The kernel functions include {triangular , uniform, quadratic , epanechnikov, quartic, gaussian}.

  • Uniform, K(z)=1/2 for |z|<1,

  • Triangular, K(z)=(1βˆ’|z|) for |z|<1,

  • Quadratic or Epanechnikov, K(z)=(3/4)(1βˆ’z^2) for |z|<1,

  • Quartic, K(z)=(15/16)(1βˆ’z^2)^2 for |z|<1|z|<1, and

  • Gaussian. K(z) = (2Ο€)^{1/2}exp(-z^2/2)

For more information, please read: https://geodacenter.github.io/workbook/4c_distance_functions/lab4c.html#kernel-weights

CONTENTS

  1. kernel_weights()

  2. kernel_knn_weights() -- fixed and adaptive bandwidth

There are two types of fixed bandwidths for kernel weights. One is the max-min distance used earlier (the largest of the nearest-neighbor distances): kernel_weights(). The other is the maximum distance for a given specification of k-nearest neighbors: kernel_knn_weights().

1. kernel_weights()

Synopsis

Short version

bytea kernel_weights(integer gid, geometry the_geom, 
    float dist_band, character varying kernel)

Full version

bytea kernel_weights(integer gid, geometry the_geom, 
    float dist_band, character varying kernel,
    float power, 
    boolean is_inverse,
    boolean is_arc,
    boolean is_mile,
    boolean use_kernel_diagonals)

Arguments

Input Arguments

Type

Description

gid

integer

the feature id of geometry: e.g. gid, fid, ogcfid, cartodb_id

the_geom

geometry

the geometry (only points and polygons are supported)

dist_band

float

the distance band/threshold that makes sure each observation has at least one neighbor

kernel

character varying

a varchar value of kernel method, which has to be one of {'triangular', 'uniform', 'epanechnikov', 'quartic', 'gaussian'}

use_kernel_diagonals

boolean

if apply kernel on the diagonal of weights matrix. Default: FALSE.

power

float

the power/exponent corresponds to the number of times the base (dist_band) is used as a factor. Default: 1.

is_inverse

boolean

if apply inverse on distance value. Default: False.

is_arc

boolean

if compute arc distance between two observations. Default: FALSE.

is_mile

boolean

if convert distance unit from mile to kilometer(KM). Default: TRUE.

Return

Value

Description

bytea

the weights structure for each observation in binary format, which is defined in table 2.1.

Examples

SELECT kernel_weights(gid, the_geom, 1.46578, 'gaussian') FROM natregimes;

               kernel_weights 
---------------------------------------------------------
 \x770700001400600800001608000014080000130800005f08000017080000c3070000c5070000c70700007107000074070000750700001e0700002a0700002107000020070000b9060000be060000c407000062060000f134883ede5a823eeee69f3efbfdaa3e54bf843e8752983ecc68c33e75f4943eed5dae3e8ae29b3e89f0be3e5c2bb63efc8cc33e034d953e90c
db63e4345ae3e23649a3ec0c2a23e20afb63eb05e853e
 \x7a0000000e007b0000006d000000cc000000b300000098000000970000008d000000b20000005c0000004e00000025000000670000006800000039000000bda9833e9348853e6812873ee17db43ec9d7c33e8588aa3ee16e993e9f12993e33dda43e6057be3e65c37e3e2756923e7b05b33e91aa923e
 \xeb0000001200260100003f01000066010000ce000000490100002501000024010000010100000401000002010000ea000000c9000000cb00000096000000b0000000af00000095000000940000001a20a93ea651833e82ef853ed196aa3eb26d8a3ebc06a83eeb83953e5f70ae3e865aa23ea939c63ea4cfae3eeda9a83e02abc63e542b8f3e15cca23e68cdb43ed1c
6863e8c9c9c3e
...

2. kernel_knn_weights()

With knn set to a given value, the maximum distance between the selected k-nearest neighbors' pairs is used as a "fixed" bandwidth. However, a drawback of fixed bandwidth kernel weights is that the number of non-zero weights can vary considerably, especially when the density of the point locations is not uniform throughout space. The argument adaptive_bandwidth is provided to allow adaptive bandwidth in knn kernel weights: instead of a fixed distance bandwidth, the distance to the k-th nearest neighbor is used in the kernel function for each observation.

Synopsis

Short version

  • Fixed bandwidth

bytea kernel_knn_weights(integer gid, geometry the_geom, 
    integer k, character varying kernel)
  • Adaptive bandwidth

bytea kernel_knn_weights(integer gid, geometry the_geom, 
    integer k, character varying kernel, boolean adaptive_bandwidth)

Full version

bytea kernel_knn_weights(integer gid, geometry the_geom, 
    integer k, character varying kernel,
    boolean adaptive_bandwidth,
    float power, 
    boolean is_inverse,
    boolean is_arc,
    boolean is_mile,
    boolean use_kernel_diagonals)

Arguments

Input Arguments

Type

Description

gid

integer

the feature id of geometry: e.g. gid, fid, ogcfid, cartodb_id

the_geom

geometry

the geometry (only points and polygons are supported)

k

integer

the k nearest neighbors

kernel

character varying

a varchar value of kernel method, which has to be one of {'triangular', 'uniform', 'epanechnikov', 'quartic', 'gaussian'}

adaptive_bandwidth

boolean

if use adaptive bandwidth (distance to k-th nearest neighbor for each observation), or use max knn distance of all observations. Default: FALSE.

use_kernel_diagonals

boolean

if apply kernel on the diagonal of weights matrix. Default: FALSE.

power

float

the power/exponent corresponds to the number of times the base (dist_band) is used as a factor. Default: 1.

is_inverse

boolean

if apply inverse on distance value. Default: False.

is_arc

boolean

if compute arc distance between two observations. Default: FALSE.

is_mile

boolean

if convert distance unit from mile to kilometer(KM). Default: TRUE.

Return

Value

Description

bytea

the weights structure for each observation in binary format, which is defined in table 2.1.

Examples

SELECT kernel_knn_weights(gid, the_geom, 5, 'gaussian') FROM natregimes;

               kernel_weights 
---------------------------------------------------------
 \x770700001400600800001608000014080000130800005f08000017080000c3070000c5070000c70700007107000074070000750700001e0700002a0700002107000020070000b9060000be060000c407000062060000f134883ede5a823eeee69f3efbfdaa3e54bf843e8752983ecc68c33e75f4943eed5dae3e8ae29b3e89f0be3e5c2bb63efc8cc33e034d953e90c
db63e4345ae3e23649a3ec0c2a23e20afb63eb05e853e
 \x7a0000000e007b0000006d000000cc000000b300000098000000970000008d000000b20000005c0000004e00000025000000670000006800000039000000bda9833e9348853e6812873ee17db43ec9d7c33e8588aa3ee16e993e9f12993e33dda43e6057be3e65c37e3e2756923e7b05b33e91aa923e
 \xeb0000001200260100003f01000066010000ce000000490100002501000024010000010100000401000002010000ea000000c9000000cb00000096000000b0000000af00000095000000940000001a20a93ea651833e82ef853ed196aa3eb26d8a3ebc06a83eeb83953e5f70ae3e865aa23ea939c63ea4cfae3eeda9a83e02abc63e542b8f3e15cca23e68cdb43ed1c
6863e8c9c9c3e
...

Last updated

Was this helpful?