Install
openclaw skills install @ruiduobao/geoskill-geographically-weighted-regressionGWR局部回归+带宽选择+局部系数空间图+局部R2 (Fotheringham/Brunsdon/Charlton 范式, bisquare/gaussian核, AICc带宽选择)
openclaw skills install @ruiduobao/geoskill-geographically-weighted-regressionGeographically weighted regression (GWR): at each regression point, a distance-decay kernel (bisquare/gaussian) is used for weighted least squares, producing local coefficients that vary in space; the optimal bandwidth is selected by AICc cross-validation (Hurvich & Tsai 1989); outputs include local coefficient rasters and local R².
w(d,h) = (1 - (d/h)²)² for d<h, 0 otherwisew(d,h) = exp(-0.5·(d/h)²)β_i = (X^T W_i X)^{-1} X^T W_i y (Fotheringham et al. 2002, Chapter 4)AICc = n·log(σ²) + n·log(2π) + n·(n + tr(S))/(n − 2 − tr(S)), where tr(S) = Σ_i x_i^T (X^T W_i X)^{-1} x_i·w_i is the trace of the hat matrix1 − resid²/var(y) at each regression point, clipped to [0,1] (per-point residual normalization, used as a proxy for local goodness of fit)| Source | Purpose |
|---|---|
| Fotheringham, Brunsdon, Charlton, Geographically Weighted Regression, Wiley 2002 | GWR paradigm, kernel functions, AICc, local coefficients, R² |
| Brunsdon, Fotheringham, Charlton, Geographical Analysis 28(4):281-298, 1996, DOI:10.1111/j.1538-4632.1996.tb00936.x | Original GWR paper |
| Hurvich, Tsai, Biometrika 76(2):297-307, 1989, DOI:10.1093/biomet/76.2.297 | AICc formula |
| Páez, Farber, Wheeler, Environment and Planning B 38(6):1075-1098, 2011, DOI:10.1068/b100708j | Systematic comparison of bisquare vs gaussian / fixed vs adaptive bandwidths |
pip install numpy rasterio scipy
python geoskill-geographically-weighted-regression.py --bbox 116.0 39.0 117.0 40.0 --synthetic --output-dir ./out
python geoskill-geographically-weighted-regression.py --bbox 121.0 31.0 122.0 32.0 --synthetic --output-dir ./out2 --quiet
python geoskill-geographically-weighted-regression.py --input housing.csv --output-dir ./out3
CSV columns: must contain x, y, dep; optionally multiple independent variables ind1, ind2, ... (no intercept; the script adds it automatically).
python geoskill-geographically-weighted-regression.py --bbox 116.39 39.90 116.40 39.91 --synthetic --output-dir ./out4 --quiet
| File | Format | Description |
|---|---|---|
local_coefficients.tif | GeoTIFF (k bands) | Band 1 = intercept; bands 2+ = local coefficient per independent variable |
local_r2.tif | GeoTIFF (single band) | Local R² raster (IDW-interpolated from sample points) |
gwr_stats.json | JSON | Optimal bandwidth, AICc, tr(S), R², bandwidth search curve, coefficient means |
output-manifest.json | JSON | Run manifest |
_load_csv uses float(v); a "NaN" string raises ValueError (exit 2); no NoData filtering.x, y, dep, ind...), no network requests.--synthetic mode reads no external data.MIT
地理加权回归(GWR):在每个回归点用距离衰减核(双平方/高斯)做加权最小二乘,得到随空间变化的局部系数;用 AICc 交叉验证(Hurvich & Tsai 1989)选最优带宽;输出局部系数栅格与局部 R²。
w(d,h) = (1 - (d/h)²)² for d<h, 0 otherwisew(d,h) = exp(-0.5·(d/h)²)β_i = (X^T W_i X)^{-1} X^T W_i y(Fotheringham et al. 2002, Chapter 4)AICc = n·log(σ²) + n·log(2π) + n·(n + tr(S))/(n − 2 − tr(S)),其中 tr(S) = Σ_i x_i^T (X^T W_i X)^{-1} x_i·w_i 是帽矩阵迹1 − resid²/var(y) 截到 [0,1](per-point 残差归一化,作为局部拟合优度的代理指标)| 来源 | 用途 |
|---|---|
| Fotheringham, Brunsdon, Charlton, Geographically Weighted Regression, Wiley 2002 | GWR 范式、核函数、AICc、局部系数、R² |
| Brunsdon, Fotheringham, Charlton, Geographical Analysis 28(4):281-298, 1996, DOI:10.1111/j.1538-4632.1996.tb00936.x | GWR 原始论文 |
| Hurvich, Tsai, Biometrika 76(2):297-307, 1989, DOI:10.1093/biomet/76.2.297 | AICc 公式 |
| Páez, Farber, Wheeler, Environment and Planning B 38(6):1075-1098, 2011, DOI:10.1068/b100708j | bisquare vs gaussian / 固定 vs adaptive 带宽系统对比 |
pip install numpy rasterio scipy
python geoskill-geographically-weighted-regression.py --bbox 116.0 39.0 117.0 40.0 --synthetic --output-dir ./out
python geoskill-geographically-weighted-regression.py --bbox 121.0 31.0 122.0 32.0 --synthetic --output-dir ./out2 --quiet
python geoskill-geographically-weighted-regression.py --input housing.csv --output-dir ./out3
CSV 列:必须含 x, y, dep;可选多个 ind1, ind2, ... 自变量(不含截距,脚本自动加)。
python geoskill-geographically-weighted-regression.py --bbox 116.39 39.90 116.40 39.91 --synthetic --output-dir ./out4 --quiet
| 文件 | 格式 | 说明 |
|---|---|---|
local_coefficients.tif | GeoTIFF (k 波段) | 第 1 波段=截距,第 2+ 波段=各自变量局部系数 |
local_r2.tif | GeoTIFF (单波段) | 局部 R² 栅格(IDW 插值自样本点) |
gwr_stats.json | JSON | 最优带宽、AICc、tr(S)、R²、带宽搜索曲线、系数均值 |
output-manifest.json | JSON | 运行清单 |
_load_csv 用 float(v),遇 "NaN" 字符串抛 ValueError(exit 2),未做 NoData 过滤。x, y, dep, ind...),无网络请求。--synthetic 模式不读取任何外部数据。MIT