graphical-sampling 0.1.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.
Files changed (41) hide show
  1. graphical_sampling-0.1.0/.gitignore +174 -0
  2. graphical_sampling-0.1.0/.vscode/settings.json +7 -0
  3. graphical_sampling-0.1.0/LICENSE +21 -0
  4. graphical_sampling-0.1.0/PKG-INFO +85 -0
  5. graphical_sampling-0.1.0/README.md +69 -0
  6. graphical_sampling-0.1.0/clustering.ipynb +157 -0
  7. graphical_sampling-0.1.0/dubly_balanced_clustering.ipynb +1134 -0
  8. graphical_sampling-0.1.0/graphical_sampling/__init__.py +14 -0
  9. graphical_sampling-0.1.0/graphical_sampling/clustering/__init__.py +13 -0
  10. graphical_sampling-0.1.0/graphical_sampling/clustering/aggregate.py +213 -0
  11. graphical_sampling-0.1.0/graphical_sampling/clustering/dubly_balanced_clustering.py +209 -0
  12. graphical_sampling-0.1.0/graphical_sampling/clustering/one_boundary.py +233 -0
  13. graphical_sampling-0.1.0/graphical_sampling/clustering/soft_balanced_kmeans.py +161 -0
  14. graphical_sampling-0.1.0/graphical_sampling/criteria/__init__.py +4 -0
  15. graphical_sampling-0.1.0/graphical_sampling/criteria/criteria.py +15 -0
  16. graphical_sampling-0.1.0/graphical_sampling/criteria/var_nht.py +26 -0
  17. graphical_sampling-0.1.0/graphical_sampling/design.py +128 -0
  18. graphical_sampling-0.1.0/graphical_sampling/measure/__init__.py +4 -0
  19. graphical_sampling-0.1.0/graphical_sampling/measure/density.py +94 -0
  20. graphical_sampling-0.1.0/graphical_sampling/random/__init__.py +4 -0
  21. graphical_sampling-0.1.0/graphical_sampling/random/generator.py +251 -0
  22. graphical_sampling-0.1.0/graphical_sampling/red_black_tree.py +475 -0
  23. graphical_sampling-0.1.0/graphical_sampling/sampling/__init__.py +6 -0
  24. graphical_sampling-0.1.0/graphical_sampling/sampling/kmeans_spatial_sampling.py +61 -0
  25. graphical_sampling-0.1.0/graphical_sampling/sampling/population.py +234 -0
  26. graphical_sampling-0.1.0/graphical_sampling/sampling/random_sampling.py +21 -0
  27. graphical_sampling-0.1.0/graphical_sampling/search/__init__.py +4 -0
  28. graphical_sampling-0.1.0/graphical_sampling/search/astar.py +119 -0
  29. graphical_sampling-0.1.0/graphical_sampling/structs.py +94 -0
  30. graphical_sampling-0.1.0/graphical_sampling/type.py +17 -0
  31. graphical_sampling-0.1.0/measure.ipynb +1297 -0
  32. graphical_sampling-0.1.0/pyproject.toml +39 -0
  33. graphical_sampling-0.1.0/simulation.ipynb +1956 -0
  34. graphical_sampling-0.1.0/simulation_bardia.ipynb +2068 -0
  35. graphical_sampling-0.1.0/swiss.csv +962 -0
  36. graphical_sampling-0.1.0/tests/test_clustering.py +34 -0
  37. graphical_sampling-0.1.0/tests/test_maxheap.py +82 -0
  38. graphical_sampling-0.1.0/tests/test_population.py +60 -0
  39. graphical_sampling-0.1.0/tests/test_sample.py +15 -0
  40. graphical_sampling-0.1.0/uv.lock +2497 -0
  41. graphical_sampling-0.1.0/zone_problem.ipynb +1322 -0
@@ -0,0 +1,174 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
+ .pdm.toml
111
+ .pdm-python
112
+ .pdm-build/
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ #.idea/
163
+
164
+ # ruff
165
+ .ruff_cache
166
+
167
+
168
+ .idea
169
+ .envrc
170
+
171
+ temp_*
172
+ *.png
173
+
174
+ .DS_Store
@@ -0,0 +1,7 @@
1
+ {
2
+ "python.testing.pytestArgs": [
3
+ "tests"
4
+ ],
5
+ "python.testing.unittestEnabled": false,
6
+ "python.testing.pytestEnabled": true
7
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mehdi Mohebbi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,85 @@
1
+ Metadata-Version: 2.4
2
+ Name: graphical-sampling
3
+ Version: 0.1.0
4
+ Summary: Python package for Graphical Sampling Method
5
+ Author-email: Bardia Panahbehagh <bardia.panah@gmail.com>, Mehdi Mohebbi <mehdi.mohebbi23@gmail.com>, AmirMohammad HosseiniNasab <awmirhn@gmail.com>, Mehdi Hosseini Moghadam <m.h.moghadam1996@gmail.com>
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: k-means-constrained>=0.7.5
9
+ Requires-Dist: matplotlib
10
+ Requires-Dist: numpy
11
+ Requires-Dist: package-sampling>=0.3.0
12
+ Requires-Dist: pandas
13
+ Requires-Dist: scikit-learn
14
+ Requires-Dist: scipy
15
+ Description-Content-Type: text/markdown
16
+
17
+
18
+ # Graphical Sampling Method - Python Package
19
+
20
+ The Graphical Sampling Method, introduced by Panahbehagh (2025), presents an innovative approach to finite population sampling based on a unique graphical framework. This method allows researchers to visually depict first-order inclusion probabilities (FIP) as bars on a two-dimensional graph. By adjusting the positions of these bars, users can explore a wide range of sampling designs while controlling second-order inclusion probabilities (SIP).
21
+
22
+ This package, `graphical_sampling`, provides tools for implementing the Graphical Sampling Method and is available on PyPI.
23
+
24
+ ---
25
+
26
+ ## Features
27
+ - Create various unequal probability sampling designs with a fixed FIP.
28
+ - Control and explore second-order inclusion probabilities (SIP) through visual manipulation.
29
+ - Incorporate search algorithms, such as A* and Genetic Algorithm, to optimize sampling designs for specific needs (e.g., well-spread or optimal sampling).
30
+
31
+ ## Installation
32
+
33
+ Install the package via pip:
34
+ ```bash
35
+ pip install graphical_sampling
36
+ ```
37
+
38
+ ## How to Use
39
+
40
+ The package includes core classes and methods to facilitate sampling design creation and optimization. Below is a basic example demonstrating the API.
41
+
42
+ ### Example Usage
43
+
44
+ ```python
45
+ import graphical_sampling as gs
46
+ import numpy as np
47
+
48
+ # Set up random generator and sample data
49
+ rng = np.random.default_rng()
50
+ N = 50 # Population size
51
+ x = rng.random(size=N) # Auxiliary variable
52
+ n = 5 # Sample size
53
+
54
+ # Generate initial inclusion probabilities
55
+ inclusion = rng.random(N)
56
+ inclusion *= n / inclusion.sum()
57
+
58
+ # Define initial sampling design and evaluation criteria
59
+ initial_design = gs.Design(inclusion)
60
+ nht = gs.criteria.VarNHT(x, inclusion)
61
+ astar = gs.search.AStar(initial_design, nht, switch_coefficient=1)
62
+
63
+ # Display initial criteria and design
64
+ print("Initial criteria value:", astar.initial_criteria_value)
65
+ astar.initial_design.show()
66
+
67
+ # Run the A* search algorithm to optimize the design
68
+ astar.run(max_iterations=2000, num_new_nodes=10, max_open_set_size=10000, num_changes=1)
69
+
70
+ # Display results after optimization
71
+ print("Best criteria value:", astar.best_criteria_value)
72
+ astar.best_design.show()
73
+ ```
74
+
75
+
76
+ ## Maintainers
77
+
78
+ - Bardia Panahbehagh - [bardia.panah@gmail.com](mailto:bardia.panah@gmail.com)
79
+ - Mehdi Mohebbi - [mehdi.mohebbi23@gmail.com](mailto:mehdi.mohebbi23@gmail.com)
80
+ - AmirMohammad HosseiniNasab - [awmirhn@gmail.com](mailto:awmirhn@gmail.com)
81
+ - Mehdi Hosseini Moghadam - [m.h.moghadam1996@gmail.com](mailto:m.h.moghadam1996@gmail.com)
82
+
83
+ ---
84
+
85
+ For more details, consult the official paper: Panahbehagh, B. (2025). Graphical Sampling Method.
@@ -0,0 +1,69 @@
1
+
2
+ # Graphical Sampling Method - Python Package
3
+
4
+ The Graphical Sampling Method, introduced by Panahbehagh (2025), presents an innovative approach to finite population sampling based on a unique graphical framework. This method allows researchers to visually depict first-order inclusion probabilities (FIP) as bars on a two-dimensional graph. By adjusting the positions of these bars, users can explore a wide range of sampling designs while controlling second-order inclusion probabilities (SIP).
5
+
6
+ This package, `graphical_sampling`, provides tools for implementing the Graphical Sampling Method and is available on PyPI.
7
+
8
+ ---
9
+
10
+ ## Features
11
+ - Create various unequal probability sampling designs with a fixed FIP.
12
+ - Control and explore second-order inclusion probabilities (SIP) through visual manipulation.
13
+ - Incorporate search algorithms, such as A* and Genetic Algorithm, to optimize sampling designs for specific needs (e.g., well-spread or optimal sampling).
14
+
15
+ ## Installation
16
+
17
+ Install the package via pip:
18
+ ```bash
19
+ pip install graphical_sampling
20
+ ```
21
+
22
+ ## How to Use
23
+
24
+ The package includes core classes and methods to facilitate sampling design creation and optimization. Below is a basic example demonstrating the API.
25
+
26
+ ### Example Usage
27
+
28
+ ```python
29
+ import graphical_sampling as gs
30
+ import numpy as np
31
+
32
+ # Set up random generator and sample data
33
+ rng = np.random.default_rng()
34
+ N = 50 # Population size
35
+ x = rng.random(size=N) # Auxiliary variable
36
+ n = 5 # Sample size
37
+
38
+ # Generate initial inclusion probabilities
39
+ inclusion = rng.random(N)
40
+ inclusion *= n / inclusion.sum()
41
+
42
+ # Define initial sampling design and evaluation criteria
43
+ initial_design = gs.Design(inclusion)
44
+ nht = gs.criteria.VarNHT(x, inclusion)
45
+ astar = gs.search.AStar(initial_design, nht, switch_coefficient=1)
46
+
47
+ # Display initial criteria and design
48
+ print("Initial criteria value:", astar.initial_criteria_value)
49
+ astar.initial_design.show()
50
+
51
+ # Run the A* search algorithm to optimize the design
52
+ astar.run(max_iterations=2000, num_new_nodes=10, max_open_set_size=10000, num_changes=1)
53
+
54
+ # Display results after optimization
55
+ print("Best criteria value:", astar.best_criteria_value)
56
+ astar.best_design.show()
57
+ ```
58
+
59
+
60
+ ## Maintainers
61
+
62
+ - Bardia Panahbehagh - [bardia.panah@gmail.com](mailto:bardia.panah@gmail.com)
63
+ - Mehdi Mohebbi - [mehdi.mohebbi23@gmail.com](mailto:mehdi.mohebbi23@gmail.com)
64
+ - AmirMohammad HosseiniNasab - [awmirhn@gmail.com](mailto:awmirhn@gmail.com)
65
+ - Mehdi Hosseini Moghadam - [m.h.moghadam1996@gmail.com](mailto:m.h.moghadam1996@gmail.com)
66
+
67
+ ---
68
+
69
+ For more details, consult the official paper: Panahbehagh, B. (2025). Graphical Sampling Method.