Registry / analytics / wnet
library0.9.16pypypi✓ verified 83d ago

Tools for calculating the Wasserstein metric between probability distributions using a network flow algorithm. Version 0.9.16, active development with occasional releases.

pip install wnet
INSTALL
IMPORT
SIG · WNET
W
wnet
analyticspythonv0.9.16
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WassersteinNetwork
from wnet import WassersteinNetwork
primary class for computation
L2Cost
from wnet.costs import L2Cost
import L2Cost from wnet
cost functions are in submodule
EMDGauss
from wnet.emd import EMDGauss
Gaussian EMD solver

Quickstart for computing Wasserstein distance between two point sets.

import numpy as np from wnet import WassersteinNetwork from wnet.costs import L2Cost np.random.seed(42) P = np.random.rand(100, 2) Q = np.random.rand(100, 2) cost = L2Cost() net = WassersteinNetwork(P, Q, cost) res = net.solve() print(res.wasserstein_distance)
Debug
Known issues
gotchaCost function must be instantiated before passing to WassersteinNetwork; passing a class instead of an instance leads to cryptic errors.
fix
Always create cost = L2Cost() then use WassersteinNetwork(P, Q, cost).
affects: all
gotchaThe library uses network simplex algorithm which can be slow for large datasets (>10k points). Consider downsampling or using entropic regularized methods if speed is critical.
fix
Downsample input data or use alternative libraries (e.g., POT) for large-scale optimal transport.
affects: all
gotchaWassersteinNetwork modifies inputs in-place? The solver may mutate input arrays; keep original copies if needed.
fix
Pass copies of your data: WassersteinNetwork(P.copy(), Q.copy(), cost).
affects: all
Errors
Common errors & fixes
TypeError: __init__() missing 1 required positional argument: 'cost'
Cost function not provided when creating WassersteinNetwork.
fix
Ensure you pass a cost instance: net = WassersteinNetwork(P, Q, L2Cost())
ModuleNotFoundError: No module named 'wnet.costs'
Older version or incomplete installation. Costs submodule is part of wnet.
fix
Reinstall with pip install --upgrade wnet and import using from wnet.costs import L2Cost
Upgrade
Version history
0.9.16latest on PyPI · released May 20, 2026
Audit
Dependencies
numpyrequiredarray operations
scipyrequiredsparse matrix support
Agent activity
30 hits · last 30 days
node
28
OpenAI (training)
1
Resources
wnet — pip install wnet · libregistry