benchmake 1.1.2__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.
- benchmake-1.1.2/LICENSE +21 -0
- benchmake-1.1.2/PKG-INFO +311 -0
- benchmake-1.1.2/README.md +291 -0
- benchmake-1.1.2/benchmake/BenchMake.py +423 -0
- benchmake-1.1.2/benchmake/__init__.py +1 -0
- benchmake-1.1.2/benchmake.egg-info/PKG-INFO +311 -0
- benchmake-1.1.2/benchmake.egg-info/SOURCES.txt +10 -0
- benchmake-1.1.2/benchmake.egg-info/dependency_links.txt +1 -0
- benchmake-1.1.2/benchmake.egg-info/requires.txt +4 -0
- benchmake-1.1.2/benchmake.egg-info/top_level.txt +1 -0
- benchmake-1.1.2/pyproject.toml +27 -0
- benchmake-1.1.2/setup.cfg +4 -0
benchmake-1.1.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2025] Amanda S Barnard
|
|
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.
|
benchmake-1.1.2/PKG-INFO
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: benchmake
|
|
3
|
+
Version: 1.1.2
|
|
4
|
+
Summary: A lightweight benchmarking toolkit for Python, helping you measure and compare code performance with ease.
|
|
5
|
+
Author: Prof Dr Amanda S Barnard
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: benchmark,performance,tooling
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.6
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: numpy
|
|
16
|
+
Requires-Dist: pandas
|
|
17
|
+
Requires-Dist: joblib
|
|
18
|
+
Requires-Dist: scikit-learn
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
# BenchMake
|
|
23
|
+
## Turn any Scientific Data Set into a Reproducible Benchmark
|
|
24
|
+
|
|
25
|
+
Version: **1.1.2**
|
|
26
|
+
Date: **01/07/2025**
|
|
27
|
+
Author: **Prof. Amanda S. Barnard, PhD DSc**
|
|
28
|
+
|
|
29
|
+
BenchMake is a Python package that partitions a data set into train/test splits using **archetypal analysis**. It relies on an **NMF-based** approach, performing a multiplicative-update factorization and then computing distances to the discovered “archetypes.” The nearest unique data points become the test set (or optionally just the test **indices**). BenchMake supports **GPU acceleration** via **CuPy** (if available), or automatically falls back to CPU-based NumPy.
|
|
30
|
+
|
|
31
|
+
## Table of Contents
|
|
32
|
+
|
|
33
|
+
1. [Features](#features)
|
|
34
|
+
2. [Installation](#installation)
|
|
35
|
+
3. [Quick Start](#quick-start)
|
|
36
|
+
4. [Usage](#usage)
|
|
37
|
+
- [Partitioning Tabular Data](#partitioning-tabular-data)
|
|
38
|
+
- [Partitioning Images](#partitioning-images)
|
|
39
|
+
- [Partitioning Sequential Data](#partitioning-sequential-data)
|
|
40
|
+
- [Partitioning Signal Data](#partitioning-signal-data)
|
|
41
|
+
- [Partitioning Graph Data](#partitioning-graph-data)
|
|
42
|
+
5. [Implementation](#implementation)
|
|
43
|
+
- [Parallelism & GPU Acceleration](#parallelism--gpu-acceleration)
|
|
44
|
+
- [Algorithmic Details](#algorithmic-details)
|
|
45
|
+
- [Known Limitations](#known-limitations)
|
|
46
|
+
6. [Acknowledgements](#acknowledgments)
|
|
47
|
+
- [License](#license)
|
|
48
|
+
- [Citation](#citation)
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Features
|
|
53
|
+
|
|
54
|
+
- **Archetypal Analysis Partitioning**
|
|
55
|
+
Automatically finds “extreme” points (archetypes) that best approximate the entire data set in a low-dimensional sense, and uses them to form a test set.
|
|
56
|
+
|
|
57
|
+
- **Multi-Domain Support**
|
|
58
|
+
BenchMake handles:
|
|
59
|
+
- **Tabular** structured data (NumPy arrays, Pandas DataFrames)
|
|
60
|
+
- **Image** data (multi-dimensional arrays)
|
|
61
|
+
- **Sequential** data (strings, text)
|
|
62
|
+
- **Signal** data (time-series, audio, sensor arrays)
|
|
63
|
+
- **Graph** data (node-feature matrices)
|
|
64
|
+
|
|
65
|
+
- **Deterministic**
|
|
66
|
+
Fixed random seeds and consistent initialization ensure you get the same splits every time for the same data, whatever split size you select, regardless of data order.
|
|
67
|
+
|
|
68
|
+
- **Automatic Batch Size**
|
|
69
|
+
Dynamically chooses a batch size for distance computations based on the data size and number of CPU jobs available.
|
|
70
|
+
|
|
71
|
+
- **Optional Return of Indices**
|
|
72
|
+
Users can obtain either `(X_train, X_test, y_train, y_test)` **or** `(Train_indices, Test_indices)` for maximum flexibility.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Installation
|
|
77
|
+
|
|
78
|
+
BenchMake requires Python 3.7 or higher. To install via pip:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install benchmake
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Optional**: For GPU support, install [CuPy](https://docs.cupy.dev/en/stable/install.html) appropriate to your CUDA version. Install CuPy separately if you require this capability, making sure it is compatible with your CUDA installation too. If CuPy is not found or no compatible GPU exists, BenchMake reverts to CPU silently (with a warning).
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Quick Start
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from benchmake import BenchMake
|
|
92
|
+
import numpy as np
|
|
93
|
+
|
|
94
|
+
# Sample data: 1000 samples, 20 features
|
|
95
|
+
X = np.random.rand(1000, 20)
|
|
96
|
+
y = np.random.randint(0, 5, size=1000)
|
|
97
|
+
|
|
98
|
+
# Instantiate BenchMake with 4 parallel CPU jobs
|
|
99
|
+
bm = BenchMake(n_jobs=4)
|
|
100
|
+
|
|
101
|
+
# Partition the data into train/test using 20% test split
|
|
102
|
+
X_train, X_test, y_train, y_test = bm.partition(
|
|
103
|
+
X,
|
|
104
|
+
y,
|
|
105
|
+
test_size=0.2,
|
|
106
|
+
data_type='tabular',
|
|
107
|
+
return_indices=False
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
print("Train size:", len(X_train), "Test size:", len(X_test))
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Usage
|
|
116
|
+
|
|
117
|
+
### Partitioning Tabular Data
|
|
118
|
+
|
|
119
|
+
When tabular data is provided (as a NumPy array, Pandas DataFrame, or list), BenchMake first converts it to a consistent NumPy array (if it isn’t already) so that all numerical operations are performed in float32. Next, it reorders the data rows deterministically by computing a stable hash (using the MD5 algorithm) for each row. This guarantees that the same data, regardless of the original row order, produces the same sorted order. BenchMake then applies a min–max scaling to the data before partitioning. BenchMake returns either four splits (`X_train, X_test, y_train, y_test`) in the same data type as the user provided (for example, if you used Pandas DataFrames, you get DataFrames back) or, if requested, just the lists of indices for the training and testing sets.
|
|
120
|
+
|
|
121
|
+
Assume you have `(X, y)` in either a NumPy array or a Pandas DataFrame/Series. Just specify `data_type='tabular'`:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
X_train, X_test, y_train, y_test = bm.partition(
|
|
125
|
+
X,
|
|
126
|
+
y,
|
|
127
|
+
test_size=0.2,
|
|
128
|
+
data_type='tabular',
|
|
129
|
+
return_indices=False
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
Train_indices, Test_indices = bm.partition(
|
|
133
|
+
X,
|
|
134
|
+
y,
|
|
135
|
+
test_size=0.2,
|
|
136
|
+
data_type='tabular',
|
|
137
|
+
return_indices=True
|
|
138
|
+
)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Partitioning Images
|
|
142
|
+
|
|
143
|
+
For image data, BenchMake expects input in the form of a multi-dimensional array or DataFrame, where each image is typically structured as (`n_samples`, `height`, `width`, `channels`). It first converts the data to a float32 NumPy array (if it isn’t already) and then flattens each image (`n_samples, height*width*channels`) into a one-dimensional vector so that every image is represented as a row vector. The rows are then reordered deterministically using the stable hashing strategy. The images (now as 1D vectors) are min–max scaled, and the data is partitioned. BenchMake returns either the training and testing subsets in the same format as the original input (e.g., as NumPy arrays or DataFrames) or the corresponding indices if the user has requested that mode.
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
# Suppose X is shape (n_samples, height, width, channels)
|
|
147
|
+
X_train, X_test, y_train, y_test = bm.partition(
|
|
148
|
+
X,
|
|
149
|
+
y,
|
|
150
|
+
test_size=0.2,
|
|
151
|
+
data_type='image',
|
|
152
|
+
return_indices=False
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
Train_indices, Test_indices = bm.partition(
|
|
156
|
+
X,
|
|
157
|
+
y,
|
|
158
|
+
test_size=0.2,
|
|
159
|
+
data_type='image',
|
|
160
|
+
return_indices=True
|
|
161
|
+
)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Partitioning Sequential Data
|
|
165
|
+
|
|
166
|
+
BenchMake handles sequential data such as text strings, SMILES strings, or DNA sequences by first taking the provided list or Pandas Series and converting each sequence into a numerical (vector) representation using a character-level `CountVectorizer`. This transformation results in a two-dimensional NumPy array (float32) where each row corresponds to the numeric representation of a sequence. The rows of this numeric representation are then deterministically reordered via the stable hash. BenchMake then applies min–max scaling and partitions the data. Finally, the original sequences are re-ordered using the same hash order, and BenchMake returns either the full training and testing splits (in the same type as the original input, e.g., list or Series) or the indices of the splits if that is requested.
|
|
167
|
+
|
|
168
|
+
For sequences or text:
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
sequences = ["ACGTG", "GGTTA", "TTACG", ...] # e.g., list of strings
|
|
172
|
+
# sequences can also be SMILEs, e.g., ["CCO", "c1ccccc1", "CC(=O)O", ...]
|
|
173
|
+
y = [label1, label2, ...] # labels
|
|
174
|
+
|
|
175
|
+
X_train, X_test, y_train, y_test = bm.partition(
|
|
176
|
+
sequences,
|
|
177
|
+
y,
|
|
178
|
+
test_size=0.2,
|
|
179
|
+
data_type='sequential',
|
|
180
|
+
return_indices=False
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
Train_indices, Test_indices = bm.partition(
|
|
184
|
+
sequences,
|
|
185
|
+
y,
|
|
186
|
+
test_size=0.2,
|
|
187
|
+
data_type='sequential',
|
|
188
|
+
return_indices=True
|
|
189
|
+
)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Partitioning Signal Data
|
|
193
|
+
|
|
194
|
+
For signal data such as time series, audio signals, or sensor outputs BenchMake first ensures that the data is represented as a consistent float32 NumPy array. If the signals are provided in a multi-dimensional format (for example, if each signal has multiple channels or timepoints arranged in a 3D array), they are flattened so that each signal becomes a single row vector. Once in this unified 2D format, the rows are deterministically sorted using a stable hashing method. After min–max scaling BenchMake partitions the data. BenchMake returns either the resulting training and testing data in the same structure as the input (e.g., NumPy arrays or DataFrames) or simply the lists of indices for each split.
|
|
195
|
+
|
|
196
|
+
Signal data (time-series, audio, sensors) can be 2D `(n_signals, n_features)` or 3D `(n_signals, length, channels)`:
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
X_train, X_test, y_train, y_test = bm.partition(
|
|
200
|
+
X,
|
|
201
|
+
y,
|
|
202
|
+
test_size=0.2,
|
|
203
|
+
data_type='signal',
|
|
204
|
+
return_indices=False
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
Train_indices, Test_indices = bm.partition(
|
|
208
|
+
X,
|
|
209
|
+
y,
|
|
210
|
+
test_size=0.2,
|
|
211
|
+
data_type='signal',
|
|
212
|
+
return_indices=True
|
|
213
|
+
)
|
|
214
|
+
```
|
|
215
|
+
### Partitioning Graph Data
|
|
216
|
+
|
|
217
|
+
When dealing with graph data, BenchMake assumes that the user provides a node-feature matrix where each row represents a node and each column represents a feature (this can be in a Pandas DataFrame, NumPy array, or list format). If necessary, the multi-dimensional input is first converted into a two-dimensional float32 array (by flattening any extra dimensions). Stable hashing is applied to the rows to reorder the data, and following min–max scaling, BenchMake partitions the data based on the nodes. The final output will be either the training and testing splits in the same format as the input data or, if specified by the user, the lists of indices corresponding to these splits.
|
|
218
|
+
|
|
219
|
+
If you have a node-feature matrix `(n_nodes, n_features)`, treat it as `data_type='graph'`:
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
X_train, X_test, y_train, y_test = bm.partition(
|
|
223
|
+
X_node_features,
|
|
224
|
+
node_labels,
|
|
225
|
+
test_size=0.2,
|
|
226
|
+
data_type='graph',
|
|
227
|
+
return_indices=False
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
Train_indices, Test_indices = bm.partition(
|
|
231
|
+
X_node_features,
|
|
232
|
+
node_labels,
|
|
233
|
+
test_size=0.2,
|
|
234
|
+
data_type='graph',
|
|
235
|
+
return_indices=True
|
|
236
|
+
)
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Implementation
|
|
240
|
+
|
|
241
|
+
### Parallelism & GPU Acceleration
|
|
242
|
+
|
|
243
|
+
CPU Parallelism:
|
|
244
|
+
BenchMake uses Python’s [joblib](https://joblib.readthedocs.io/) for parallelizing the **distance** computations only.
|
|
245
|
+
The main NMF loop is effectively single-threaded from Python’s perspective, though an optimized BLAS library (MKL/OpenBLAS) can provide multi-threaded matrix multiplication.
|
|
246
|
+
|
|
247
|
+
GPU Acceleration:
|
|
248
|
+
If [CuPy](https://docs.cupy.dev/) is installed and you have a CUDA-capable GPU, BenchMake calls GPU code for the NMF factorization and distance calculations.
|
|
249
|
+
If insufficient GPU memory is detected, or if any GPU error occurs, BenchMake warns and reverts to the CPU.
|
|
250
|
+
|
|
251
|
+
Batch Size:
|
|
252
|
+
Automatically chosen to balance memory usage and overhead. You can control the number of CPU jobs via `n_jobs` when creating `BenchMake(n_jobs=4)`. Use `BenchMake(n_jobs=-1)` to access all available processors.
|
|
253
|
+
|
|
254
|
+
Important: Because most of the work is in the NMF loop, you may not see dramatic multi-CPU speedups unless you rely on a multi-threaded NumPy/BLAS or CuPy on GPU.
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
### Algorithmic Details
|
|
259
|
+
|
|
260
|
+
1. NMF (Multiplicative Update):
|
|
261
|
+
BenchMake performs a basic multiplicative‐update NMF with a fixed random seed for determinism. The number of components is equal to the desired **test set size** (i.e., `ceil(n_samples * test_size)`).
|
|
262
|
+
|
|
263
|
+
2. Archetype Selection:
|
|
264
|
+
After NMF, the code computes distances from each sample to each of the `k` archetypes, picks the closest sample to each archetype, and forms the test set from those selected indices.
|
|
265
|
+
|
|
266
|
+
3. Stable Hash Sorting:
|
|
267
|
+
BenchMake reorders all data by a hash of each row’s bytes to ensure that identical data yields identical partitions no matter the input order. This ensures strict determinism.
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
### Known Limitations
|
|
272
|
+
|
|
273
|
+
Scaling:
|
|
274
|
+
Because `k ~ O(n)` (for a constant fraction test size) and factorization and distances (d) each scale approximately as `O(n² d)`, BenchMake can become slow for very large data sets. BenchMake is not a fast alternative to random splits, it is a better alternative; delivering reproducible, and more challenging testing sets.
|
|
275
|
+
|
|
276
|
+
Limited Parallelism:
|
|
277
|
+
The NMF step is effectively single-threaded except for what is inherent in BLAS. Only the distance computations are joblib-parallelized. GPU usage (if available) provides a bigger speedup for NMF and distance steps.
|
|
278
|
+
|
|
279
|
+
Memory Consumption:
|
|
280
|
+
For large `n`, or if `test_size` is large, memory usage can be significant. BenchMake attempts to estimate GPU memory usage and revert to CPU if insufficient.
|
|
281
|
+
|
|
282
|
+
Simplicity Over Customization:
|
|
283
|
+
BenchMake does not expose advanced NMF algorithms (such as HALS or block-coordinate). The code may be extended to accommodate more sophisticated or distributed approaches in the future.
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
## Acknowledgments
|
|
287
|
+
|
|
288
|
+
### License
|
|
289
|
+
|
|
290
|
+
The project is distributed under an MIT License.
|
|
291
|
+
|
|
292
|
+
This software is provided 'as-is', without any express or implied warranty. Use at your own risk.
|
|
293
|
+
|
|
294
|
+
### Citation
|
|
295
|
+
|
|
296
|
+
Amanda S. Barnard, "BenchMake: Turn any Scientific Data Set into a Reproducible Benchmark" arXiv preprint arXiv:2506.23419, 2025.
|
|
297
|
+
|
|
298
|
+
```python
|
|
299
|
+
@misc{barnard2025benchmake,
|
|
300
|
+
title={BenchMake: Turn any scientific data set into a reproducible benchmark},
|
|
301
|
+
author={Amanda S Barnard},
|
|
302
|
+
year={2025},
|
|
303
|
+
eprint={2506.23419},
|
|
304
|
+
archivePrefix={arXiv},
|
|
305
|
+
primaryClass={cs.LG},
|
|
306
|
+
url={https://arxiv.org/abs/2506.23419},
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
Happy BenchMaking!
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
---
|
|
2
|
+
# BenchMake
|
|
3
|
+
## Turn any Scientific Data Set into a Reproducible Benchmark
|
|
4
|
+
|
|
5
|
+
Version: **1.1.2**
|
|
6
|
+
Date: **01/07/2025**
|
|
7
|
+
Author: **Prof. Amanda S. Barnard, PhD DSc**
|
|
8
|
+
|
|
9
|
+
BenchMake is a Python package that partitions a data set into train/test splits using **archetypal analysis**. It relies on an **NMF-based** approach, performing a multiplicative-update factorization and then computing distances to the discovered “archetypes.” The nearest unique data points become the test set (or optionally just the test **indices**). BenchMake supports **GPU acceleration** via **CuPy** (if available), or automatically falls back to CPU-based NumPy.
|
|
10
|
+
|
|
11
|
+
## Table of Contents
|
|
12
|
+
|
|
13
|
+
1. [Features](#features)
|
|
14
|
+
2. [Installation](#installation)
|
|
15
|
+
3. [Quick Start](#quick-start)
|
|
16
|
+
4. [Usage](#usage)
|
|
17
|
+
- [Partitioning Tabular Data](#partitioning-tabular-data)
|
|
18
|
+
- [Partitioning Images](#partitioning-images)
|
|
19
|
+
- [Partitioning Sequential Data](#partitioning-sequential-data)
|
|
20
|
+
- [Partitioning Signal Data](#partitioning-signal-data)
|
|
21
|
+
- [Partitioning Graph Data](#partitioning-graph-data)
|
|
22
|
+
5. [Implementation](#implementation)
|
|
23
|
+
- [Parallelism & GPU Acceleration](#parallelism--gpu-acceleration)
|
|
24
|
+
- [Algorithmic Details](#algorithmic-details)
|
|
25
|
+
- [Known Limitations](#known-limitations)
|
|
26
|
+
6. [Acknowledgements](#acknowledgments)
|
|
27
|
+
- [License](#license)
|
|
28
|
+
- [Citation](#citation)
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- **Archetypal Analysis Partitioning**
|
|
35
|
+
Automatically finds “extreme” points (archetypes) that best approximate the entire data set in a low-dimensional sense, and uses them to form a test set.
|
|
36
|
+
|
|
37
|
+
- **Multi-Domain Support**
|
|
38
|
+
BenchMake handles:
|
|
39
|
+
- **Tabular** structured data (NumPy arrays, Pandas DataFrames)
|
|
40
|
+
- **Image** data (multi-dimensional arrays)
|
|
41
|
+
- **Sequential** data (strings, text)
|
|
42
|
+
- **Signal** data (time-series, audio, sensor arrays)
|
|
43
|
+
- **Graph** data (node-feature matrices)
|
|
44
|
+
|
|
45
|
+
- **Deterministic**
|
|
46
|
+
Fixed random seeds and consistent initialization ensure you get the same splits every time for the same data, whatever split size you select, regardless of data order.
|
|
47
|
+
|
|
48
|
+
- **Automatic Batch Size**
|
|
49
|
+
Dynamically chooses a batch size for distance computations based on the data size and number of CPU jobs available.
|
|
50
|
+
|
|
51
|
+
- **Optional Return of Indices**
|
|
52
|
+
Users can obtain either `(X_train, X_test, y_train, y_test)` **or** `(Train_indices, Test_indices)` for maximum flexibility.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
BenchMake requires Python 3.7 or higher. To install via pip:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pip install benchmake
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Optional**: For GPU support, install [CuPy](https://docs.cupy.dev/en/stable/install.html) appropriate to your CUDA version. Install CuPy separately if you require this capability, making sure it is compatible with your CUDA installation too. If CuPy is not found or no compatible GPU exists, BenchMake reverts to CPU silently (with a warning).
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Quick Start
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from benchmake import BenchMake
|
|
72
|
+
import numpy as np
|
|
73
|
+
|
|
74
|
+
# Sample data: 1000 samples, 20 features
|
|
75
|
+
X = np.random.rand(1000, 20)
|
|
76
|
+
y = np.random.randint(0, 5, size=1000)
|
|
77
|
+
|
|
78
|
+
# Instantiate BenchMake with 4 parallel CPU jobs
|
|
79
|
+
bm = BenchMake(n_jobs=4)
|
|
80
|
+
|
|
81
|
+
# Partition the data into train/test using 20% test split
|
|
82
|
+
X_train, X_test, y_train, y_test = bm.partition(
|
|
83
|
+
X,
|
|
84
|
+
y,
|
|
85
|
+
test_size=0.2,
|
|
86
|
+
data_type='tabular',
|
|
87
|
+
return_indices=False
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
print("Train size:", len(X_train), "Test size:", len(X_test))
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Usage
|
|
96
|
+
|
|
97
|
+
### Partitioning Tabular Data
|
|
98
|
+
|
|
99
|
+
When tabular data is provided (as a NumPy array, Pandas DataFrame, or list), BenchMake first converts it to a consistent NumPy array (if it isn’t already) so that all numerical operations are performed in float32. Next, it reorders the data rows deterministically by computing a stable hash (using the MD5 algorithm) for each row. This guarantees that the same data, regardless of the original row order, produces the same sorted order. BenchMake then applies a min–max scaling to the data before partitioning. BenchMake returns either four splits (`X_train, X_test, y_train, y_test`) in the same data type as the user provided (for example, if you used Pandas DataFrames, you get DataFrames back) or, if requested, just the lists of indices for the training and testing sets.
|
|
100
|
+
|
|
101
|
+
Assume you have `(X, y)` in either a NumPy array or a Pandas DataFrame/Series. Just specify `data_type='tabular'`:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
X_train, X_test, y_train, y_test = bm.partition(
|
|
105
|
+
X,
|
|
106
|
+
y,
|
|
107
|
+
test_size=0.2,
|
|
108
|
+
data_type='tabular',
|
|
109
|
+
return_indices=False
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
Train_indices, Test_indices = bm.partition(
|
|
113
|
+
X,
|
|
114
|
+
y,
|
|
115
|
+
test_size=0.2,
|
|
116
|
+
data_type='tabular',
|
|
117
|
+
return_indices=True
|
|
118
|
+
)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Partitioning Images
|
|
122
|
+
|
|
123
|
+
For image data, BenchMake expects input in the form of a multi-dimensional array or DataFrame, where each image is typically structured as (`n_samples`, `height`, `width`, `channels`). It first converts the data to a float32 NumPy array (if it isn’t already) and then flattens each image (`n_samples, height*width*channels`) into a one-dimensional vector so that every image is represented as a row vector. The rows are then reordered deterministically using the stable hashing strategy. The images (now as 1D vectors) are min–max scaled, and the data is partitioned. BenchMake returns either the training and testing subsets in the same format as the original input (e.g., as NumPy arrays or DataFrames) or the corresponding indices if the user has requested that mode.
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
# Suppose X is shape (n_samples, height, width, channels)
|
|
127
|
+
X_train, X_test, y_train, y_test = bm.partition(
|
|
128
|
+
X,
|
|
129
|
+
y,
|
|
130
|
+
test_size=0.2,
|
|
131
|
+
data_type='image',
|
|
132
|
+
return_indices=False
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
Train_indices, Test_indices = bm.partition(
|
|
136
|
+
X,
|
|
137
|
+
y,
|
|
138
|
+
test_size=0.2,
|
|
139
|
+
data_type='image',
|
|
140
|
+
return_indices=True
|
|
141
|
+
)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Partitioning Sequential Data
|
|
145
|
+
|
|
146
|
+
BenchMake handles sequential data such as text strings, SMILES strings, or DNA sequences by first taking the provided list or Pandas Series and converting each sequence into a numerical (vector) representation using a character-level `CountVectorizer`. This transformation results in a two-dimensional NumPy array (float32) where each row corresponds to the numeric representation of a sequence. The rows of this numeric representation are then deterministically reordered via the stable hash. BenchMake then applies min–max scaling and partitions the data. Finally, the original sequences are re-ordered using the same hash order, and BenchMake returns either the full training and testing splits (in the same type as the original input, e.g., list or Series) or the indices of the splits if that is requested.
|
|
147
|
+
|
|
148
|
+
For sequences or text:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
sequences = ["ACGTG", "GGTTA", "TTACG", ...] # e.g., list of strings
|
|
152
|
+
# sequences can also be SMILEs, e.g., ["CCO", "c1ccccc1", "CC(=O)O", ...]
|
|
153
|
+
y = [label1, label2, ...] # labels
|
|
154
|
+
|
|
155
|
+
X_train, X_test, y_train, y_test = bm.partition(
|
|
156
|
+
sequences,
|
|
157
|
+
y,
|
|
158
|
+
test_size=0.2,
|
|
159
|
+
data_type='sequential',
|
|
160
|
+
return_indices=False
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
Train_indices, Test_indices = bm.partition(
|
|
164
|
+
sequences,
|
|
165
|
+
y,
|
|
166
|
+
test_size=0.2,
|
|
167
|
+
data_type='sequential',
|
|
168
|
+
return_indices=True
|
|
169
|
+
)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Partitioning Signal Data
|
|
173
|
+
|
|
174
|
+
For signal data such as time series, audio signals, or sensor outputs BenchMake first ensures that the data is represented as a consistent float32 NumPy array. If the signals are provided in a multi-dimensional format (for example, if each signal has multiple channels or timepoints arranged in a 3D array), they are flattened so that each signal becomes a single row vector. Once in this unified 2D format, the rows are deterministically sorted using a stable hashing method. After min–max scaling BenchMake partitions the data. BenchMake returns either the resulting training and testing data in the same structure as the input (e.g., NumPy arrays or DataFrames) or simply the lists of indices for each split.
|
|
175
|
+
|
|
176
|
+
Signal data (time-series, audio, sensors) can be 2D `(n_signals, n_features)` or 3D `(n_signals, length, channels)`:
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
X_train, X_test, y_train, y_test = bm.partition(
|
|
180
|
+
X,
|
|
181
|
+
y,
|
|
182
|
+
test_size=0.2,
|
|
183
|
+
data_type='signal',
|
|
184
|
+
return_indices=False
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
Train_indices, Test_indices = bm.partition(
|
|
188
|
+
X,
|
|
189
|
+
y,
|
|
190
|
+
test_size=0.2,
|
|
191
|
+
data_type='signal',
|
|
192
|
+
return_indices=True
|
|
193
|
+
)
|
|
194
|
+
```
|
|
195
|
+
### Partitioning Graph Data
|
|
196
|
+
|
|
197
|
+
When dealing with graph data, BenchMake assumes that the user provides a node-feature matrix where each row represents a node and each column represents a feature (this can be in a Pandas DataFrame, NumPy array, or list format). If necessary, the multi-dimensional input is first converted into a two-dimensional float32 array (by flattening any extra dimensions). Stable hashing is applied to the rows to reorder the data, and following min–max scaling, BenchMake partitions the data based on the nodes. The final output will be either the training and testing splits in the same format as the input data or, if specified by the user, the lists of indices corresponding to these splits.
|
|
198
|
+
|
|
199
|
+
If you have a node-feature matrix `(n_nodes, n_features)`, treat it as `data_type='graph'`:
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
X_train, X_test, y_train, y_test = bm.partition(
|
|
203
|
+
X_node_features,
|
|
204
|
+
node_labels,
|
|
205
|
+
test_size=0.2,
|
|
206
|
+
data_type='graph',
|
|
207
|
+
return_indices=False
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
Train_indices, Test_indices = bm.partition(
|
|
211
|
+
X_node_features,
|
|
212
|
+
node_labels,
|
|
213
|
+
test_size=0.2,
|
|
214
|
+
data_type='graph',
|
|
215
|
+
return_indices=True
|
|
216
|
+
)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Implementation
|
|
220
|
+
|
|
221
|
+
### Parallelism & GPU Acceleration
|
|
222
|
+
|
|
223
|
+
CPU Parallelism:
|
|
224
|
+
BenchMake uses Python’s [joblib](https://joblib.readthedocs.io/) for parallelizing the **distance** computations only.
|
|
225
|
+
The main NMF loop is effectively single-threaded from Python’s perspective, though an optimized BLAS library (MKL/OpenBLAS) can provide multi-threaded matrix multiplication.
|
|
226
|
+
|
|
227
|
+
GPU Acceleration:
|
|
228
|
+
If [CuPy](https://docs.cupy.dev/) is installed and you have a CUDA-capable GPU, BenchMake calls GPU code for the NMF factorization and distance calculations.
|
|
229
|
+
If insufficient GPU memory is detected, or if any GPU error occurs, BenchMake warns and reverts to the CPU.
|
|
230
|
+
|
|
231
|
+
Batch Size:
|
|
232
|
+
Automatically chosen to balance memory usage and overhead. You can control the number of CPU jobs via `n_jobs` when creating `BenchMake(n_jobs=4)`. Use `BenchMake(n_jobs=-1)` to access all available processors.
|
|
233
|
+
|
|
234
|
+
Important: Because most of the work is in the NMF loop, you may not see dramatic multi-CPU speedups unless you rely on a multi-threaded NumPy/BLAS or CuPy on GPU.
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
### Algorithmic Details
|
|
239
|
+
|
|
240
|
+
1. NMF (Multiplicative Update):
|
|
241
|
+
BenchMake performs a basic multiplicative‐update NMF with a fixed random seed for determinism. The number of components is equal to the desired **test set size** (i.e., `ceil(n_samples * test_size)`).
|
|
242
|
+
|
|
243
|
+
2. Archetype Selection:
|
|
244
|
+
After NMF, the code computes distances from each sample to each of the `k` archetypes, picks the closest sample to each archetype, and forms the test set from those selected indices.
|
|
245
|
+
|
|
246
|
+
3. Stable Hash Sorting:
|
|
247
|
+
BenchMake reorders all data by a hash of each row’s bytes to ensure that identical data yields identical partitions no matter the input order. This ensures strict determinism.
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
### Known Limitations
|
|
252
|
+
|
|
253
|
+
Scaling:
|
|
254
|
+
Because `k ~ O(n)` (for a constant fraction test size) and factorization and distances (d) each scale approximately as `O(n² d)`, BenchMake can become slow for very large data sets. BenchMake is not a fast alternative to random splits, it is a better alternative; delivering reproducible, and more challenging testing sets.
|
|
255
|
+
|
|
256
|
+
Limited Parallelism:
|
|
257
|
+
The NMF step is effectively single-threaded except for what is inherent in BLAS. Only the distance computations are joblib-parallelized. GPU usage (if available) provides a bigger speedup for NMF and distance steps.
|
|
258
|
+
|
|
259
|
+
Memory Consumption:
|
|
260
|
+
For large `n`, or if `test_size` is large, memory usage can be significant. BenchMake attempts to estimate GPU memory usage and revert to CPU if insufficient.
|
|
261
|
+
|
|
262
|
+
Simplicity Over Customization:
|
|
263
|
+
BenchMake does not expose advanced NMF algorithms (such as HALS or block-coordinate). The code may be extended to accommodate more sophisticated or distributed approaches in the future.
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
## Acknowledgments
|
|
267
|
+
|
|
268
|
+
### License
|
|
269
|
+
|
|
270
|
+
The project is distributed under an MIT License.
|
|
271
|
+
|
|
272
|
+
This software is provided 'as-is', without any express or implied warranty. Use at your own risk.
|
|
273
|
+
|
|
274
|
+
### Citation
|
|
275
|
+
|
|
276
|
+
Amanda S. Barnard, "BenchMake: Turn any Scientific Data Set into a Reproducible Benchmark" arXiv preprint arXiv:2506.23419, 2025.
|
|
277
|
+
|
|
278
|
+
```python
|
|
279
|
+
@misc{barnard2025benchmake,
|
|
280
|
+
title={BenchMake: Turn any scientific data set into a reproducible benchmark},
|
|
281
|
+
author={Amanda S Barnard},
|
|
282
|
+
year={2025},
|
|
283
|
+
eprint={2506.23419},
|
|
284
|
+
archivePrefix={arXiv},
|
|
285
|
+
primaryClass={cs.LG},
|
|
286
|
+
url={https://arxiv.org/abs/2506.23419},
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
Happy BenchMaking!
|