Bandwidth selection¶
This page documents 5 public symbols. Each entry includes its purpose, import path, full API docstring, and the maintained example that exercises it.
BandwidthSelector¶
Abstract base class for bandwidth selection methods.
| Property | Value |
|---|---|
| Type | class |
| Import | from pygwrx.core import BandwidthSelector |
| Signature | BandwidthSelector() |
| Maintained example | examples/core/07_bandwidth_selectors.py |
BandwidthSelector ¶
Bases: ABC
Abstract base class for bandwidth selection methods.
select
abstractmethod
¶
select(
X: ndarray,
y: ndarray,
coords: ndarray,
kernel_func: KernelFunction,
bandwidth_range: BandwidthRange = None,
distance_metric: str = "euclidean",
) -> Bandwidth
Select an optimal fixed-distance or adaptive integer bandwidth.
Source code in src/pygwrx/core/bandwidth.py
CrossValidationSelector¶
Select bandwidth by strict leave-one-out squared prediction error.
| Property | Value |
|---|---|
| Type | class |
| Import | from pygwrx.core import CrossValidationSelector |
| Signature | CrossValidationSelector(n_intervals: 'int' = 20, optimization_method: 'str' = 'golden_section', adaptive: 'bool' = False, verbose: 'bool' = False) -> 'None' |
| Maintained example | examples/core/07_bandwidth_selectors.py |
CrossValidationSelector ¶
CrossValidationSelector(
n_intervals: int = 20,
optimization_method: str = "golden_section",
adaptive: bool = False,
verbose: bool = False,
)
Bases: _BaseSelector
Select bandwidth by strict leave-one-out squared prediction error.
Source code in src/pygwrx/core/bandwidth.py
AICSelector¶
Select bandwidth using Gaussian GWR AIC or AICc.
| Property | Value |
|---|---|
| Type | class |
| Import | from pygwrx.core import AICSelector |
| Signature | AICSelector(n_intervals: 'int' = 20, corrected: 'bool' = True, adaptive: 'bool' = False, optimization_method: 'str' = 'golden_section', verbose: 'bool' = False) -> 'None' |
| Maintained example | examples/core/07_bandwidth_selectors.py |
AICSelector ¶
AICSelector(
n_intervals: int = 20,
corrected: bool = True,
adaptive: bool = False,
optimization_method: str = "golden_section",
verbose: bool = False,
)
Bases: _BaseSelector
Select bandwidth using Gaussian GWR AIC or AICc.
Source code in src/pygwrx/core/bandwidth.py
BICSelector¶
Select bandwidth using Gaussian GWR BIC.
| Property | Value |
|---|---|
| Type | class |
| Import | from pygwrx.core import BICSelector |
| Signature | BICSelector(n_intervals: 'int' = 20, optimization_method: 'str' = 'golden_section', adaptive: 'bool' = False, verbose: 'bool' = False) -> 'None' |
| Maintained example | examples/core/07_bandwidth_selectors.py |
BICSelector ¶
BICSelector(
n_intervals: int = 20,
optimization_method: str = "golden_section",
adaptive: bool = False,
verbose: bool = False,
)
Bases: _BaseSelector
Select bandwidth using Gaussian GWR BIC.
Source code in src/pygwrx/core/bandwidth.py
get_bandwidth_selector¶
Create a bandwidth selector by method name.
| Property | Value |
|---|---|
| Type | function |
| Import | from pygwrx.core import get_bandwidth_selector |
| Signature | get_bandwidth_selector(method: 'str', **kwargs) -> 'BandwidthSelector' |
| Maintained example | examples/core/07_bandwidth_selectors.py |
get_bandwidth_selector ¶
Create a bandwidth selector by method name.
Constructor parameters belong in kwargs. Search-time parameters such as
bandwidth_range and distance_metric must be supplied to select().
Source code in src/pygwrx/core/bandwidth.py
Runnable examples used on this page¶
examples/core/07_bandwidth_selectors.py
# SPDX-FileCopyrightText: 2026 Jinghao Hu
# SPDX-License-Identifier: MIT
"""Select bandwidths with CV, AIC/AICc, and BIC selectors."""
# Allow this script to run directly from any working directory.
import sys
from pathlib import Path
_PROJECT_ROOT = Path(__file__).resolve().parents[2]
_EXAMPLES_ROOT = _PROJECT_ROOT / "examples"
_SRC_ROOT = _PROJECT_ROOT / "src"
for _path in (_SRC_ROOT, _EXAMPLES_ROOT):
if str(_path) not in sys.path:
sys.path.insert(0, str(_path))
import numpy as np
from _common import spatial_regression
from pygwrx.core import (
AICSelector,
BandwidthSelector,
BICSelector,
CrossValidationSelector,
gaussian_kernel,
get_bandwidth_selector,
)
X, y, coords = spatial_regression(n=28, p=2)
Xa, ya, ca = X.to_numpy(), np.asarray(y), coords.to_numpy()
selectors = [
CrossValidationSelector(n_intervals=5, adaptive=True, verbose=False),
AICSelector(n_intervals=5, corrected=False, adaptive=True, verbose=False),
AICSelector(n_intervals=5, corrected=True, adaptive=True, verbose=False),
BICSelector(n_intervals=5, adaptive=True, verbose=False),
]
for selector in selectors:
print(
type(selector).__name__,
selector.select(Xa, ya, ca, gaussian_kernel, bandwidth_range=(10, 18)),
)
print("factory=", type(get_bandwidth_selector("aicc", adaptive=True)).__name__)
print("abstract_base=", BandwidthSelector)