wnet 0.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ cmake_minimum_required(VERSION 3.15)
2
+
3
+ execute_process(
4
+ COMMAND python -m pylmcf --include
5
+ OUTPUT_VARIABLE PYLMCF_INCLUDE_DIRS
6
+ OUTPUT_STRIP_TRAILING_WHITESPACE
7
+ )
8
+
9
+
10
+ project(wnet LANGUAGES CXX)
11
+ find_package(Python 3.8
12
+ REQUIRED COMPONENTS Interpreter Development.Module
13
+ OPTIONAL_COMPONENTS Development.SABIModule)
14
+ find_package(nanobind REQUIRED CONFIG)
15
+
16
+ set(CMAKE_CXX_STANDARD 20)
17
+
18
+ nanobind_add_module(wnet_cpp
19
+ NB_STATIC NOMINSIZE
20
+ src/wnet/cpp/wnet/wnet.cpp)
21
+
22
+ target_include_directories(wnet_cpp PRIVATE ${PYLMCF_INCLUDE_DIRS})
23
+
24
+ install(TARGETS wnet_cpp LIBRARY DESTINATION wnet)
25
+
26
+ # Uncomment the following line to enable detailed debug prints in the C++ code
27
+ # target_compile_definitions(wnet_cpp PRIVATE DO_TONS_OF_PRINTS)
wnet-0.9.0/LICENCE ADDED
@@ -0,0 +1,7 @@
1
+ This software is Copyright 2025 Michał Startek, and provided under terms of MIT licence, below.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
wnet-0.9.0/PKG-INFO ADDED
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.4
2
+ Name: wnet
3
+ Version: 0.9.0
4
+ Summary: Tools for calculation of Wasserstein metric between distributions based on Network Flow algorithm
5
+ Keywords: Wasserstein,Optimal Transport,Network Flow,Earth Mover's Distance
6
+ Author-Email: =?utf-8?q?Micha=C5=82_Startek?= <michal.startek@mimuw.edu.pl>
7
+ Maintainer-Email: =?utf-8?q?Micha=C5=82_Startek?= <michal.startek@mimuw.edu.pl>
8
+ License-Expression: MIT
9
+ License-File: LICENCE
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
12
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
+ Classifier: Development Status :: 4 - Beta
14
+ Project-URL: Homepage, https://github.com/michalsta/wnet
15
+ Project-URL: Repository, https://github.com/michalsta/wnet.git
16
+ Requires-Dist: pylmcf
17
+ Requires-Dist: numpy
18
+ Provides-Extra: extras
19
+ Requires-Dist: networkx; extra == "extras"
20
+ Requires-Dist: matplotlib; extra == "extras"
21
+ Description-Content-Type: text/markdown
22
+
23
+ # wnet
24
+
25
+ Wasserstein Network (wnet) is a Python/C++ library for working with Wasserstein distances. It uses the Min Cost Flow algorithm as implemented by the [LEMON library](https://lemon.cs.elte.hu/trac/lemon), and exposes this functionality to Python via the [pylmcf module](https://github.com/michalsta/pylmcf), enabling efficient computation and manipulation of Wasserstein distances between multidimensional distributions.
26
+
27
+ ## Features
28
+ - Wasserstein and Truncated Wasserstein distance calculations
29
+ - Calculation of der
30
+ - Python and C++ integration
31
+
32
+ ## Installation
33
+
34
+ You can install the Python package using pip:
35
+
36
+ ```bash
37
+ pip install .
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ Simple usage:
43
+ ```python
44
+ import numpy as np
45
+ from wnet import WassersteinDistance, Distribution
46
+ from wnet.distances import L1Distance
47
+
48
+ positions1 = np.array(
49
+ [[0, 1, 5, 10],
50
+ [0, 0, 0, 3]]
51
+ )
52
+ intensities1 = np.array([10, 5, 5, 5])
53
+
54
+ positions2 = np.array(
55
+ [[1,10],
56
+ [0, 0]])
57
+ intensities2 = np.array([20, 5])
58
+
59
+ S1 = Distribution(positions1, intensities1)
60
+ S2 = Distribution(positions2, intensities2)
61
+
62
+ print(WassersteinDistance(S1, S2, L1Distance()))
63
+ # 45
64
+ ```
65
+
66
+ ## Licence
67
+ MIT Licence
68
+
69
+ ## Related Projects
70
+
71
+ - [pylmcf](https://github.com/cheind/pylmcf) - Python bindings for Min Cost Flow algorithms from LEMON library.
72
+ - [LEMON Graph Library](https://lemon.cs.elte.hu/trac/lemon) - C++ library for efficient graph algorithms.
wnet-0.9.0/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # wnet
2
+
3
+ Wasserstein Network (wnet) is a Python/C++ library for working with Wasserstein distances. It uses the Min Cost Flow algorithm as implemented by the [LEMON library](https://lemon.cs.elte.hu/trac/lemon), and exposes this functionality to Python via the [pylmcf module](https://github.com/michalsta/pylmcf), enabling efficient computation and manipulation of Wasserstein distances between multidimensional distributions.
4
+
5
+ ## Features
6
+ - Wasserstein and Truncated Wasserstein distance calculations
7
+ - Calculation of der
8
+ - Python and C++ integration
9
+
10
+ ## Installation
11
+
12
+ You can install the Python package using pip:
13
+
14
+ ```bash
15
+ pip install .
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ Simple usage:
21
+ ```python
22
+ import numpy as np
23
+ from wnet import WassersteinDistance, Distribution
24
+ from wnet.distances import L1Distance
25
+
26
+ positions1 = np.array(
27
+ [[0, 1, 5, 10],
28
+ [0, 0, 0, 3]]
29
+ )
30
+ intensities1 = np.array([10, 5, 5, 5])
31
+
32
+ positions2 = np.array(
33
+ [[1,10],
34
+ [0, 0]])
35
+ intensities2 = np.array([20, 5])
36
+
37
+ S1 = Distribution(positions1, intensities1)
38
+ S2 = Distribution(positions2, intensities2)
39
+
40
+ print(WassersteinDistance(S1, S2, L1Distance()))
41
+ # 45
42
+ ```
43
+
44
+ ## Licence
45
+ MIT Licence
46
+
47
+ ## Related Projects
48
+
49
+ - [pylmcf](https://github.com/cheind/pylmcf) - Python bindings for Min Cost Flow algorithms from LEMON library.
50
+ - [LEMON Graph Library](https://lemon.cs.elte.hu/trac/lemon) - C++ library for efficient graph algorithms.
wnet-0.9.0/example.py ADDED
@@ -0,0 +1,26 @@
1
+ from wnet import Distribution, WassersteinNetwork
2
+ from wnet.distances import L1Distance, wrap_distance_function
3
+ import numpy as np
4
+
5
+ positions1 = np.array(
6
+ [[0, 1, 5, 10],
7
+ [0, 0, 0, 3]]
8
+ )
9
+ intensities1 = np.array([10, 5, 5, 5])
10
+
11
+ positions2 = np.array(
12
+ [[1,10],
13
+ [0, 0]])
14
+ intensities2 = np.array([20, 5])
15
+
16
+ S1 = Distribution(positions1, intensities1)
17
+ S2 = Distribution(positions2, intensities2)
18
+
19
+ W = WassersteinNetwork(S1, [S2], L1Distance(), 10)
20
+ W.add_simple_trash(15)
21
+ W.build()
22
+ W.solve()
23
+ print("Total cost:", W.total_cost())
24
+ print(W.subgraphs()[0].as_netowkrx())
25
+ print(W.flows_for_target(0))
26
+ W.subgraphs()[0].show()
@@ -0,0 +1,32 @@
1
+ [build-system]
2
+ requires = ["scikit-build-core", "nanobind", "pylmcf"]
3
+ build-backend = "scikit_build_core.build"
4
+
5
+ [project]
6
+ name = "wnet"
7
+ version = "0.9.0"
8
+ description = "Tools for calculation of Wasserstein metric between distributions based on Network Flow algorithm"
9
+ authors = [{ name="Michał Startek", email="michal.startek@mimuw.edu.pl" }]
10
+ maintainers = [{ name="Michał Startek", email="michal.startek@mimuw.edu.pl" }]
11
+ dependencies = ["pylmcf", "numpy"]
12
+ license = "MIT"
13
+ license-files = ["LICENCE"]
14
+ readme = "README.md"
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "Topic :: Scientific/Engineering :: Mathematics",
18
+ "Topic :: Software Development :: Libraries :: Python Modules",
19
+ "Development Status :: 4 - Beta",
20
+
21
+ ]
22
+ keywords = ["Wasserstein", "Optimal Transport", "Network Flow", "Earth Mover's Distance"]
23
+
24
+ [project.urls]
25
+ "Homepage" = "https://github.com/michalsta/wnet"
26
+ "Repository" = "https://github.com/michalsta/wnet.git"
27
+
28
+ [project.optional-dependencies]
29
+ extras = ["networkx", "matplotlib"]
30
+
31
+ [tool.scikit-build]
32
+ sdist.exclude = [".github", ".gitignore", "tests"]
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ pip uninstall -y wnet
4
+ VERBOSE=1 pip install -v -e .
@@ -0,0 +1,8 @@
1
+ #! /usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from .distribution import Distribution_1D, Distribution
5
+ from . import wnet_cpp
6
+ from .wasserstein_network import WassersteinNetwork
7
+ from .wasserstein import WassersteinDistance, TruncatedWassersteinDistance
8
+ from .distribution import Distribution_1D, Distribution
@@ -0,0 +1,21 @@
1
+ import importlib.metadata
2
+ from pathlib import Path
3
+
4
+
5
+ __version__ = importlib.metadata.version("wnet")
6
+
7
+ def module_main():
8
+ import argparse
9
+ parser = argparse.ArgumentParser(description="WNet: A module for calculation of Wasserstein metric between distributions using network flow-based approach.")
10
+ parser.add_argument("--version", "-v",action="version", version=__version__)
11
+ parser.add_argument("--include", "-i", help="Print include path for C++ headers", action="store_true")
12
+
13
+ args = parser.parse_args()
14
+
15
+ if args.include:
16
+ print(Path(__file__).parent / "cpp")
17
+ else:
18
+ parser.print_help()
19
+
20
+ if __name__ == "__main__":
21
+ module_main()