Skip to main content

Python implementation of SGWR and Fast SGWR (MPI-enhanced)

Project description

FastSGWR: "Enhancing the Computational Efficiency of the SGWR Model and Introducing Its Software Implementation." This article along the python packages (parallel & sequential), and a Graphic User Interface (GUI) tool named 'SGWR Model' is developed based on this article :SGWR: similarity and geographically weighted regression (https://doi.org/10.1080/13658816.2024.2342319).

Author info

  • Code Author: M. Naser Lessani (GIBD)
  • Realeased Year: 2025
  • Affiliation: Geoinformation and Big Data Research Laboratory (GIBD), Department of Geography, The Pennsylvania State University, University Park, PA, USA

Overview

The SGWR (Similarity and Geographically Weighted Regression) model is a novel local spatial regression model that extends the conventional GWR by incorporating both geographical proximity and attribute similarity into a composite spatial weight matrix. The combination of spatial and attribute-based weights is governed by a parameter alpha, which is optimized based on AICc measure.

This Python package includes:

  • MPI-enabled parallel implementations of the SGWR
  • Serial version of the SGWR model
  • Support for Gaussian and bi-square kernels
  • Also, supports a combination of adaptive bisquare and gaussian

Key Features

  • Parallel Computation with MPI: Achieve substantial runtime reductions using multiple CPU cores.
  • Alpha Optimization: Automatically tune the contribution of similarity and spatial proximity.
  • Kernel Flexibility: Choose between Gaussian (default) and bi-square kernels.
  • Also, users have the ability to either chose standardize or don't standardize their data
  • Evaluation Metrics: Outputs include R², adjusted R², AICc, and other metrics
  • Also, users can run the GWR model in both parallel and serial version of this library

Installation Requirements

Ensure the following dependencies are installed:

Standard Python Libraries:

  • os
  • argparse
  • datetime
  • math
  • copy
  • typing (Optional)
  • itertools (combinations)

MPI and CLI:

  • mpi4py
  • click

Numerical and Data Handling:

  • numpy
  • pandas
  • scipy (stats, linalg, spatial.distance)

Machine Learning and Metrics:

  • scikit-learn (metrics)

Specialized Geospatial Modeling:

  • spglm (family, glm, iwls, utils)

Data Format

Input data must be a CSV file with the following column order:

longitude, latitude, dependent_variable, independent_variable_1, ..., independent_variable_n

Categorical variables must be pre-processed into dummy variables. Example: For a 3-class variable ("urban", "peri-urban", "rural"), create:

  • urban_dummy: 1 if urban, else 0
  • peri_urban_dummy: 1 if peri-urban, else 0
  • Rural becomes the reference class (excluded)

Usage

After preparing your dataset and ensuring all dependencies are installed, the model can be run via the command line:

MPI Commands (parallel):

  • fastsgwr run -np x -data path_to_data (by default the kernel is Gaussian function, and doesn't standardize the data)
  • fastsgwr run -np x -data path_to_data -standardize (using Gaussian function and standardize the input data)
  • fastsgwr run -np x -data path_to_data -bisquare
  • fastsgwr run -np x -data path_to_data -bisquare -standardize
  • fastsgwr run -np x -data path_to_data -biga (adaptive bisquare and gaussian)
  • fastsgwr run -np x -data path__to_data -gwr (run gwr as well in parallel)
  • x: Number of cores
  • path_to_data: Path to the CSV dataset

The output will be a CSV file saved in the same input directory, and containing local coefficients and performance metrics. PI Commands (parallel):

Serial commands:

  • selector = ALPHA(g_coords, g_y, g_x, data, fixed=True, kernel='gaussian') ## for fixed bandwidth and gaussian kernel
  • bw, alpha = selector.fit()
  • sgwr_model = SGWR(g_coords, g_y, g_x, bw, data, alpha, fixed=True, kernel='gaussian') ## after bandwidth and alpha optimizationi
  • result = sgwr_model.fit()
  • selector = ALPHA(g_coords, g_y, g_x, data) ## for adaptive bandwidth and bisquare kernel
  • bw, alpha = selector.fit()
  • sgwr_model = SGWR(g_coords, g_y, g_x, bw, data, alpha)
  • result = sgwr_model.fit()

Parameter extraction when running in serial mode:

  • result.R2
  • result.adj_R2
  • result.aicc
  • result.aic
  • result.params
  • result.bse
  • result.localR2
  • result.filter_tvals()
  • result.filter_tvals(alpha=0.05) ### t values with 95% confidence interval
  • result.summary()

Citation

If you use this package in your work, please cite the following articles:

  1. Lessani, M. Naser, and Zhenlong Li. "SGWR: similarity and geographically weighted regression." International Journal of Geographical Information Science 38, no. 7 (2024): 1232-1255.
  2. Lessani, M. Naser, and Zhenlong Li. "Enhancing the Computational Efficiency of the SGWR Model and Introducing Its Software Implementation." Annals of GIS (2025).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sgwr-0.3.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sgwr-0.3-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

Details for the file sgwr-0.3.tar.gz.

File metadata

  • Download URL: sgwr-0.3.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for sgwr-0.3.tar.gz
Algorithm Hash digest
SHA256 2dec6fbb132e04be08ccd35c8463d9f2ba1913dfbe33e13a821a7acdcdaa7904
MD5 40bc01b9141892be22627ec4b07b3e83
BLAKE2b-256 dd415cdde71a17f256b279759777308c9e55c61b39c80bfc310e7f15a7a62b7c

See more details on using hashes here.

File details

Details for the file sgwr-0.3-py3-none-any.whl.

File metadata

  • Download URL: sgwr-0.3-py3-none-any.whl
  • Upload date:
  • Size: 25.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for sgwr-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 93571bc765ad8175c0eb8502fd7bcd67deea57e2cd1a1ef0dfc23aab96014edd
MD5 f5ab786b0754509053c5fc7164d790af
BLAKE2b-256 db2d1bc2036b9b175b46478c65a70b1e0cdc9d922a3d70fc151112a9774b072f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page