Skip to main content

A library for crowdflow prediction!

Project description

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


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

st_dif-0.1.2.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

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

st_dif-0.1.2-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file st_dif-0.1.2.tar.gz.

File metadata

  • Download URL: st_dif-0.1.2.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for st_dif-0.1.2.tar.gz
Algorithm Hash digest
SHA256 32bed49bd920921522508e1fb3e52ac6c121640f8c5622b8d79bff66ff68e0df
MD5 3d71764ae129d987ea126ce247c1b7fc
BLAKE2b-256 2455c4aff5027a4fce1596d9b8bf78d9e46ad151f1d90e76eec726e8fb4bd32f

See more details on using hashes here.

Provenance

The following attestation bundles were made for st_dif-0.1.2.tar.gz:

Publisher: publish.yml on vivian-wong/crowd-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file st_dif-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: st_dif-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for st_dif-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1aa14110e9d8dab1a034245443b0a1b94f8f382a57d2851786aeb64dfbbbc944
MD5 0a1fb738c6a364d998011f0f748b6e39
BLAKE2b-256 aafc2b29f1a989514113e2a094fc5df9720fff6201dddf0c4bcce27946abdd1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for st_dif-0.1.2-py3-none-any.whl:

Publisher: publish.yml on vivian-wong/crowd-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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