deduplicate-lib 0.1.3__tar.gz → 1.0.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.
- deduplicate_lib-1.0.0/.gitignore +10 -0
- deduplicate_lib-1.0.0/CHANGELOG.md +274 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/PKG-INFO +19 -1
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/README.md +14 -0
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_curves.png +0 -0
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_window_bimodal.png +0 -0
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_window_linear.png +0 -0
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_window_probe_steps.png +0 -0
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_window_trimodal.png +0 -0
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_window_uniform.png +0 -0
- deduplicate_lib-1.0.0/docs/_static/ntpp/ntpp_window_unimodal.png +0 -0
- deduplicate_lib-1.0.0/docs/api/core.rst +37 -0
- deduplicate_lib-1.0.0/docs/api/tolerance.rst +184 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/docs/index.rst +1 -0
- deduplicate_lib-1.0.0/docs/large_datasets.rst +186 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/docs/quickstart.rst +0 -1
- deduplicate_lib-1.0.0/docs/scripts/ntpp_window_study.py +414 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/examples/multi_hashing_demo.ipynb +6 -12
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/examples/multi_hashing_demo_output.ipynb +8 -14
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/pyproject.toml +7 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/src/deduplicate_lib/core/duplicate_detection_algorithm.py +184 -12
- deduplicate_lib-1.0.0/src/deduplicate_lib/core/hash_index.py +316 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/core/resources.py +140 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/core/tolerance_calculator.py +230 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/core/vector_store.py +405 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/distance_matrix.py +55 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/plugins/duplicate_detection_algorithms/multi_hashing.py +775 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/plugins/tolerance_calculators/natural_tolerance_plateau_probe.py +323 -0
- deduplicate_lib-1.0.0/src/deduplicate_lib/plugins/tolerance_calculators/perturbed_dataset_reclustering.py +130 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/src/deduplicate_lib/version.py +2 -2
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/conftest.py +0 -3
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/integration/test_example_notebook.py +1 -4
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/integration/test_tol_find_and_deduplicate.py +33 -46
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/unit/core/test_duplicate_detection_algorithm.py +61 -0
- deduplicate_lib-1.0.0/tests/unit/core/test_resources.py +141 -0
- deduplicate_lib-1.0.0/tests/unit/core/test_tolerance_calculator.py +157 -0
- deduplicate_lib-1.0.0/tests/unit/core/test_vector_store.py +325 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/conftest.py +9 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/reference_multi_hashing.py +46 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/unit/plugins/duplicate_detection_algoirthms/test_distance_matrix.py +50 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/test_hash_index.py +516 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/test_multi_hashing.py +515 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/test_out_of_core.py +364 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/duplicate_detection_algoirthms/test_tuning_copy.py +145 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/tolerance_calculators/test_natural_tolerance_plateau_probe.py +323 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/tolerance_calculators/test_out_of_core_tuning.py +104 -0
- deduplicate_lib-1.0.0/tests/unit/plugins/tolerance_calculators/test_perturbed_dataset_reclustering.py +165 -0
- deduplicate_lib-0.1.3/.gitignore +0 -8
- deduplicate_lib-0.1.3/CHANGELOG.md +0 -147
- deduplicate_lib-0.1.3/docs/api/core.rst +0 -12
- deduplicate_lib-0.1.3/docs/api/tolerance.rst +0 -33
- deduplicate_lib-0.1.3/src/deduplicate_lib/core/tolerance_calculator.py +0 -178
- deduplicate_lib-0.1.3/src/deduplicate_lib/plugins/duplicate_detection_algorithms/multi_hashing.py +0 -319
- deduplicate_lib-0.1.3/src/deduplicate_lib/plugins/tolerance_calculators/natural_tolerance_plateau_probe.py +0 -258
- deduplicate_lib-0.1.3/src/deduplicate_lib/plugins/tolerance_calculators/perturbed_dataset_reclustering.py +0 -104
- deduplicate_lib-0.1.3/tests/unit/core/test_tolerance_calculator.py +0 -151
- deduplicate_lib-0.1.3/tests/unit/plugins/duplicate_detection_algoirthms/test_multi_hashing.py +0 -331
- deduplicate_lib-0.1.3/tests/unit/plugins/tolerance_calculators/test_natural_tolerance_plateau_probe.py +0 -215
- deduplicate_lib-0.1.3/tests/unit/plugins/tolerance_calculators/test_perturbed_dataset_reclustering.py +0 -149
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/LICENSE +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/docs/api/algorithms.rst +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/docs/api/index.rst +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/docs/conf.py +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/docs/requirements.txt +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/src/deduplicate_lib/__init__.py +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/src/deduplicate_lib/core/__init__.py +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/src/deduplicate_lib/core/plugin_registry.py +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/src/deduplicate_lib/plugins/__init__.py +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/__init__.py +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/src/deduplicate_lib/plugins/tolerance_calculators/__init__.py +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/__init__.py +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/unit/core/.coverage +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/unit/core/__init__.py +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/unit/core/test_registry.py +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/unit/plugins/__init__.py +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/unit/plugins/duplicate_detection_algoirthms/__init__.py +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/unit/plugins/tolerance_calculators/__init__.py +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/unit/plugins/tolerance_calculators/plateau_detection.png +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/unit/plugins/tolerance_calculators/plateau_detection_DistanceMatrix.png +0 -0
- {deduplicate_lib-0.1.3 → deduplicate_lib-1.0.0}/tests/unit/plugins/tolerance_calculators/plateau_detection_MultiHashing.png +0 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2026-11-17
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
- `MultiHashing` was rewritten around flat `uint64` hash tables: per perturbation, a
|
|
9
|
+
sorted array of the dataset's distinct hashes (`sorted_hashes`), plus a per-vector
|
|
10
|
+
count of the perturbations in which it is the earliest vector of its hash bucket
|
|
11
|
+
(`unique_counts`). `get_dataset_unique_structures()` is now O(P·n log n) instead of
|
|
12
|
+
O(P·n²) and uses a fraction of the memory, which is the first step towards
|
|
13
|
+
out-of-core deduplication of very large datasets. Results are unchanged: the unique
|
|
14
|
+
masks, `duplicate_check()` and `get_uniqueness_score()` are tested against the old
|
|
15
|
+
implementation.
|
|
16
|
+
- Hashes come from a new numba kernel, `fast_quantise_and_hash`, instead of Python's
|
|
17
|
+
`hash()`, so they are the same in every process (Python salts `hash()` per process)
|
|
18
|
+
and can be persisted.
|
|
19
|
+
- Progress output of the tolerance calculators goes through `logging`
|
|
20
|
+
(`deduplicate_lib.*` loggers) instead of `print`; leftover debug prints were removed.
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- `DuplicateDetectionAlgorithm.get_unique_vector_mask()` returns the boolean mask of
|
|
24
|
+
unique vectors. `get_unique_vector_indices()` still returns integer indices.
|
|
25
|
+
- Out-of-core datasets: pass `dataset=` (a `.npy`/`.h5`/`.hdf5` path or a
|
|
26
|
+
`VectorStore`) instead of `dataset_array=`, and `MultiHashing` reads the vectors in
|
|
27
|
+
chunks instead of loading them. New `deduplicate_lib.core.vector_store` module:
|
|
28
|
+
`InMemoryStore`, `NpyStore` (memory-mapped), `HDF5Store` (appendable),
|
|
29
|
+
`CallableStore` (adapter for databases and other sources), `open_store()`.
|
|
30
|
+
- `memory_limit` (bytes, `"8GB"`, or `"auto"` = half the available memory) sizes the
|
|
31
|
+
row chunks and perturbation batches. `MultiHashing` keeps the per-perturbation hash
|
|
32
|
+
tables only if they fit in a quarter of it; otherwise it keeps just the unique
|
|
33
|
+
counts, and `duplicate_check()`, `get_uniqueness_score()` and appends raise
|
|
34
|
+
`MemoryError`.
|
|
35
|
+
- `n_threads`: `fast_quantise_and_hash` is now parallel (numba `prange`).
|
|
36
|
+
- `progress=True` shows tqdm progress bars.
|
|
37
|
+
- `deduplicate(out=...)` streams the unique vectors to a `.npy`/HDF5 file and returns
|
|
38
|
+
it as a store. Out-of-core datasets write `<input>_unique.<ext>` by default; for
|
|
39
|
+
in-memory datasets `deduplicate()` still returns an array.
|
|
40
|
+
- `MultiHashing(index_dir=...)` keeps the hash tables on disk (memory-mapped), so
|
|
41
|
+
`duplicate_check()` and appends work at any dataset size. The index is reused when
|
|
42
|
+
the dataset and hashing parameters match (`IndexMismatchError` names what differs),
|
|
43
|
+
resumes an interrupted build (it commits after every perturbation batch), and
|
|
44
|
+
recovers vectors appended to an HDF5 dataset without a `flush()`. Commits are
|
|
45
|
+
atomic (`metadata.json` names the current generation-numbered files) and fsynced;
|
|
46
|
+
see `deduplicate_lib.core.hash_index`.
|
|
47
|
+
- `MultiHashing.add_vectors()` appends many vectors at once (same result as appending
|
|
48
|
+
one at a time) and `MultiHashing.flush()` saves appended vectors to the index.
|
|
49
|
+
- `VectorStore.iter_chunks()` takes an optional row range.
|
|
50
|
+
- Optional extras `hdf5` (h5py) and `progress` (tqdm).
|
|
51
|
+
- Docs: a "Large datasets" page.
|
|
52
|
+
|
|
53
|
+
### Changed (DistanceMatrix)
|
|
54
|
+
- `DistanceMatrix` refuses out-of-core datasets (`ValueError`) and raises
|
|
55
|
+
`MemoryError` when its `max_vector_array_size`² matrix would exceed `memory_limit`,
|
|
56
|
+
pointing to `MultiHashing`. Pass a larger `memory_limit` to override.
|
|
57
|
+
|
|
58
|
+
### Changed (tolerance calculators, breaking)
|
|
59
|
+
- Both tolerance calculators tune on a sample of the dataset read through
|
|
60
|
+
`dda.store`, so they work on out-of-core datasets, and run every search on a
|
|
61
|
+
separate in-memory copy of the DDA (`DuplicateDetectionAlgorithm.tuning_copy()`):
|
|
62
|
+
the DDA passed in (its dataset, store, `index_dir` and hash tables) is no longer
|
|
63
|
+
modified. New arguments `sample_size` (rows tuned on), `sampling` (`"blocks"`,
|
|
64
|
+
`"random"`, `"head"`), `block_rows` and `seed`; all arguments after the DDA are
|
|
65
|
+
keyword-only.
|
|
66
|
+
- `PerturbedDatasetReclustering` builds its noisy copies from the sample (default
|
|
67
|
+
`perturbations_per_vector=5`, `sample_size=500`, `sampling="random"`); the default
|
|
68
|
+
target is the number of sampled vectors. An invalid
|
|
69
|
+
`target_unique_vectors_threshold` raises in `__init__`.
|
|
70
|
+
- `NaturalTolerancePlateauProbe` sweeps log-spaced tolerances from below the
|
|
71
|
+
"all different" to above the "all same" tolerance (it used a linear sweep between
|
|
72
|
+
10%/90%-unique bounds, which missed fine clustering scales), detects plateaus
|
|
73
|
+
against log tolerance, merges neighbouring plateaus with the same count, and returns
|
|
74
|
+
a plateau's geometric midpoint. New `find_natural_plateaus()` returns every plateau
|
|
75
|
+
as a `Plateau` (start/end/midpoint tolerance, unique count, steps, `trivial`);
|
|
76
|
+
`calculate_tolerance(condition=...)` takes `"longest"` (default), `"tightest"` or
|
|
77
|
+
`"loosest"` and never picks the trivial all-unique/all-same plateaus. Default
|
|
78
|
+
`sampling="blocks"`. The gradient window (`datapoints_to_calculate_gradient`) now
|
|
79
|
+
defaults to 10% of `probe_steps` (it was 3 steps), chosen from a study across
|
|
80
|
+
synthetic datasets, sizes, dimensions and both DDAs; see "Choosing the gradient
|
|
81
|
+
window" in the docs and `docs/scripts/ntpp_window_study.py`. Fixes plateau detection mis-pairing starts and ends when the
|
|
82
|
+
sweep begins inside a plateau.
|
|
83
|
+
- `memory_limit="auto"` uses `MemAvailable` on Linux; it used the free physical
|
|
84
|
+
pages, which leave out reclaimable page cache and were often a small fraction of
|
|
85
|
+
the usable memory.
|
|
86
|
+
|
|
87
|
+
### Added (tolerance calculators)
|
|
88
|
+
- `VectorStore.sample_blocks()` and `deduplicate_lib.core.tolerance_calculator.draw_sample()`.
|
|
89
|
+
|
|
90
|
+
### Fixed
|
|
91
|
+
- `deduplicate()` recomputes the unique mask first; it returned rows chosen by a stale
|
|
92
|
+
mask after a `tolerance` change or a same-size `set_dataset_array()`.
|
|
93
|
+
- `MultiHashing` keeps a user-supplied `pertrubation_array`; it was replaced by one
|
|
94
|
+
generated from `seed` on the first build. A seed-generated array is regenerated when
|
|
95
|
+
`seed` changes, and assigning a new array triggers a rebuild.
|
|
96
|
+
- `deduplicate(out=...)` refuses to write over its own input file.
|
|
97
|
+
- `DistanceMatrix.set_dataset_store()` with an on-disk dataset raises before dropping the
|
|
98
|
+
current data, leaving the DDA usable.
|
|
99
|
+
- `DistanceMatrix` only refuses (`MemoryError`) a distance matrix larger than an
|
|
100
|
+
explicit `memory_limit`; with the default `"auto"` (which depends on the memory free
|
|
101
|
+
at that moment) it warns (`ResourceWarning`).
|
|
102
|
+
- `MultiHashing.add_vectors()` keeps `vector_count` in step with the hash tables if it
|
|
103
|
+
fails part-way, and hashes rows left in an out-of-core store by such a failure before
|
|
104
|
+
appending more.
|
|
105
|
+
- `VectorStore.take()`/`sample()` read only the requested rows (memory-mapped fancy
|
|
106
|
+
indexing for `.npy`, one point selection for HDF5) instead of a 65536-row chunk per row.
|
|
107
|
+
- The hash index fingerprints every indexed row (sha256 per block of 2^20 rows,
|
|
108
|
+
extended incrementally as the index grows) instead of the first and last 1024 rows,
|
|
109
|
+
so an index is no longer reused after rows in the middle of the dataset change.
|
|
110
|
+
Opening an index reads the indexed rows once. Index format version 2.
|
|
111
|
+
|
|
112
|
+
### Known issues
|
|
113
|
+
- Peak memory while building hash tables can exceed `memory_limit` by roughly
|
|
114
|
+
1.2-1.5x (`np.unique`'s working copies are not budgeted).
|
|
115
|
+
- Many small `MultiHashing.add_vectors()` calls in `index_dir` mode slow down with the
|
|
116
|
+
number of pending (unflushed) hashes; call `flush()` periodically or add in larger
|
|
117
|
+
batches.
|
|
118
|
+
|
|
119
|
+
### Removed (breaking)
|
|
120
|
+
- `ToleranceCalculator(tolerance_dataset_array=...)`, `temp_attr`,
|
|
121
|
+
`create_perturbed_dataset()`, `_ensure_perturbed_dataset()`, and the
|
|
122
|
+
`perturbations_per_vector`/`perturbation_scale` arguments of the base class and
|
|
123
|
+
`NaturalTolerancePlateauProbe`; `NaturalTolerancePlateauProbe(probe_buffer_fraction=...)`
|
|
124
|
+
and its `"minimum"`/`"maximum"` conditions (use `"tightest"`/`"loosest"`).
|
|
125
|
+
- `MultiHashing.hash_dict` and its helpers (`initialize_hash_vector_dictionary`,
|
|
126
|
+
`compute_hash_vector_dictionary`, `add_input_vector_hashes_to_dictionary`,
|
|
127
|
+
`warn_if_vector_dict_mismatch`) and `fast_round_and_perturb`. Use
|
|
128
|
+
`sorted_hashes`/`unique_counts`, `initialize_hash_tables()`, `compute_hash_tables()`
|
|
129
|
+
and `add_input_vector_hashes()` instead. `create_hash_vector()` now returns `uint64`
|
|
130
|
+
hashes, whose values differ from the old ones.
|
|
131
|
+
|
|
132
|
+
## [0.1.3] - 2026-10-12
|
|
133
|
+
|
|
134
|
+
### Changed
|
|
135
|
+
- Packaging moved to uv + hatchling: dev/test dependencies are now PEP 735 dependency
|
|
136
|
+
groups (`uv sync` installs them) instead of the `dev` extra, `uv.lock` pins the
|
|
137
|
+
development environment, and CI installs with `uv sync --locked` and tests on
|
|
138
|
+
Python 3.10–3.12.
|
|
139
|
+
- Minimum Python version raised from 3.8 to 3.10 (current numba releases already
|
|
140
|
+
require it).
|
|
141
|
+
- The version now comes from git tags via hatch-vcs instead of a hand-edited
|
|
142
|
+
`__version__` (which had drifted: the `0.1.2` tag still said `0.1.1`).
|
|
143
|
+
`deduplicate_lib.__version__` still works. New tags use the `vMAJOR.MINOR.PATCH` form.
|
|
144
|
+
- Ruff now enforces the same rule set as ALomancy (isort, bugbear, pyupgrade,
|
|
145
|
+
comprehensions, unused arguments, simplify, ruff-specific). Code was updated to
|
|
146
|
+
match: sorted imports, builtin generics, `stacklevel=2` on all warnings, so they
|
|
147
|
+
point at the caller instead of inside the library.
|
|
148
|
+
- `DuplicateDetectionAlgorithm.pre_dda_processing()` (and the `MultiHashing`
|
|
149
|
+
override) no longer accept unused `*args, **kwargs`.
|
|
150
|
+
|
|
151
|
+
### Fixed
|
|
152
|
+
- `DistanceMatrix.get_dataset_unique_structures()` now keeps exactly one vector from
|
|
153
|
+
each group of near-duplicates: in dataset order, a vector is unique unless it is within
|
|
154
|
+
`tolerance` of a vector already kept. Before, a vector counted as unique only if
|
|
155
|
+
nothing at all was within `tolerance` (row 0 excepted), so every group that didn't
|
|
156
|
+
contain row 0 was flagged in full and `deduplicate()` dropped it entirely. This matches
|
|
157
|
+
`MultiHashing`, which already keeps the first vector of each group.
|
|
158
|
+
|
|
159
|
+
### Behaviour change
|
|
160
|
+
- Unique counts from `DistanceMatrix` are higher wherever near-duplicate groups exist,
|
|
161
|
+
so the tolerances that `NaturalTolerancePlateauProbe` and
|
|
162
|
+
`PerturbedDatasetReclustering` find with it shift. In the integration tests,
|
|
163
|
+
0.168 → 0.181 (reclustering) and 0.141 → 0.153 (plateau probe). At the old values,
|
|
164
|
+
one point plus a 30-vector cluster deduplicated to the point alone; at the new
|
|
165
|
+
values, to the point plus one cluster member.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## [0.1.2] - 2026-09-23
|
|
170
|
+
|
|
171
|
+
### Fixed
|
|
172
|
+
- `NaturalTolerancePlateauProbe`: fixed selection of the minimum/maximum plateau.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## [0.1.1] - 2026-09-23
|
|
177
|
+
|
|
178
|
+
### Added
|
|
179
|
+
- `NaturalTolerancePlateauProbe` can select the minimum or maximum plateau.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## [0.1.0] - 2026-06-14
|
|
184
|
+
|
|
185
|
+
### Fixed
|
|
186
|
+
- `MultiHashing.duplicate_check()` / `get_uniqueness_score()` no longer return stale results
|
|
187
|
+
when `tolerance`, `seed`, or `perturbations` change after the hash dictionary was first
|
|
188
|
+
built — `pre_dda_processing()` now detects these changes and forces a rebuild.
|
|
189
|
+
- `DistanceMatrix.duplicate_check()` no longer triggers an unnecessary full O(N²)
|
|
190
|
+
distance-matrix rebuild (and large preallocation) on a clean dataset; it now only ensures
|
|
191
|
+
the dataset array is preinitialized.
|
|
192
|
+
- `set_dataset_array()` is now a no-op (no reallocation, no `_dirty` invalidation) when the
|
|
193
|
+
incoming array is identical to the data already loaded, avoiding redundant rebuilds when
|
|
194
|
+
tolerance calculators temporarily swap datasets and restore the original.
|
|
195
|
+
- Removed a redundant double-computation of the hash vector dictionary in
|
|
196
|
+
`MultiHashing.get_dataset_unique_structures()`.
|
|
197
|
+
- `DistanceMatrix._rebuild_auxiliary_structures()` no longer redundantly reinitializes the
|
|
198
|
+
distance matrix before recomputing it.
|
|
199
|
+
|
|
200
|
+
### Changed
|
|
201
|
+
- Dropped the unused `input_dataset_array` parameter from `pre_dda_processing()`.
|
|
202
|
+
- Extracted `MultiHashing._perturbation_array_stale()` to share the perturbation-array
|
|
203
|
+
staleness check between `pre_dda_processing()` and `_rebuild_auxiliary_structures()`.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## [0.0.5] - 2026-04-23
|
|
208
|
+
|
|
209
|
+
### Changed
|
|
210
|
+
- Reinstated dictionary-based storage in multi-hashing implementation (`b3f3fad`).
|
|
211
|
+
- Verified full test and coverage status for the dictionary reversion (`b3f3fad`).
|
|
212
|
+
- Finalized release/build readiness updates (`ff9ee21`, `02614ed`).
|
|
213
|
+
|
|
214
|
+
### Merged
|
|
215
|
+
- PR #9: Reinstate dictionaries for MH (`aa9aff4`).
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## [0.0.4] - 2026-04-22
|
|
220
|
+
|
|
221
|
+
### Added
|
|
222
|
+
- Pre-initialisation logic for dataset handling (`60736ff`).
|
|
223
|
+
|
|
224
|
+
### Changed
|
|
225
|
+
- Coverage/test completeness improvements (`74658d4`).
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## [0.0.3] - 2026-04-16
|
|
230
|
+
|
|
231
|
+
### Added
|
|
232
|
+
- Tight and loose options to PDR (`eca4ab0`).
|
|
233
|
+
- `get_uniqueness_score` support in multi-hash flow (`671ddac`).
|
|
234
|
+
|
|
235
|
+
### Changed
|
|
236
|
+
- Acceptance threshold moved to sigma-based threshold (`62d80e6`).
|
|
237
|
+
- Round-then-perturb bug fix and hash-array/input reset fixes (`671ddac`).
|
|
238
|
+
- Test updates and cleanup (`4d72241`, `47f1271`).
|
|
239
|
+
- Version update for v0.0.3 (`ab12fde`).
|
|
240
|
+
|
|
241
|
+
### Merged
|
|
242
|
+
- PR #5: Release v0.0.3 (`97d2102`).
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## [0.0.2] - 2026-03-30
|
|
247
|
+
|
|
248
|
+
### Added
|
|
249
|
+
- Example usage and deduplicate function introduced (`7ee94df`).
|
|
250
|
+
- Additional tests (`85e666a`).
|
|
251
|
+
- SciPy dependency (`9c1cfc4`).
|
|
252
|
+
|
|
253
|
+
### Changed
|
|
254
|
+
- Release prep for v0.0.2 (`2239439`).
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## [0.0.1] - 2026-03-26
|
|
259
|
+
|
|
260
|
+
### Added
|
|
261
|
+
- Initial CI and test setup (`b0b5477`, `bb03869`).
|
|
262
|
+
- Numba acceleration for DDAs (`cf10a8e`, `fa93d56`).
|
|
263
|
+
- Codecov integration and badge (`033d99f`, `e13a1ba`).
|
|
264
|
+
- License and core tolerance calculator tests (`3edf959`).
|
|
265
|
+
|
|
266
|
+
### Changed
|
|
267
|
+
- README and packaging updates (`851b609`, `8108a50`).
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## [0.0.0] - 2026-03-17
|
|
272
|
+
|
|
273
|
+
### Added
|
|
274
|
+
- Initial project commit (`03a02d8`).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: deduplicate_lib
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Deduplication of numpy vector arrays, with automatic tolerance tuning.
|
|
5
5
|
Project-URL: Homepage, https://github.com/julianholland/deduplicate
|
|
6
6
|
Project-URL: Repository, https://github.com/julianholland/deduplicate
|
|
@@ -23,6 +23,10 @@ Provides-Extra: docs
|
|
|
23
23
|
Requires-Dist: furo; extra == 'docs'
|
|
24
24
|
Requires-Dist: sphinx-autodoc-typehints; extra == 'docs'
|
|
25
25
|
Requires-Dist: sphinx>=7; extra == 'docs'
|
|
26
|
+
Provides-Extra: hdf5
|
|
27
|
+
Requires-Dist: h5py; extra == 'hdf5'
|
|
28
|
+
Provides-Extra: progress
|
|
29
|
+
Requires-Dist: tqdm; extra == 'progress'
|
|
26
30
|
Description-Content-Type: text/markdown
|
|
27
31
|
|
|
28
32
|
<div align="center">
|
|
@@ -76,6 +80,20 @@ dda.input_vector = np.array([1.0, 2.0])
|
|
|
76
80
|
print(dda.duplicate_check()) # True
|
|
77
81
|
```
|
|
78
82
|
|
|
83
|
+
### Large datasets
|
|
84
|
+
|
|
85
|
+
Datasets too large for memory can be deduplicated straight from disk (`.npy`, HDF5, or any
|
|
86
|
+
source via `CallableStore`), in chunks sized by `memory_limit`:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
dda = MultiHashing(dataset="descriptors.npy", tolerance=0.05, memory_limit="8GB", n_threads=8)
|
|
90
|
+
dda.get_dataset_unique_structures()
|
|
91
|
+
mask = dda.get_unique_vector_mask() # boolean mask over the dataset
|
|
92
|
+
dda.deduplicate() # writes descriptors_unique.npy
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Optional extras: `pip install deduplicate_lib[hdf5,progress]`.
|
|
96
|
+
|
|
79
97
|
See the **[full documentation](https://deduplicate-lib.readthedocs.io)** for API reference, tolerance tuning, and more examples.
|
|
80
98
|
|
|
81
99
|
### Dependencies
|
|
@@ -49,6 +49,20 @@ dda.input_vector = np.array([1.0, 2.0])
|
|
|
49
49
|
print(dda.duplicate_check()) # True
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
### Large datasets
|
|
53
|
+
|
|
54
|
+
Datasets too large for memory can be deduplicated straight from disk (`.npy`, HDF5, or any
|
|
55
|
+
source via `CallableStore`), in chunks sized by `memory_limit`:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
dda = MultiHashing(dataset="descriptors.npy", tolerance=0.05, memory_limit="8GB", n_threads=8)
|
|
59
|
+
dda.get_dataset_unique_structures()
|
|
60
|
+
mask = dda.get_unique_vector_mask() # boolean mask over the dataset
|
|
61
|
+
dda.deduplicate() # writes descriptors_unique.npy
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Optional extras: `pip install deduplicate_lib[hdf5,progress]`.
|
|
65
|
+
|
|
52
66
|
See the **[full documentation](https://deduplicate-lib.readthedocs.io)** for API reference, tolerance tuning, and more examples.
|
|
53
67
|
|
|
54
68
|
### Dependencies
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
Core API
|
|
2
|
+
========
|
|
3
|
+
|
|
4
|
+
The typical DDA lifecycle is: construct the DDA (optionally passing
|
|
5
|
+
``dataset_array`` or calling ``set_dataset_array()`` afterwards) → set
|
|
6
|
+
``input_vector`` → call ``duplicate_check()`` or
|
|
7
|
+
``add_input_vector_to_dda()`` for streaming ingestion → call
|
|
8
|
+
``deduplicate()`` to retrieve the full set of unique vectors.
|
|
9
|
+
|
|
10
|
+
.. autoclass:: deduplicate_lib.core.duplicate_detection_algorithm.DuplicateDetectionAlgorithm
|
|
11
|
+
:members: deduplicate, duplicate_check, add_input_vector_to_dda, set_dataset_array, set_dataset_store, store, is_out_of_core, get_dataset_unique_structures, get_unique_vector_mask, get_unique_vector_indices, tuning_copy
|
|
12
|
+
:show-inheritance:
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
Vector stores
|
|
16
|
+
-------------
|
|
17
|
+
|
|
18
|
+
Where a dataset's vectors live. Pass a path or a store as ``dataset`` to use an
|
|
19
|
+
out-of-core dataset; see :doc:`../large_datasets`.
|
|
20
|
+
|
|
21
|
+
.. automodule:: deduplicate_lib.core.vector_store
|
|
22
|
+
:members: VectorStore, InMemoryStore, NpyStore, HDF5Store, CallableStore, open_store
|
|
23
|
+
:show-inheritance:
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
Hash index
|
|
27
|
+
----------
|
|
28
|
+
|
|
29
|
+
.. automodule:: deduplicate_lib.core.hash_index
|
|
30
|
+
:members: HashIndex, IndexMismatchError
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
Resources
|
|
34
|
+
---------
|
|
35
|
+
|
|
36
|
+
.. automodule:: deduplicate_lib.core.resources
|
|
37
|
+
:members: parse_memory_limit, chunk_rows, perturbation_batch
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Tolerance Calculators
|
|
2
|
+
=====================
|
|
3
|
+
|
|
4
|
+
Tolerance calculators automatically find a ``tolerance`` value for a given
|
|
5
|
+
dataset and DDA. Run the calculator once, then assign the result to
|
|
6
|
+
``dda.tolerance`` before calling ``deduplicate()`` or ``duplicate_check()``.
|
|
7
|
+
They tune on a sample of ``sample_size`` vectors (see :doc:`../large_datasets`)
|
|
8
|
+
and never modify the DDA they are given.
|
|
9
|
+
|
|
10
|
+
.. autoclass:: deduplicate_lib.core.tolerance_calculator.ToleranceCalculator
|
|
11
|
+
:members: binary_search_tolerance
|
|
12
|
+
|
|
13
|
+
.. autofunction:: deduplicate_lib.core.tolerance_calculator.draw_sample
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
PerturbedDatasetReclustering
|
|
17
|
+
-----------------------------
|
|
18
|
+
|
|
19
|
+
Follows each sampled vector with ``perturbations_per_vector - 1`` copies
|
|
20
|
+
carrying Gaussian noise of scale ``perturbation_scale``, then binary-searches
|
|
21
|
+
for the tolerance at which the copies collapse back onto their originals.
|
|
22
|
+
``"average"`` mode averages the loose and tight bounds; ``"loose"`` returns the
|
|
23
|
+
highest valid tolerance; ``"tight"`` returns the lowest.
|
|
24
|
+
|
|
25
|
+
.. autoclass:: deduplicate_lib.plugins.tolerance_calculators.perturbed_dataset_reclustering.PerturbedDatasetReclustering
|
|
26
|
+
:members: calculate_tolerance
|
|
27
|
+
:show-inheritance:
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
NaturalTolerancePlateauProbe
|
|
31
|
+
-----------------------------
|
|
32
|
+
|
|
33
|
+
No perturbed data needed. Sweeps log-spaced tolerances from below the
|
|
34
|
+
all-different bound to above the all-same bound, records the unique-structure
|
|
35
|
+
count at each step, and finds plateaus — regions where the clustering is stable
|
|
36
|
+
and insensitive to small changes in tolerance, i.e. natural clustering scales.
|
|
37
|
+
``find_natural_plateaus()`` lists them; ``calculate_tolerance()`` returns the
|
|
38
|
+
midpoint of the longest, tightest or loosest one (the trivial all-unique and
|
|
39
|
+
all-same plateaus at the ends are never chosen).
|
|
40
|
+
|
|
41
|
+
.. autoclass:: deduplicate_lib.plugins.tolerance_calculators.natural_tolerance_plateau_probe.NaturalTolerancePlateauProbe
|
|
42
|
+
:members: calculate_tolerance, find_natural_plateaus
|
|
43
|
+
:show-inheritance:
|
|
44
|
+
|
|
45
|
+
.. autoclass:: deduplicate_lib.plugins.tolerance_calculators.natural_tolerance_plateau_probe.Plateau
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
Choosing the gradient window
|
|
49
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
50
|
+
|
|
51
|
+
A plateau is a run of probe steps over which the unique-vector count barely
|
|
52
|
+
changes, measured over a window of ``datapoints_to_calculate_gradient`` steps.
|
|
53
|
+
The window is a trade-off:
|
|
54
|
+
|
|
55
|
+
* **Too small**, and noise in the curve shows up as false plateaus. The
|
|
56
|
+
random gaps between vectors of data with no structure make short flat
|
|
57
|
+
stretches.
|
|
58
|
+
* **Too large**, and genuine plateaus shorter than the window are missed.
|
|
59
|
+
|
|
60
|
+
By default the window is 10% of ``probe_steps`` (``DEFAULT_WINDOW_FRACTION``),
|
|
61
|
+
chosen from the study below. Pass an integer to override it.
|
|
62
|
+
|
|
63
|
+
The study sweeps synthetic datasets with a known answer, for 8, 64 and 256
|
|
64
|
+
dimensions, 100, 400 and 1600 vectors, both DDAs, 50 to 400 probe steps and
|
|
65
|
+
3 seeds (720 sweeps). Every window from 2% to 20% of the sweep is then
|
|
66
|
+
scored on whether NTPP finds exactly the expected non-trivial plateaus:
|
|
67
|
+
|
|
68
|
+
* **bimodal**: groups of 4 near-duplicates, so one plateau, at n/4.
|
|
69
|
+
* **trimodal**: super-clusters of clusters of near-duplicates, so two plateaus.
|
|
70
|
+
* **linear**, **uniform**, **unimodal**: points along a line, uniform in a
|
|
71
|
+
hypercube, and a single Gaussian. These have no natural scale, so the
|
|
72
|
+
right answer is no plateau at all.
|
|
73
|
+
|
|
74
|
+
The figures come from ``docs/scripts/ntpp_window_study.py``, which can be
|
|
75
|
+
re-run to reproduce them.
|
|
76
|
+
|
|
77
|
+
.. figure:: ../_static/ntpp/ntpp_curves.png
|
|
78
|
+
:width: 100%
|
|
79
|
+
:alt: Unique vectors against tolerance for the five datasets, with the
|
|
80
|
+
plateaus NTPP finds shaded.
|
|
81
|
+
|
|
82
|
+
What NTPP sees: the unique-vector count across the sweep for each dataset
|
|
83
|
+
(d = 8, n = 400, DistanceMatrix), with the plateaus found at the default
|
|
84
|
+
window shaded. Bimodal and trimodal give their expected plateaus. The
|
|
85
|
+
linear dataset shows the main failure mode on data with no structure: a
|
|
86
|
+
plateau just below "all unique" (399 of 400), where its closest pair has
|
|
87
|
+
merged long before the next one. NTPP cannot tell this apart from a
|
|
88
|
+
dataset that really has one near-duplicate pair.
|
|
89
|
+
|
|
90
|
+
.. list-table:: Share of runs with exactly the expected plateaus
|
|
91
|
+
:header-rows: 1
|
|
92
|
+
|
|
93
|
+
* - window (% of sweep)
|
|
94
|
+
- 4%
|
|
95
|
+
- 6%
|
|
96
|
+
- 8%
|
|
97
|
+
- **10%**
|
|
98
|
+
- 12%
|
|
99
|
+
- 15%
|
|
100
|
+
* - bimodal, trimodal (right plateaus found)
|
|
101
|
+
- 90%
|
|
102
|
+
- 91%
|
|
103
|
+
- 94%
|
|
104
|
+
- **94%**
|
|
105
|
+
- 93%
|
|
106
|
+
- 88%
|
|
107
|
+
* - linear, uniform, unimodal (no false plateau)
|
|
108
|
+
- 54%
|
|
109
|
+
- 75%
|
|
110
|
+
- 86%
|
|
111
|
+
- **91%**
|
|
112
|
+
- 93%
|
|
113
|
+
- 94%
|
|
114
|
+
|
|
115
|
+
**The window is a share of the sweep, not a number of steps.** The noise in
|
|
116
|
+
the curve spans a fixed range of tolerance. Probing more finely only samples
|
|
117
|
+
the same noise more often, so the window must span the same share of the
|
|
118
|
+
sweep whatever ``probe_steps`` is. More probe steps only make the plateau
|
|
119
|
+
edges sharper:
|
|
120
|
+
|
|
121
|
+
.. figure:: ../_static/ntpp/ntpp_window_probe_steps.png
|
|
122
|
+
:width: 100%
|
|
123
|
+
:alt: Share of correct runs against window size, one line per probe_steps
|
|
124
|
+
value, nearly identical.
|
|
125
|
+
|
|
126
|
+
All datasets and sizes at d = 8: the curves for 50 to 400 probe steps lie
|
|
127
|
+
on top of each other once the window is given as a share of the sweep.
|
|
128
|
+
|
|
129
|
+
Per dataset, by dimension (rows) and dataset size (columns), pooled over
|
|
130
|
+
probe densities and seeds. The dashed line marks the default window:
|
|
131
|
+
|
|
132
|
+
.. figure:: ../_static/ntpp/ntpp_window_bimodal.png
|
|
133
|
+
:width: 100%
|
|
134
|
+
:alt: Bimodal: share of correct runs against window size.
|
|
135
|
+
|
|
136
|
+
Bimodal: the single plateau is wide and is found at any window from
|
|
137
|
+
about 8%.
|
|
138
|
+
|
|
139
|
+
.. figure:: ../_static/ntpp/ntpp_window_trimodal.png
|
|
140
|
+
:width: 100%
|
|
141
|
+
:alt: Trimodal: share of correct runs against window size.
|
|
142
|
+
|
|
143
|
+
Trimodal: DistanceMatrix finds both plateaus at every dimension.
|
|
144
|
+
MultiHashing's coarse plateau shrinks as the dimension grows and drops
|
|
145
|
+
out above about 13% at d = 64. At d = 256 it is too narrow for any but
|
|
146
|
+
the smallest windows (see the limitations below).
|
|
147
|
+
|
|
148
|
+
.. figure:: ../_static/ntpp/ntpp_window_linear.png
|
|
149
|
+
:width: 100%
|
|
150
|
+
:alt: Linear: share of correct runs against window size.
|
|
151
|
+
|
|
152
|
+
Linear: the hardest case. The near-"all unique" plateau described above
|
|
153
|
+
needs windows of 10-20% to suppress, and is never suppressed in some
|
|
154
|
+
configurations.
|
|
155
|
+
|
|
156
|
+
.. figure:: ../_static/ntpp/ntpp_window_uniform.png
|
|
157
|
+
:width: 100%
|
|
158
|
+
:alt: Uniform: share of correct runs against window size.
|
|
159
|
+
|
|
160
|
+
Uniform: in 8 dimensions false plateaus remain in about 1 run in 10 even
|
|
161
|
+
at 10-15%, mostly with few vectors (n = 100). In 64 and 256 dimensions
|
|
162
|
+
there are none from about 6% upwards.
|
|
163
|
+
|
|
164
|
+
.. figure:: ../_static/ntpp/ntpp_window_unimodal.png
|
|
165
|
+
:width: 100%
|
|
166
|
+
:alt: Unimodal: share of correct runs against window size.
|
|
167
|
+
|
|
168
|
+
Unimodal (Gaussian): no false plateaus from about 8%.
|
|
169
|
+
|
|
170
|
+
**Limitations.**
|
|
171
|
+
|
|
172
|
+
* *Data with few duplicates.* On data with no clustering, NTPP can report a
|
|
173
|
+
plateau just below "all unique", because the closest pair or two merge long
|
|
174
|
+
before the rest. Check ``find_natural_plateaus()``: a plateau whose
|
|
175
|
+
``unique_vectors`` is close to the sample size means very few duplicates.
|
|
176
|
+
``"tightest"`` will pick it.
|
|
177
|
+
* *MultiHashing in high dimensions.* MultiHashing rounds every coordinate to
|
|
178
|
+
the ``tolerance`` grid, so coarse clusters only merge once the tolerance
|
|
179
|
+
nears the spread of the coordinates, just below its all-same tolerance. In
|
|
180
|
+
high dimensions this squeezes the coarsest plateau against the top of the
|
|
181
|
+
sweep. It may be missed, or found much narrower than with DistanceMatrix.
|
|
182
|
+
Finer scales, such as near-duplicates, are unaffected. If you need the
|
|
183
|
+
coarse scale, tune with a ``DistanceMatrix`` on a small sample, or set a
|
|
184
|
+
smaller ``datapoints_to_calculate_gradient`` and inspect the plateaus.
|