SGWR Code Implementation
Run the SGWR model sequentially or with MPI-parallel processing, configure its kernel, and extract the primary model diagnostics.
pip install sgwrSequential implementation
For the default adaptive bisquare kernel, initialize the joint bandwidth-and-alpha search and then pass the optimized parameters to the SGWR model:
selector = ALPHA((u, v), y, X, data)
BW, Alpha = selector.fit()
model = SGWR(
(u, v),
y,
X,
BW,
data,
Alpha
).fit()The first step initializes the parameter-search procedure. The selector.fit() method jointly identifies the optimized bandwidth (BW) and alpha (Alpha). These optimized values are then passed to the SGWR model for final estimation.
Fixed Gaussian kernel
For a fixed Gaussian kernel, use the same implementation and specify the additional kernel arguments in both the search and estimation stages:
selector = ALPHA(
(u, v),
y,
X,
data,
fixed=True,
kernel="gaussian"
)
BW, Alpha = selector.fit()
model = SGWR(
(u, v),
y,
X,
BW,
data,
Alpha,
fixed=True,
kernel="gaussian"
).fit()Model diagnostics
After fitting the model, common goodness-of-fit and model-comparison statistics can be obtained directly from the fitted model object:
R2 = model.R2
Adj_R2 = model.adj_R2
AIC = model.aic
AICc = model.aicc
RSS = np.sum(model.resid_response ** 2)These outputs provide the primary statistics needed to evaluate SGWR model fit and compare alternative model specifications.
Parallel MPI implementation
For larger datasets, the package provides an MPI implementation that distributes SGWR computations across multiple processors. Users must first install MPI and mpi4py. The input CSV must follow this column order:
The basic parallel command is:
fastsgwr run -np x -data path_to_dataHere, x is the number of processors or CPU cores and path_to_data is the path to the input dataset. By default, the parallel implementation uses the adaptive bisquare kernel and does not standardize the variables.
Command-line options
Optional flags can be added to select the kernel, standardize variables, run conventional GWR, or access the earlier SGWR implementation:
# Fixed Gaussian kernel
fastsgwr run -np x -data path_to_data -fixed
# Standardize variables
fastsgwr run -np x -data path_to_data -standardize
# Run conventional GWR
fastsgwr run -np x -data path_to_data -gwr
# Fixed Gaussian kernel with standardization
fastsgwr run -np x -data path_to_data -fixed -standardize
# Access the earlier SGWR implementation
fastsgwr run -np x -data path_to_data -bigaThe order of optional suffixes does not affect execution; for example, -fixed -standardize and -standardize -fixed are equivalent. After execution, the software prints key diagnostics, including R², adjusted R², and AICc, and saves the detailed model output as a CSV file in the input-data directory.