Skip to main content

st_dif

A Python library for crowd flow prediction and spatiotemporal modeling. Built on PyTorch, PyTorch Geometric, and PyTorch Geometric Temporal.

This is the Python library developed for Chapter 3 and 4 of the thesis:

V. W. H. Wong, Spatio-temporal Representation Learning: Applications to Manufacturing Planning and Pedestrian Crowd Analysis, Ph.D. Thesis, Department of Civil and Environmental Engineering, Stanford University, Stanford, CA, June 2024.

Installation Guide

Follow these steps carefully to set up your environment.


Option 1: Install from PYPI

1. Create a New Virtual Environment

Using conda:

conda create -n st_dif_env python=3.10
conda activate st_dif_env

Or using venv:

python -m venv st_dif_env
st_dif_env\Scripts\activate   # Windows
source st_dif_env/bin/activate # macOS/Linux

2. Install PyTorch

Install PyTorch matching your hardware (example for CUDA 12.6):

pip install torch torchvision torchaudio

(Refer to the PyTorch Get Started guide if you need specific instructions.)


3. Install PyTorch Geometric Libraries

Because st_dif depends on CUDA-based libraries, it is necessary to install them manually:

pip install torch-scatter torch-sparse torch-geometric -f https://data.pyg.org/whl/torch-2.5.1+cu121.html
pip install torch-geometric-temporal

Important: Make sure you install from the special https://data.pyg.org wheels to ensure CUDA compatibility.


4. Install st_dif

Install the st_dif library:

pip install st_dif

Summary:

  • Follow the installation steps carefully to match CUDA and PyTorch versions.
  • Manually install torch-scatter, torch-sparse, and torch-geometric from the correct source.
  • Then install st_dif.

Example Full Setup Commands

conda create -n st_dif_env python=3.10
conda activate st_dif_env

pip install torch torchvision torchaudio

pip install torch-scatter torch-sparse torch-geometric -f https://data.pyg.org/whl/torch-2.5.1+cu121.html
pip install torch-geometric-temporal

pip install st_dif

At this point, you are ready to use st_dif.


Notes

  • If you encounter [WinError 127] The specified procedure could not be found, it usually indicates that torch-scatter or torch-sparse were installed incorrectly. Reinstall them following the instructions above.
  • Ensure that your PyTorch version matches your CUDA version.
  • If using a CPU-only version of PyTorch, install CPU-compatible versions of the dependencies.

Option 2: Install from Source (developer)

git clone https://github.com/vivian-wong/crowd-framework/
cd crowd-framework
pip install -e .[dev]

Run Installation Test

Assuming pytest has been installed:

python -m pytest

Example Usage

from st_dif.data_utils import get_pyg_temporal_dataset, get_loaders
from st_dif.models.sten import STEN

Check the examples/ directory for simplified demo notebooks.


Reproducing paper experiments

To run all experiments as detailed in the thesis, run

bash reproduce_paper_experiments.sh

and generate plots with the jupyter notebook experiments/plot_results.ipynb


Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss proposed changes.


License

MIT License


Metadata

Release files for st-dif 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for st-dif 0.1.2
File Size Uploaded
st_dif-0.1.2.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for st-dif 0.1.2
File Interpreter ABI Platform
st_dif-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 27.8 kB

Release files / st_dif-0.1.2.tar.gz

Download URL st_dif-0.1.2.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
32bed49bd920921522508e1fb3e52ac6c121640f8c5622b8d79bff66ff68e0df
BLAKE2b-256 checksum
How to use checksums
2455c4aff5027a4fce1596d9b8bf78d9e46ad151f1d90e76eec726e8fb4bd32f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2025.

Transparency log

Release files / st_dif-0.1.2-py3-none-any.whl

Download URL st_dif-0.1.2-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1aa14110e9d8dab1a034245443b0a1b94f8f382a57d2851786aeb64dfbbbc944
BLAKE2b-256 checksum
How to use checksums
aafc2b29f1a989514113e2a094fc5df9720fff6201dddf0c4bcce27946abdd1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 25, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page