graphical-sampling 0.1.0__tar.gz → 0.1.1__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.
- {graphical_sampling-0.1.0 → graphical_sampling-0.1.1}/.gitignore +6 -2
- graphical_sampling-0.1.1/PKG-INFO +255 -0
- graphical_sampling-0.1.1/README.md +228 -0
- graphical_sampling-0.1.1/graphical_sampling/__init__.py +25 -0
- graphical_sampling-0.1.1/graphical_sampling/clustering/__init__.py +4 -0
- graphical_sampling-0.1.1/graphical_sampling/clustering/fip_balanced_nmeans.py +1403 -0
- graphical_sampling-0.1.1/graphical_sampling/criteria/__init__.py +28 -0
- graphical_sampling-0.1.1/graphical_sampling/criteria/criteria.py +42 -0
- graphical_sampling-0.1.1/graphical_sampling/criteria/multi_objective.py +214 -0
- graphical_sampling-0.1.1/graphical_sampling/design.py +566 -0
- graphical_sampling-0.1.1/graphical_sampling/index/__init__.py +15 -0
- graphical_sampling-0.1.1/graphical_sampling/index/density_disparity.py +175 -0
- graphical_sampling-0.1.1/graphical_sampling/index/local_balance.py +121 -0
- graphical_sampling-0.1.1/graphical_sampling/index/moran.py +186 -0
- graphical_sampling-0.1.1/graphical_sampling/index/store/density.py +111 -0
- graphical_sampling-0.1.1/graphical_sampling/index/store/local_balance_r.py +57 -0
- graphical_sampling-0.1.1/graphical_sampling/index/store/moran_r.py +72 -0
- graphical_sampling-0.1.1/graphical_sampling/index/store/voronoi_r.py +58 -0
- graphical_sampling-0.1.1/graphical_sampling/index/voronoi.py +85 -0
- graphical_sampling-0.1.1/graphical_sampling/order.py +965 -0
- graphical_sampling-0.1.1/graphical_sampling/population.py +240 -0
- {graphical_sampling-0.1.0 → graphical_sampling-0.1.1}/graphical_sampling/random/generator.py +23 -21
- graphical_sampling-0.1.1/graphical_sampling/sampling/__init__.py +36 -0
- graphical_sampling-0.1.1/graphical_sampling/sampling/border.py +42 -0
- graphical_sampling-0.1.1/graphical_sampling/sampling/builder.py +604 -0
- graphical_sampling-0.1.1/graphical_sampling/sampling/entity.py +420 -0
- graphical_sampling-0.1.1/graphical_sampling/sampling/kmeans_sampler.py +487 -0
- graphical_sampling-0.1.1/graphical_sampling/sampling/kmeans_sampling_old.py +317 -0
- graphical_sampling-0.1.1/graphical_sampling/sampling/order.py +474 -0
- graphical_sampling-0.1.1/graphical_sampling/sampling/organizer.py +449 -0
- {graphical_sampling-0.1.0 → graphical_sampling-0.1.1}/graphical_sampling/sampling/random_sampling.py +5 -2
- graphical_sampling-0.1.1/graphical_sampling/search/__init__.py +5 -0
- graphical_sampling-0.1.1/graphical_sampling/search/gbfs.py +326 -0
- {graphical_sampling-0.1.0 → graphical_sampling-0.1.1}/graphical_sampling/structs.py +37 -43
- {graphical_sampling-0.1.0 → graphical_sampling-0.1.1}/pyproject.toml +25 -1
- graphical_sampling-0.1.1/uv.lock +3934 -0
- graphical_sampling-0.1.0/.vscode/settings.json +0 -7
- graphical_sampling-0.1.0/PKG-INFO +0 -85
- graphical_sampling-0.1.0/README.md +0 -69
- graphical_sampling-0.1.0/clustering.ipynb +0 -157
- graphical_sampling-0.1.0/dubly_balanced_clustering.ipynb +0 -1134
- graphical_sampling-0.1.0/graphical_sampling/__init__.py +0 -14
- graphical_sampling-0.1.0/graphical_sampling/clustering/__init__.py +0 -13
- graphical_sampling-0.1.0/graphical_sampling/clustering/aggregate.py +0 -213
- graphical_sampling-0.1.0/graphical_sampling/clustering/dubly_balanced_clustering.py +0 -209
- graphical_sampling-0.1.0/graphical_sampling/clustering/one_boundary.py +0 -233
- graphical_sampling-0.1.0/graphical_sampling/clustering/soft_balanced_kmeans.py +0 -161
- graphical_sampling-0.1.0/graphical_sampling/criteria/__init__.py +0 -4
- graphical_sampling-0.1.0/graphical_sampling/criteria/criteria.py +0 -15
- graphical_sampling-0.1.0/graphical_sampling/criteria/var_nht.py +0 -26
- graphical_sampling-0.1.0/graphical_sampling/design.py +0 -128
- graphical_sampling-0.1.0/graphical_sampling/measure/__init__.py +0 -4
- graphical_sampling-0.1.0/graphical_sampling/measure/density.py +0 -94
- graphical_sampling-0.1.0/graphical_sampling/red_black_tree.py +0 -475
- graphical_sampling-0.1.0/graphical_sampling/sampling/__init__.py +0 -6
- graphical_sampling-0.1.0/graphical_sampling/sampling/kmeans_spatial_sampling.py +0 -61
- graphical_sampling-0.1.0/graphical_sampling/sampling/population.py +0 -234
- graphical_sampling-0.1.0/graphical_sampling/search/__init__.py +0 -4
- graphical_sampling-0.1.0/graphical_sampling/search/astar.py +0 -119
- graphical_sampling-0.1.0/graphical_sampling/type.py +0 -17
- graphical_sampling-0.1.0/measure.ipynb +0 -1297
- graphical_sampling-0.1.0/simulation.ipynb +0 -1956
- graphical_sampling-0.1.0/simulation_bardia.ipynb +0 -2068
- graphical_sampling-0.1.0/swiss.csv +0 -962
- graphical_sampling-0.1.0/tests/test_clustering.py +0 -34
- graphical_sampling-0.1.0/tests/test_maxheap.py +0 -82
- graphical_sampling-0.1.0/tests/test_population.py +0 -60
- graphical_sampling-0.1.0/tests/test_sample.py +0 -15
- graphical_sampling-0.1.0/uv.lock +0 -2497
- graphical_sampling-0.1.0/zone_problem.ipynb +0 -1322
- {graphical_sampling-0.1.0 → graphical_sampling-0.1.1}/LICENSE +0 -0
- {graphical_sampling-0.1.0 → graphical_sampling-0.1.1}/graphical_sampling/random/__init__.py +0 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: graphical-sampling
|
|
3
|
+
Version: 0.1.1
|
|
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: dill>=0.4.1
|
|
9
|
+
Requires-Dist: geodatasets>=2026.5.1
|
|
10
|
+
Requires-Dist: geopandas>=1.1.3
|
|
11
|
+
Requires-Dist: ipykernel>=6.29.5
|
|
12
|
+
Requires-Dist: joblib>=1.5.0
|
|
13
|
+
Requires-Dist: k-means-constrained>=0.7.5
|
|
14
|
+
Requires-Dist: matplotlib
|
|
15
|
+
Requires-Dist: numba>=0.63.1
|
|
16
|
+
Requires-Dist: numpy
|
|
17
|
+
Requires-Dist: opencv-python>=4.13.0.92
|
|
18
|
+
Requires-Dist: package-sampling>=0.3.0
|
|
19
|
+
Requires-Dist: pandas
|
|
20
|
+
Requires-Dist: pyreadr>=0.5.6
|
|
21
|
+
Requires-Dist: rpy2>=3.6.1
|
|
22
|
+
Requires-Dist: scikit-learn
|
|
23
|
+
Requires-Dist: scipy
|
|
24
|
+
Requires-Dist: seaborn>=0.13.2
|
|
25
|
+
Requires-Dist: tqdm>=4.67.1
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# graphical-sampling
|
|
29
|
+
|
|
30
|
+
`graphical-sampling` is a Python package for finite-population sampling, with a particular focus on graphical sampling designs, unequal inclusion probabilities, and spatially well-spread samples.
|
|
31
|
+
|
|
32
|
+
The package implements the Graphical Finite-Population Sampling (GFS) framework and its spatial extensions, including probability-balanced `n`-means clustering, nested spatial ordering, and intelligent search procedures for improving spatial spread while preserving prescribed first-order inclusion probabilities.
|
|
33
|
+
|
|
34
|
+
The package is designed for researchers and practitioners working in survey sampling, spatial statistics, environmental monitoring, ecological sampling, agricultural surveys, and related fields.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Main Features
|
|
39
|
+
|
|
40
|
+
* Construct fixed-size sampling designs with prescribed first-order inclusion probabilities.
|
|
41
|
+
* Represent sampling designs through the graphical/bar construction of GFS.
|
|
42
|
+
* Draw samples from the resulting design.
|
|
43
|
+
* Compute design properties such as:
|
|
44
|
+
|
|
45
|
+
* first-order inclusion probabilities,
|
|
46
|
+
* second-order inclusion probabilities,
|
|
47
|
+
* entropy and relative entropy,
|
|
48
|
+
* exact Narain--Horvitz--Thompson variance when the response variable is supplied.
|
|
49
|
+
* Build probability-balanced spatial clusters using FIP-balanced `n`-means.
|
|
50
|
+
* Create nested cluster-zone structures for spatial sampling.
|
|
51
|
+
* Evaluate spatial spread using indices such as:
|
|
52
|
+
|
|
53
|
+
* Moran-type spatial balance,
|
|
54
|
+
* Voronoi-based spread,
|
|
55
|
+
* Density Disparity Index,
|
|
56
|
+
* local balance measures.
|
|
57
|
+
* Improve sampling designs using intelligent search procedures such as Greedy Best-First Search.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
Install the package from PyPI:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install graphical-sampling
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
or install the development version from GitHub:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install git+https://github.com/mehdimhb/graphical-sampling.git
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Then import the package in Python:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import graphical_sampling
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Depending on the installation version, the main classes can also be imported directly from their submodules.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Basic Example
|
|
86
|
+
|
|
87
|
+
The following example constructs a finite population with spatial coordinates, unequal inclusion probabilities, and a response variable. It then builds a graphical sampling design and draws samples from it.
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
import numpy as np
|
|
91
|
+
|
|
92
|
+
from graphical_sampling.population import Population
|
|
93
|
+
from graphical_sampling.design import Design
|
|
94
|
+
|
|
95
|
+
# Reproducibility
|
|
96
|
+
rng = np.random.default_rng(123)
|
|
97
|
+
|
|
98
|
+
# Population size and sample size
|
|
99
|
+
N = 200
|
|
100
|
+
n = 20
|
|
101
|
+
|
|
102
|
+
# Spatial coordinates
|
|
103
|
+
coords = rng.random((N, 2))
|
|
104
|
+
|
|
105
|
+
# Unequal size measure, normalized internally to sum to n
|
|
106
|
+
weights = 0.5 + rng.random(N)
|
|
107
|
+
|
|
108
|
+
# Example response variable
|
|
109
|
+
y = coords[:, 0] + coords[:, 1] + rng.normal(scale=0.1, size=N)
|
|
110
|
+
|
|
111
|
+
# Create the finite population
|
|
112
|
+
pop = Population(
|
|
113
|
+
coords=coords,
|
|
114
|
+
inclusions=weights,
|
|
115
|
+
variable=y,
|
|
116
|
+
n=n
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# Build a graphical sampling design
|
|
120
|
+
design = Design(population=pop)
|
|
121
|
+
|
|
122
|
+
# Draw five samples
|
|
123
|
+
samples = design.sample(num_samples=5)
|
|
124
|
+
|
|
125
|
+
print(samples)
|
|
126
|
+
print("Relative entropy:", design.relative_entropy)
|
|
127
|
+
print("NHT variance:", design.nht_variance)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Spatial Sampling with FIP-Balanced `n`-Means
|
|
133
|
+
|
|
134
|
+
The package also provides probability-balanced spatial clustering. This is useful when the aim is to form compact spatial clusters whose total inclusion probabilities are controlled exactly.
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from graphical_sampling.population import Population
|
|
138
|
+
from graphical_sampling.design import Design
|
|
139
|
+
from graphical_sampling.order import Order
|
|
140
|
+
from graphical_sampling.clustering.fip_balanced_nmeans import FIPBalancedNMeans
|
|
141
|
+
|
|
142
|
+
# Fit FIP-balanced n-means clustering
|
|
143
|
+
fbn = FIPBalancedNMeans(
|
|
144
|
+
n=n,
|
|
145
|
+
n_init=20,
|
|
146
|
+
init_clust_method="expanded"
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
fbn.fit(population=pop)
|
|
150
|
+
|
|
151
|
+
# Optionally divide each cluster into internal zones
|
|
152
|
+
fbn.fit_zones(
|
|
153
|
+
num_zones=(2, 2),
|
|
154
|
+
mode="sweep_xy"
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
# Build a spatial order from the cluster-zone structure
|
|
158
|
+
order = Order.from_clusters(
|
|
159
|
+
population=pop,
|
|
160
|
+
clusters=fbn.clusters,
|
|
161
|
+
zone_strategy="snake",
|
|
162
|
+
point_strategy="snake"
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
# Construct the corresponding spatial graphical design
|
|
166
|
+
spatial_design = Design.from_order(pop, order)
|
|
167
|
+
|
|
168
|
+
print("Moran index:", spatial_design.moran)
|
|
169
|
+
print("Voronoi index:", spatial_design.voronoi)
|
|
170
|
+
print("Density disparity:", spatial_design.density_disparity)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Intelligent Spatial Sampling
|
|
176
|
+
|
|
177
|
+
The package includes search tools for improving a sampling design while preserving design validity. These methods modify the graphical order or exchange probability mass in a controlled way, and therefore maintain the prescribed inclusion probabilities.
|
|
178
|
+
|
|
179
|
+
A typical workflow is:
|
|
180
|
+
|
|
181
|
+
1. Create a `Population`.
|
|
182
|
+
2. Build an initial design using GFS or FIP-balanced `n`-means clustering.
|
|
183
|
+
3. Choose a criterion, such as a spatial spread index or a weighted combination of indices.
|
|
184
|
+
4. Run an intelligent search algorithm to improve the design.
|
|
185
|
+
5. Use the optimized design for sampling and design-based inference.
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Citation
|
|
190
|
+
|
|
191
|
+
If you use `graphical-sampling`, please cite the software package. If you use the spatial clustering or intelligent spatial sampling methods, please also cite the corresponding methodological paper.
|
|
192
|
+
|
|
193
|
+
### Software citation
|
|
194
|
+
|
|
195
|
+
```bibtex
|
|
196
|
+
@software{graphical_sampling_2025,
|
|
197
|
+
author = {Panahbehagh, Bardia and Mohebbi, Mehdi and HosseiniNasab, Amir Mohammad and Hosseini Moghadam, Mehdi},
|
|
198
|
+
title = {graphical-sampling: A Python package for graphical finite-population and spatial sampling},
|
|
199
|
+
year = {2025},
|
|
200
|
+
url = {https://github.com/mehdimhb/graphical-sampling},
|
|
201
|
+
note = {Python package}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Methodological papers
|
|
206
|
+
|
|
207
|
+
For the graphical finite-population sampling framework, cite:
|
|
208
|
+
|
|
209
|
+
```bibtex
|
|
210
|
+
@article{panahbehagh2026geometric,
|
|
211
|
+
author = {Panahbehagh, Bardia},
|
|
212
|
+
title = {Graphical Finite-Population Sampling},
|
|
213
|
+
year = {2026},
|
|
214
|
+
note = {Manuscript}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
For the spatial sampling design, cite:
|
|
219
|
+
|
|
220
|
+
```bibtex
|
|
221
|
+
@article{panahbehagh2026intelligent,
|
|
222
|
+
author = {Panahbehagh, Bardia and Mohebbi, Mehdi},
|
|
223
|
+
title = {Intelligent n-Means Spatial Sampling},
|
|
224
|
+
year = {2026},
|
|
225
|
+
note = {Manuscript}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
For the spatial spread measure, cite:
|
|
230
|
+
|
|
231
|
+
```bibtex
|
|
232
|
+
@article{panahbehagh2026spread,
|
|
233
|
+
author = {Panahbehagh, Bardia and Mohebbi, Mehdi and HosseiniNasab, Amir Mohammad},
|
|
234
|
+
title = {Measuring Spatial Spread via n-Means Balanced Clustering},
|
|
235
|
+
year = {2026},
|
|
236
|
+
note = {Manuscript}
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Please replace the manuscript entries with the final journal citation once the papers are published.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Maintainers
|
|
245
|
+
|
|
246
|
+
* Bardia Panahbehagh
|
|
247
|
+
* Mehdi Mohebbi
|
|
248
|
+
* Amir Mohammad HosseiniNasab
|
|
249
|
+
* Mehdi Hosseini Moghadam
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## License
|
|
254
|
+
|
|
255
|
+
License information should be checked in the repository before redistribution.
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# graphical-sampling
|
|
2
|
+
|
|
3
|
+
`graphical-sampling` is a Python package for finite-population sampling, with a particular focus on graphical sampling designs, unequal inclusion probabilities, and spatially well-spread samples.
|
|
4
|
+
|
|
5
|
+
The package implements the Graphical Finite-Population Sampling (GFS) framework and its spatial extensions, including probability-balanced `n`-means clustering, nested spatial ordering, and intelligent search procedures for improving spatial spread while preserving prescribed first-order inclusion probabilities.
|
|
6
|
+
|
|
7
|
+
The package is designed for researchers and practitioners working in survey sampling, spatial statistics, environmental monitoring, ecological sampling, agricultural surveys, and related fields.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Main Features
|
|
12
|
+
|
|
13
|
+
* Construct fixed-size sampling designs with prescribed first-order inclusion probabilities.
|
|
14
|
+
* Represent sampling designs through the graphical/bar construction of GFS.
|
|
15
|
+
* Draw samples from the resulting design.
|
|
16
|
+
* Compute design properties such as:
|
|
17
|
+
|
|
18
|
+
* first-order inclusion probabilities,
|
|
19
|
+
* second-order inclusion probabilities,
|
|
20
|
+
* entropy and relative entropy,
|
|
21
|
+
* exact Narain--Horvitz--Thompson variance when the response variable is supplied.
|
|
22
|
+
* Build probability-balanced spatial clusters using FIP-balanced `n`-means.
|
|
23
|
+
* Create nested cluster-zone structures for spatial sampling.
|
|
24
|
+
* Evaluate spatial spread using indices such as:
|
|
25
|
+
|
|
26
|
+
* Moran-type spatial balance,
|
|
27
|
+
* Voronoi-based spread,
|
|
28
|
+
* Density Disparity Index,
|
|
29
|
+
* local balance measures.
|
|
30
|
+
* Improve sampling designs using intelligent search procedures such as Greedy Best-First Search.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
Install the package from PyPI:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install graphical-sampling
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
or install the development version from GitHub:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install git+https://github.com/mehdimhb/graphical-sampling.git
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Then import the package in Python:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
import graphical_sampling
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Depending on the installation version, the main classes can also be imported directly from their submodules.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Basic Example
|
|
59
|
+
|
|
60
|
+
The following example constructs a finite population with spatial coordinates, unequal inclusion probabilities, and a response variable. It then builds a graphical sampling design and draws samples from it.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import numpy as np
|
|
64
|
+
|
|
65
|
+
from graphical_sampling.population import Population
|
|
66
|
+
from graphical_sampling.design import Design
|
|
67
|
+
|
|
68
|
+
# Reproducibility
|
|
69
|
+
rng = np.random.default_rng(123)
|
|
70
|
+
|
|
71
|
+
# Population size and sample size
|
|
72
|
+
N = 200
|
|
73
|
+
n = 20
|
|
74
|
+
|
|
75
|
+
# Spatial coordinates
|
|
76
|
+
coords = rng.random((N, 2))
|
|
77
|
+
|
|
78
|
+
# Unequal size measure, normalized internally to sum to n
|
|
79
|
+
weights = 0.5 + rng.random(N)
|
|
80
|
+
|
|
81
|
+
# Example response variable
|
|
82
|
+
y = coords[:, 0] + coords[:, 1] + rng.normal(scale=0.1, size=N)
|
|
83
|
+
|
|
84
|
+
# Create the finite population
|
|
85
|
+
pop = Population(
|
|
86
|
+
coords=coords,
|
|
87
|
+
inclusions=weights,
|
|
88
|
+
variable=y,
|
|
89
|
+
n=n
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
# Build a graphical sampling design
|
|
93
|
+
design = Design(population=pop)
|
|
94
|
+
|
|
95
|
+
# Draw five samples
|
|
96
|
+
samples = design.sample(num_samples=5)
|
|
97
|
+
|
|
98
|
+
print(samples)
|
|
99
|
+
print("Relative entropy:", design.relative_entropy)
|
|
100
|
+
print("NHT variance:", design.nht_variance)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Spatial Sampling with FIP-Balanced `n`-Means
|
|
106
|
+
|
|
107
|
+
The package also provides probability-balanced spatial clustering. This is useful when the aim is to form compact spatial clusters whose total inclusion probabilities are controlled exactly.
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from graphical_sampling.population import Population
|
|
111
|
+
from graphical_sampling.design import Design
|
|
112
|
+
from graphical_sampling.order import Order
|
|
113
|
+
from graphical_sampling.clustering.fip_balanced_nmeans import FIPBalancedNMeans
|
|
114
|
+
|
|
115
|
+
# Fit FIP-balanced n-means clustering
|
|
116
|
+
fbn = FIPBalancedNMeans(
|
|
117
|
+
n=n,
|
|
118
|
+
n_init=20,
|
|
119
|
+
init_clust_method="expanded"
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
fbn.fit(population=pop)
|
|
123
|
+
|
|
124
|
+
# Optionally divide each cluster into internal zones
|
|
125
|
+
fbn.fit_zones(
|
|
126
|
+
num_zones=(2, 2),
|
|
127
|
+
mode="sweep_xy"
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
# Build a spatial order from the cluster-zone structure
|
|
131
|
+
order = Order.from_clusters(
|
|
132
|
+
population=pop,
|
|
133
|
+
clusters=fbn.clusters,
|
|
134
|
+
zone_strategy="snake",
|
|
135
|
+
point_strategy="snake"
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
# Construct the corresponding spatial graphical design
|
|
139
|
+
spatial_design = Design.from_order(pop, order)
|
|
140
|
+
|
|
141
|
+
print("Moran index:", spatial_design.moran)
|
|
142
|
+
print("Voronoi index:", spatial_design.voronoi)
|
|
143
|
+
print("Density disparity:", spatial_design.density_disparity)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Intelligent Spatial Sampling
|
|
149
|
+
|
|
150
|
+
The package includes search tools for improving a sampling design while preserving design validity. These methods modify the graphical order or exchange probability mass in a controlled way, and therefore maintain the prescribed inclusion probabilities.
|
|
151
|
+
|
|
152
|
+
A typical workflow is:
|
|
153
|
+
|
|
154
|
+
1. Create a `Population`.
|
|
155
|
+
2. Build an initial design using GFS or FIP-balanced `n`-means clustering.
|
|
156
|
+
3. Choose a criterion, such as a spatial spread index or a weighted combination of indices.
|
|
157
|
+
4. Run an intelligent search algorithm to improve the design.
|
|
158
|
+
5. Use the optimized design for sampling and design-based inference.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Citation
|
|
163
|
+
|
|
164
|
+
If you use `graphical-sampling`, please cite the software package. If you use the spatial clustering or intelligent spatial sampling methods, please also cite the corresponding methodological paper.
|
|
165
|
+
|
|
166
|
+
### Software citation
|
|
167
|
+
|
|
168
|
+
```bibtex
|
|
169
|
+
@software{graphical_sampling_2025,
|
|
170
|
+
author = {Panahbehagh, Bardia and Mohebbi, Mehdi and HosseiniNasab, Amir Mohammad and Hosseini Moghadam, Mehdi},
|
|
171
|
+
title = {graphical-sampling: A Python package for graphical finite-population and spatial sampling},
|
|
172
|
+
year = {2025},
|
|
173
|
+
url = {https://github.com/mehdimhb/graphical-sampling},
|
|
174
|
+
note = {Python package}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Methodological papers
|
|
179
|
+
|
|
180
|
+
For the graphical finite-population sampling framework, cite:
|
|
181
|
+
|
|
182
|
+
```bibtex
|
|
183
|
+
@article{panahbehagh2026geometric,
|
|
184
|
+
author = {Panahbehagh, Bardia},
|
|
185
|
+
title = {Graphical Finite-Population Sampling},
|
|
186
|
+
year = {2026},
|
|
187
|
+
note = {Manuscript}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
For the spatial sampling design, cite:
|
|
192
|
+
|
|
193
|
+
```bibtex
|
|
194
|
+
@article{panahbehagh2026intelligent,
|
|
195
|
+
author = {Panahbehagh, Bardia and Mohebbi, Mehdi},
|
|
196
|
+
title = {Intelligent n-Means Spatial Sampling},
|
|
197
|
+
year = {2026},
|
|
198
|
+
note = {Manuscript}
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
For the spatial spread measure, cite:
|
|
203
|
+
|
|
204
|
+
```bibtex
|
|
205
|
+
@article{panahbehagh2026spread,
|
|
206
|
+
author = {Panahbehagh, Bardia and Mohebbi, Mehdi and HosseiniNasab, Amir Mohammad},
|
|
207
|
+
title = {Measuring Spatial Spread via n-Means Balanced Clustering},
|
|
208
|
+
year = {2026},
|
|
209
|
+
note = {Manuscript}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Please replace the manuscript entries with the final journal citation once the papers are published.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Maintainers
|
|
218
|
+
|
|
219
|
+
* Bardia Panahbehagh
|
|
220
|
+
* Mehdi Mohebbi
|
|
221
|
+
* Amir Mohammad HosseiniNasab
|
|
222
|
+
* Mehdi Hosseini Moghadam
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## License
|
|
227
|
+
|
|
228
|
+
License information should be checked in the repository before redistribution.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from importlib import metadata
|
|
2
|
+
|
|
3
|
+
from . import criteria
|
|
4
|
+
from . import search
|
|
5
|
+
from . import clustering
|
|
6
|
+
from . import random
|
|
7
|
+
from . import index
|
|
8
|
+
from .design import Design
|
|
9
|
+
from .population import Population
|
|
10
|
+
from .order import Order
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
__version__ = metadata.version("graphical_sampling")
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"Population",
|
|
17
|
+
"Design",
|
|
18
|
+
"Order",
|
|
19
|
+
"criteria",
|
|
20
|
+
"search",
|
|
21
|
+
"sampling",
|
|
22
|
+
"clustering",
|
|
23
|
+
"random",
|
|
24
|
+
"index",
|
|
25
|
+
]
|