Repository navigation
ENH: Add decay and taper arguments to normalize kernel in distance-based weights - #791
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #791 +/- ##
=====================================
Coverage 85.4% 85.4%
=====================================
Files 150 151 +1
Lines 15954 15993 +39
=====================================
+ Hits 13620 13659 +39
Misses 2334 2334
🚀 New features to boost your workflow:
|
|
Can we get it to |
Kernels in PySALThis note collects issues, background, and proposals for refactoring the treatment of kernels in PySAL, especially in relation to bandwidth handling, standardization, and cross-module reuse. BackgroundConceptual OverviewIn nonparametric statistics, kernels are generally used for smoothing. At a given focal point, a weighted average of surrounding observations is computed, with weights that decrease with distance from the focal point. The kernel function defines the distance decay pattern of these weights. In spatial analysis, kernels serve multiple purposes, which can be classified into three conceptual cases:
Current ImplementationLocation: Notation
Kernel TableA
Derivations: Do Kernels Integrate to 1?Triangular✅ Integrates to 1 Uniform✅ Integrates to 1 Quadratic (Epanechnikov)✅ Integrates to 1 Quartic (Biweight)✅ Integrates to 1 Gaussian✅ Integrates to 1 (by definition of the standard normal distribution) Why Set
|
|
One thing we need to figure out is handling of diagonal filling as a user typically does not know the value of |
|
100% w/ the In this pattern, when a weight is built & kernel calculated, we set the |
|
We've decided against this |
|
No matter what we do, we need to fix this, so that when distances are calculated, we populate the self-weight with |
Co-authored-by: knaaptime <knaaptime@Mac.attlocal.net>
for more information, see https://pre-commit.ci
These have now been propagated to the builders. |
| def build_kernel( | ||
| cls, | ||
| data, | ||
| kernel="gaussian", | ||
| k=None, | ||
| bandwidth=None, | ||
| metric="euclidean", | ||
| p=2, | ||
| coplanar="raise", |
There was a problem hiding this comment.
Should we expose decay and taper also in here? Because this is the public API.
There was a problem hiding this comment.
The same applies to build_distance_band and build_knn build_triangulation and build_travel_cost which` also allow kernels.
But again, happy to keep this for a follow up. However, without these being exposed directly in class methods, they are useful only internally.
There was a problem hiding this comment.
Thanks for the close review and catching these. Let me add these and ensure we have all kernel related changes incorporated before we merge.
|
The errors fetching the EEA Large rivers from Zenodo are strange. It indicates that we try to pull it from remote multiple times but it should not happen as we explicitly fetch the data in the workflow earlier. However, for a reason unknown to me, this one does not show up in the log. In any case, it is not related to this PR. |
|
Merging in main should make the CI green here. |
There was a problem hiding this comment.
This is a very nice notebook.

This is responding to the discussion in #790.
The default
$$K(z) = \frac{1}{\sqrt{2\pi}} e^{-\frac{1}{2} z^2}$$
normalize=Truepreserves the current behavior of the Gaussian kernel weights (heavily used inspreg):Setting
$$K(z) = e^{-\frac{1}{2} z^2}$$
normalize=Falseprovides an option to use unnormalized Gaussian weights: