deduplicate-lib 0.1.2__tar.gz → 0.1.3__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-0.1.3/.gitignore +8 -0
- deduplicate_lib-0.1.3/CHANGELOG.md +147 -0
- {deduplicate_lib-0.1.2/src/deduplicate_lib.egg-info → deduplicate_lib-0.1.3}/PKG-INFO +28 -28
- {deduplicate_lib-0.1.2 → deduplicate_lib-0.1.3}/README.md +7 -7
- deduplicate_lib-0.1.3/docs/api/algorithms.rst +51 -0
- deduplicate_lib-0.1.3/docs/api/core.rst +12 -0
- deduplicate_lib-0.1.3/docs/api/index.rst +8 -0
- deduplicate_lib-0.1.3/docs/api/tolerance.rst +33 -0
- deduplicate_lib-0.1.3/docs/conf.py +22 -0
- deduplicate_lib-0.1.3/docs/index.rst +14 -0
- deduplicate_lib-0.1.3/docs/quickstart.rst +71 -0
- deduplicate_lib-0.1.3/docs/requirements.txt +3 -0
- deduplicate_lib-0.1.3/examples/multi_hashing_demo.ipynb +355 -0
- deduplicate_lib-0.1.3/examples/multi_hashing_demo_output.ipynb +685 -0
- deduplicate_lib-0.1.3/pyproject.toml +183 -0
- deduplicate_lib-0.1.3/src/deduplicate_lib/__init__.py +6 -0
- {deduplicate_lib-0.1.2 → deduplicate_lib-0.1.3}/src/deduplicate_lib/core/duplicate_detection_algorithm.py +72 -43
- {deduplicate_lib-0.1.2 → deduplicate_lib-0.1.3}/src/deduplicate_lib/core/plugin_registry.py +1 -2
- {deduplicate_lib-0.1.2 → deduplicate_lib-0.1.3}/src/deduplicate_lib/core/tolerance_calculator.py +55 -33
- {deduplicate_lib-0.1.2 → deduplicate_lib-0.1.3}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/distance_matrix.py +31 -12
- {deduplicate_lib-0.1.2 → deduplicate_lib-0.1.3}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/multi_hashing.py +88 -48
- {deduplicate_lib-0.1.2 → deduplicate_lib-0.1.3}/src/deduplicate_lib/plugins/tolerance_calculators/natural_tolerance_plateau_probe.py +58 -31
- {deduplicate_lib-0.1.2 → deduplicate_lib-0.1.3}/src/deduplicate_lib/plugins/tolerance_calculators/perturbed_dataset_reclustering.py +22 -12
- deduplicate_lib-0.1.3/src/deduplicate_lib/version.py +24 -0
- deduplicate_lib-0.1.3/tests/__init__.py +0 -0
- deduplicate_lib-0.1.3/tests/conftest.py +75 -0
- deduplicate_lib-0.1.3/tests/integration/test_example_notebook.py +82 -0
- deduplicate_lib-0.1.3/tests/integration/test_tol_find_and_deduplicate.py +115 -0
- deduplicate_lib-0.1.3/tests/unit/core/.coverage +0 -0
- deduplicate_lib-0.1.3/tests/unit/core/__init__.py +0 -0
- deduplicate_lib-0.1.3/tests/unit/core/test_duplicate_detection_algorithm.py +396 -0
- deduplicate_lib-0.1.3/tests/unit/core/test_registry.py +50 -0
- deduplicate_lib-0.1.3/tests/unit/core/test_tolerance_calculator.py +151 -0
- deduplicate_lib-0.1.3/tests/unit/plugins/__init__.py +0 -0
- deduplicate_lib-0.1.3/tests/unit/plugins/duplicate_detection_algoirthms/__init__.py +0 -0
- deduplicate_lib-0.1.3/tests/unit/plugins/duplicate_detection_algoirthms/test_distance_matrix.py +179 -0
- deduplicate_lib-0.1.3/tests/unit/plugins/duplicate_detection_algoirthms/test_multi_hashing.py +331 -0
- deduplicate_lib-0.1.3/tests/unit/plugins/tolerance_calculators/__init__.py +0 -0
- deduplicate_lib-0.1.3/tests/unit/plugins/tolerance_calculators/plateau_detection.png +0 -0
- deduplicate_lib-0.1.3/tests/unit/plugins/tolerance_calculators/plateau_detection_DistanceMatrix.png +0 -0
- deduplicate_lib-0.1.3/tests/unit/plugins/tolerance_calculators/plateau_detection_MultiHashing.png +0 -0
- deduplicate_lib-0.1.3/tests/unit/plugins/tolerance_calculators/test_natural_tolerance_plateau_probe.py +215 -0
- deduplicate_lib-0.1.3/tests/unit/plugins/tolerance_calculators/test_perturbed_dataset_reclustering.py +149 -0
- deduplicate_lib-0.1.2/PKG-INFO +0 -165
- deduplicate_lib-0.1.2/pyproject.toml +0 -50
- deduplicate_lib-0.1.2/setup.cfg +0 -4
- deduplicate_lib-0.1.2/src/deduplicate_lib/__init__.py +0 -1
- deduplicate_lib-0.1.2/src/deduplicate_lib.egg-info/SOURCES.txt +0 -20
- deduplicate_lib-0.1.2/src/deduplicate_lib.egg-info/dependency_links.txt +0 -1
- deduplicate_lib-0.1.2/src/deduplicate_lib.egg-info/requires.txt +0 -19
- deduplicate_lib-0.1.2/src/deduplicate_lib.egg-info/top_level.txt +0 -1
- {deduplicate_lib-0.1.2 → deduplicate_lib-0.1.3}/LICENSE +0 -0
- {deduplicate_lib-0.1.2 → deduplicate_lib-0.1.3}/src/deduplicate_lib/core/__init__.py +0 -0
- {deduplicate_lib-0.1.2 → deduplicate_lib-0.1.3}/src/deduplicate_lib/plugins/__init__.py +0 -0
- {deduplicate_lib-0.1.2 → deduplicate_lib-0.1.3}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/__init__.py +0 -0
- {deduplicate_lib-0.1.2 → deduplicate_lib-0.1.3}/src/deduplicate_lib/plugins/tolerance_calculators/__init__.py +0 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.3] - 2026-10-12
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
- Packaging moved to uv + hatchling: dev/test dependencies are now PEP 735 dependency
|
|
9
|
+
groups (`uv sync` installs them) instead of the `dev` extra, `uv.lock` pins the
|
|
10
|
+
development environment, and CI installs with `uv sync --locked` and tests on
|
|
11
|
+
Python 3.10–3.12.
|
|
12
|
+
- Minimum Python version raised from 3.8 to 3.10 (current numba releases already
|
|
13
|
+
require it).
|
|
14
|
+
- The version now comes from git tags via hatch-vcs instead of a hand-edited
|
|
15
|
+
`__version__` (which had drifted: the `0.1.2` tag still said `0.1.1`).
|
|
16
|
+
`deduplicate_lib.__version__` still works. New tags use the `vMAJOR.MINOR.PATCH` form.
|
|
17
|
+
- Ruff now enforces the same rule set as ALomancy (isort, bugbear, pyupgrade,
|
|
18
|
+
comprehensions, unused arguments, simplify, ruff-specific). Code was updated to
|
|
19
|
+
match: sorted imports, builtin generics, `stacklevel=2` on all warnings, so they
|
|
20
|
+
point at the caller instead of inside the library.
|
|
21
|
+
- `DuplicateDetectionAlgorithm.pre_dda_processing()` (and the `MultiHashing`
|
|
22
|
+
override) no longer accept unused `*args, **kwargs`.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
- `DistanceMatrix.get_dataset_unique_structures()` now keeps exactly one vector from
|
|
26
|
+
each group of near-duplicates: in dataset order, a vector is unique unless it is within
|
|
27
|
+
`tolerance` of a vector already kept. Before, a vector counted as unique only if
|
|
28
|
+
nothing at all was within `tolerance` (row 0 excepted), so every group that didn't
|
|
29
|
+
contain row 0 was flagged in full and `deduplicate()` dropped it entirely. This matches
|
|
30
|
+
`MultiHashing`, which already keeps the first vector of each group.
|
|
31
|
+
|
|
32
|
+
### Behaviour change
|
|
33
|
+
- Unique counts from `DistanceMatrix` are higher wherever near-duplicate groups exist,
|
|
34
|
+
so the tolerances that `NaturalTolerancePlateauProbe` and
|
|
35
|
+
`PerturbedDatasetReclustering` find with it shift. In the integration tests,
|
|
36
|
+
0.168 → 0.181 (reclustering) and 0.141 → 0.153 (plateau probe). At the old values,
|
|
37
|
+
one point plus a 30-vector cluster deduplicated to the point alone; at the new
|
|
38
|
+
values, to the point plus one cluster member.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## [0.1.2] - 2026-09-23
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
- `NaturalTolerancePlateauProbe`: fixed selection of the minimum/maximum plateau.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## [0.1.1] - 2026-09-23
|
|
50
|
+
|
|
51
|
+
### Added
|
|
52
|
+
- `NaturalTolerancePlateauProbe` can select the minimum or maximum plateau.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## [0.1.0] - 2026-06-14
|
|
57
|
+
|
|
58
|
+
### Fixed
|
|
59
|
+
- `MultiHashing.duplicate_check()` / `get_uniqueness_score()` no longer return stale results
|
|
60
|
+
when `tolerance`, `seed`, or `perturbations` change after the hash dictionary was first
|
|
61
|
+
built — `pre_dda_processing()` now detects these changes and forces a rebuild.
|
|
62
|
+
- `DistanceMatrix.duplicate_check()` no longer triggers an unnecessary full O(N²)
|
|
63
|
+
distance-matrix rebuild (and large preallocation) on a clean dataset; it now only ensures
|
|
64
|
+
the dataset array is preinitialized.
|
|
65
|
+
- `set_dataset_array()` is now a no-op (no reallocation, no `_dirty` invalidation) when the
|
|
66
|
+
incoming array is identical to the data already loaded, avoiding redundant rebuilds when
|
|
67
|
+
tolerance calculators temporarily swap datasets and restore the original.
|
|
68
|
+
- Removed a redundant double-computation of the hash vector dictionary in
|
|
69
|
+
`MultiHashing.get_dataset_unique_structures()`.
|
|
70
|
+
- `DistanceMatrix._rebuild_auxiliary_structures()` no longer redundantly reinitializes the
|
|
71
|
+
distance matrix before recomputing it.
|
|
72
|
+
|
|
73
|
+
### Changed
|
|
74
|
+
- Dropped the unused `input_dataset_array` parameter from `pre_dda_processing()`.
|
|
75
|
+
- Extracted `MultiHashing._perturbation_array_stale()` to share the perturbation-array
|
|
76
|
+
staleness check between `pre_dda_processing()` and `_rebuild_auxiliary_structures()`.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## [0.0.5] - 2026-04-23
|
|
81
|
+
|
|
82
|
+
### Changed
|
|
83
|
+
- Reinstated dictionary-based storage in multi-hashing implementation (`b3f3fad`).
|
|
84
|
+
- Verified full test and coverage status for the dictionary reversion (`b3f3fad`).
|
|
85
|
+
- Finalized release/build readiness updates (`ff9ee21`, `02614ed`).
|
|
86
|
+
|
|
87
|
+
### Merged
|
|
88
|
+
- PR #9: Reinstate dictionaries for MH (`aa9aff4`).
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## [0.0.4] - 2026-04-22
|
|
93
|
+
|
|
94
|
+
### Added
|
|
95
|
+
- Pre-initialisation logic for dataset handling (`60736ff`).
|
|
96
|
+
|
|
97
|
+
### Changed
|
|
98
|
+
- Coverage/test completeness improvements (`74658d4`).
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## [0.0.3] - 2026-04-16
|
|
103
|
+
|
|
104
|
+
### Added
|
|
105
|
+
- Tight and loose options to PDR (`eca4ab0`).
|
|
106
|
+
- `get_uniqueness_score` support in multi-hash flow (`671ddac`).
|
|
107
|
+
|
|
108
|
+
### Changed
|
|
109
|
+
- Acceptance threshold moved to sigma-based threshold (`62d80e6`).
|
|
110
|
+
- Round-then-perturb bug fix and hash-array/input reset fixes (`671ddac`).
|
|
111
|
+
- Test updates and cleanup (`4d72241`, `47f1271`).
|
|
112
|
+
- Version update for v0.0.3 (`ab12fde`).
|
|
113
|
+
|
|
114
|
+
### Merged
|
|
115
|
+
- PR #5: Release v0.0.3 (`97d2102`).
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## [0.0.2] - 2026-03-30
|
|
120
|
+
|
|
121
|
+
### Added
|
|
122
|
+
- Example usage and deduplicate function introduced (`7ee94df`).
|
|
123
|
+
- Additional tests (`85e666a`).
|
|
124
|
+
- SciPy dependency (`9c1cfc4`).
|
|
125
|
+
|
|
126
|
+
### Changed
|
|
127
|
+
- Release prep for v0.0.2 (`2239439`).
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## [0.0.1] - 2026-03-26
|
|
132
|
+
|
|
133
|
+
### Added
|
|
134
|
+
- Initial CI and test setup (`b0b5477`, `bb03869`).
|
|
135
|
+
- Numba acceleration for DDAs (`cf10a8e`, `fa93d56`).
|
|
136
|
+
- Codecov integration and badge (`033d99f`, `e13a1ba`).
|
|
137
|
+
- License and core tolerance calculator tests (`3edf959`).
|
|
138
|
+
|
|
139
|
+
### Changed
|
|
140
|
+
- README and packaging updates (`851b609`, `8108a50`).
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## [0.0.0] - 2026-03-17
|
|
145
|
+
|
|
146
|
+
### Added
|
|
147
|
+
- Initial project commit (`03a02d8`).
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: deduplicate_lib
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Deduplication of numpy vector arrays, with automatic tolerance tuning.
|
|
5
|
+
Project-URL: Homepage, https://github.com/julianholland/deduplicate
|
|
6
|
+
Project-URL: Repository, https://github.com/julianholland/deduplicate
|
|
5
7
|
Author-email: Julian Holland <holland@fhi.mpg.de>
|
|
6
|
-
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
+
License: MIT
|
|
8
9
|
License-File: LICENSE
|
|
9
|
-
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering
|
|
18
|
+
Requires-Python: >=3.10
|
|
10
19
|
Requires-Dist: numba
|
|
20
|
+
Requires-Dist: numpy
|
|
11
21
|
Requires-Dist: scipy
|
|
12
|
-
Provides-Extra: dev
|
|
13
|
-
Requires-Dist: pytest; extra == "dev"
|
|
14
|
-
Requires-Dist: pytest-mock; extra == "dev"
|
|
15
|
-
Requires-Dist: coverage; extra == "dev"
|
|
16
|
-
Requires-Dist: ruff; extra == "dev"
|
|
17
|
-
Requires-Dist: nbconvert; extra == "dev"
|
|
18
|
-
Requires-Dist: nbclient; extra == "dev"
|
|
19
|
-
Requires-Dist: notebook; extra == "dev"
|
|
20
|
-
Requires-Dist: ipykernel; extra == "dev"
|
|
21
|
-
Requires-Dist: matplotlib; extra == "dev"
|
|
22
22
|
Provides-Extra: docs
|
|
23
|
-
Requires-Dist:
|
|
24
|
-
Requires-Dist:
|
|
25
|
-
Requires-Dist: sphinx
|
|
26
|
-
|
|
23
|
+
Requires-Dist: furo; extra == 'docs'
|
|
24
|
+
Requires-Dist: sphinx-autodoc-typehints; extra == 'docs'
|
|
25
|
+
Requires-Dist: sphinx>=7; extra == 'docs'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
27
|
|
|
28
28
|
<div align="center">
|
|
29
29
|
<h1><code>deduplicate_lib</code></h1>
|
|
@@ -34,7 +34,7 @@ Dynamic: license-file
|
|
|
34
34
|
[](https://github.com/julianholland/deduplicate)
|
|
35
35
|
[](https://codecov.io/gh/julianholland/deduplicate)
|
|
36
36
|
[](https://badge.fury.io/py/deduplicate_lib)
|
|
37
|
-
[](https://www.python.org/downloads/)
|
|
38
38
|
[](https://opensource.org/licenses/MIT)
|
|
39
39
|
[](https://github.com/julianholland/deduplicate/actions/workflows/ci.yml)
|
|
40
40
|
[](https://github.com/astral-sh/ruff)
|
|
@@ -80,7 +80,7 @@ See the **[full documentation](https://deduplicate-lib.readthedocs.io)** for API
|
|
|
80
80
|
|
|
81
81
|
### Dependencies
|
|
82
82
|
|
|
83
|
-
- Python 3.
|
|
83
|
+
- Python 3.10+
|
|
84
84
|
- `numpy`
|
|
85
85
|
- `numba`
|
|
86
86
|
- `scipy`
|
|
@@ -96,15 +96,15 @@ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) f
|
|
|
96
96
|
git clone https://github.com/julianholland/deduplicate.git
|
|
97
97
|
cd deduplicate
|
|
98
98
|
|
|
99
|
-
#
|
|
100
|
-
|
|
99
|
+
# Create a virtual environment with the package and dev dependencies (needs uv)
|
|
100
|
+
uv sync
|
|
101
101
|
|
|
102
102
|
# Run tests
|
|
103
|
-
pytest
|
|
103
|
+
uv run pytest
|
|
104
104
|
|
|
105
105
|
# Run linting
|
|
106
|
-
ruff check .
|
|
107
|
-
ruff format .
|
|
106
|
+
uv run ruff check .
|
|
107
|
+
uv run ruff format .
|
|
108
108
|
```
|
|
109
109
|
|
|
110
110
|
### Running Tests
|
|
@@ -162,4 +162,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
162
162
|
- [x] Speedup slow tasks with Numba
|
|
163
163
|
- [x] Set up Read the Docs
|
|
164
164
|
- [x] Create general deduplicate function
|
|
165
|
-
- [x] Speed up NTPP
|
|
165
|
+
- [x] Speed up NTPP
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://github.com/julianholland/deduplicate)
|
|
8
8
|
[](https://codecov.io/gh/julianholland/deduplicate)
|
|
9
9
|
[](https://badge.fury.io/py/deduplicate_lib)
|
|
10
|
-
[](https://www.python.org/downloads/)
|
|
11
11
|
[](https://opensource.org/licenses/MIT)
|
|
12
12
|
[](https://github.com/julianholland/deduplicate/actions/workflows/ci.yml)
|
|
13
13
|
[](https://github.com/astral-sh/ruff)
|
|
@@ -53,7 +53,7 @@ See the **[full documentation](https://deduplicate-lib.readthedocs.io)** for API
|
|
|
53
53
|
|
|
54
54
|
### Dependencies
|
|
55
55
|
|
|
56
|
-
- Python 3.
|
|
56
|
+
- Python 3.10+
|
|
57
57
|
- `numpy`
|
|
58
58
|
- `numba`
|
|
59
59
|
- `scipy`
|
|
@@ -69,15 +69,15 @@ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) f
|
|
|
69
69
|
git clone https://github.com/julianholland/deduplicate.git
|
|
70
70
|
cd deduplicate
|
|
71
71
|
|
|
72
|
-
#
|
|
73
|
-
|
|
72
|
+
# Create a virtual environment with the package and dev dependencies (needs uv)
|
|
73
|
+
uv sync
|
|
74
74
|
|
|
75
75
|
# Run tests
|
|
76
|
-
pytest
|
|
76
|
+
uv run pytest
|
|
77
77
|
|
|
78
78
|
# Run linting
|
|
79
|
-
ruff check .
|
|
80
|
-
ruff format .
|
|
79
|
+
uv run ruff check .
|
|
80
|
+
uv run ruff format .
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
### Running Tests
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Duplicate Detection Algorithms
|
|
2
|
+
==============================
|
|
3
|
+
|
|
4
|
+
Two algorithms are provided. Choose based on dataset size and whether exact
|
|
5
|
+
results are required.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
DistanceMatrix
|
|
9
|
+
--------------
|
|
10
|
+
|
|
11
|
+
Exact algorithm. Builds the full N×N pairwise distance matrix. Vectors are
|
|
12
|
+
taken in dataset order, and a vector is a duplicate only if it is within
|
|
13
|
+
``tolerance`` of a vector already kept, so each group of near-duplicates keeps
|
|
14
|
+
exactly one vector (its earliest). O(N²)
|
|
15
|
+
time and space; a good choice for datasets up to ~5 000 vectors. Supports all
|
|
16
|
+
four distance metrics: ``"euclidean"``, ``"manhattan"``, ``"cosine"``, and
|
|
17
|
+
``"hamming"``.
|
|
18
|
+
|
|
19
|
+
.. autoclass:: deduplicate_lib.plugins.duplicate_detection_algorithms.distance_matrix.DistanceMatrix
|
|
20
|
+
:members:
|
|
21
|
+
:show-inheritance:
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
MultiHashing
|
|
25
|
+
------------
|
|
26
|
+
|
|
27
|
+
Approximate algorithm. O(N · perturbations) time; scales well to large
|
|
28
|
+
datasets. Restricted to ``"hamming"`` distance. Accuracy is controlled by
|
|
29
|
+
``perturbations`` (more is better) and ``sigma_accepatnce_threshold`` (higher
|
|
30
|
+
reduces false positives but requires more perturbations to be reliable).
|
|
31
|
+
|
|
32
|
+
.. autoclass:: deduplicate_lib.plugins.duplicate_detection_algorithms.multi_hashing.MultiHashing
|
|
33
|
+
:members:
|
|
34
|
+
:show-inheritance:
|
|
35
|
+
|
|
36
|
+
.. note::
|
|
37
|
+
|
|
38
|
+
``sigma_accepatnce_threshold`` selects the acceptance band used to declare
|
|
39
|
+
a hash-collision a duplicate:
|
|
40
|
+
|
|
41
|
+
============================== ================
|
|
42
|
+
``sigma_accepatnce_threshold`` Acceptance band
|
|
43
|
+
============================== ================
|
|
44
|
+
1 (default) 68.3%
|
|
45
|
+
2 95.4%
|
|
46
|
+
3 99.7%
|
|
47
|
+
4 99.99%
|
|
48
|
+
============================== ================
|
|
49
|
+
|
|
50
|
+
Higher values reduce false positives but require more perturbations to be
|
|
51
|
+
statistically reliable.
|
|
@@ -0,0 +1,12 @@
|
|
|
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, get_dataset_unique_structures
|
|
12
|
+
:show-inheritance:
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
|
|
8
|
+
|
|
9
|
+
PerturbedDatasetReclustering
|
|
10
|
+
-----------------------------
|
|
11
|
+
|
|
12
|
+
Perturbs each original vector ``perturbations_per_vector`` times with Gaussian
|
|
13
|
+
noise of scale ``perturbation_scale``, then binary-searches for the tolerance
|
|
14
|
+
that recovers the original unique-vector count in the perturbed dataset.
|
|
15
|
+
``"average"`` mode averages the loose and tight bounds; ``"loose"`` returns the
|
|
16
|
+
highest valid tolerance; ``"tight"`` returns the lowest.
|
|
17
|
+
|
|
18
|
+
.. autoclass:: deduplicate_lib.plugins.tolerance_calculators.perturbed_dataset_reclustering.PerturbedDatasetReclustering
|
|
19
|
+
:members: calculate_tolerance
|
|
20
|
+
:show-inheritance:
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
NaturalTolerancePlateauProbe
|
|
24
|
+
-----------------------------
|
|
25
|
+
|
|
26
|
+
No perturbed data needed. Sweeps from the all-same tolerance bound to the
|
|
27
|
+
all-different bound, records the unique-structure count at each step, and picks
|
|
28
|
+
the midpoint of the longest plateau — a region where the clustering is stable
|
|
29
|
+
and insensitive to small changes in tolerance.
|
|
30
|
+
|
|
31
|
+
.. autoclass:: deduplicate_lib.plugins.tolerance_calculators.natural_tolerance_plateau_probe.NaturalTolerancePlateauProbe
|
|
32
|
+
:members: calculate_tolerance
|
|
33
|
+
:show-inheritance:
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
sys.path.insert(0, os.path.abspath("../src"))
|
|
5
|
+
|
|
6
|
+
project = "deduplicate_lib"
|
|
7
|
+
copyright = "2026, Julian Holland"
|
|
8
|
+
author = "Julian Holland"
|
|
9
|
+
release = "0.1.0"
|
|
10
|
+
|
|
11
|
+
extensions = [
|
|
12
|
+
"sphinx.ext.autodoc",
|
|
13
|
+
"sphinx.ext.napoleon",
|
|
14
|
+
"sphinx_autodoc_typehints",
|
|
15
|
+
"sphinx.ext.viewcode",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
html_theme = "furo"
|
|
19
|
+
autodoc_member_order = "bysource"
|
|
20
|
+
napoleon_numpy_docstring = True
|
|
21
|
+
napoleon_google_docstring = False
|
|
22
|
+
autodoc_typehints = "description"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
deduplicate_lib
|
|
2
|
+
===============
|
|
3
|
+
|
|
4
|
+
``deduplicate_lib`` is a Python library for finding and removing duplicate
|
|
5
|
+
numpy vectors in a dataset. It provides exact and approximate deduplication
|
|
6
|
+
algorithms, along with tools for automatically selecting the distance threshold
|
|
7
|
+
(``tolerance``) that determines when two vectors are considered duplicates.
|
|
8
|
+
|
|
9
|
+
.. toctree::
|
|
10
|
+
:maxdepth: 2
|
|
11
|
+
:caption: Contents
|
|
12
|
+
|
|
13
|
+
quickstart
|
|
14
|
+
api/index
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
Quick Start
|
|
2
|
+
===========
|
|
3
|
+
|
|
4
|
+
Batch deduplication
|
|
5
|
+
-------------------
|
|
6
|
+
|
|
7
|
+
Use :class:`~deduplicate_lib.plugins.duplicate_detection_algorithms.distance_matrix.DistanceMatrix`
|
|
8
|
+
to load a dataset and return only the unique vectors in a single call.
|
|
9
|
+
|
|
10
|
+
.. code-block:: python
|
|
11
|
+
|
|
12
|
+
from deduplicate_lib.plugins.duplicate_detection_algorithms.distance_matrix import DistanceMatrix
|
|
13
|
+
import numpy as np
|
|
14
|
+
|
|
15
|
+
dataset = np.array([[1.0, 2.0], [1.01, 2.01], [5.0, 6.0]])
|
|
16
|
+
dda = DistanceMatrix(tolerance=0.1, dataset_array=dataset)
|
|
17
|
+
unique = dda.deduplicate()
|
|
18
|
+
print(unique)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
Single-vector duplicate check
|
|
22
|
+
------------------------------
|
|
23
|
+
|
|
24
|
+
``duplicate_check()`` is fast — it computes distances only for ``input_vector``
|
|
25
|
+
rather than rebuilding the full matrix.
|
|
26
|
+
|
|
27
|
+
.. code-block:: python
|
|
28
|
+
|
|
29
|
+
dda.input_vector = np.array([1.0, 2.0])
|
|
30
|
+
is_duplicate = dda.duplicate_check()
|
|
31
|
+
print(is_duplicate) # True — matches first row within tolerance 0.1
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Streaming / incremental ingestion
|
|
35
|
+
----------------------------------
|
|
36
|
+
|
|
37
|
+
``add_input_vector_to_dda()`` appends ``input_vector`` to the dataset and
|
|
38
|
+
incrementally updates auxiliary structures, avoiding a full rebuild on every
|
|
39
|
+
insertion.
|
|
40
|
+
|
|
41
|
+
.. code-block:: python
|
|
42
|
+
|
|
43
|
+
from deduplicate_lib.plugins.duplicate_detection_algorithms.multi_hashing import MultiHashing
|
|
44
|
+
|
|
45
|
+
dda = MultiHashing(tolerance=0.1, perturbations=200)
|
|
46
|
+
for vec in incoming_vectors:
|
|
47
|
+
dda.input_vector = vec
|
|
48
|
+
if not dda.duplicate_check():
|
|
49
|
+
dda.add_input_vector_to_dda()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
Automatic tolerance tuning
|
|
53
|
+
---------------------------
|
|
54
|
+
|
|
55
|
+
When you do not know a good ``tolerance`` value, use a
|
|
56
|
+
:class:`~deduplicate_lib.plugins.tolerance_calculators.perturbed_dataset_reclustering.PerturbedDatasetReclustering`
|
|
57
|
+
to find one automatically, then assign it back to the DDA.
|
|
58
|
+
|
|
59
|
+
.. code-block:: python
|
|
60
|
+
|
|
61
|
+
from deduplicate_lib.plugins.tolerance_calculators.perturbed_dataset_reclustering import PerturbedDatasetReclustering
|
|
62
|
+
|
|
63
|
+
dda = DistanceMatrix(dataset_array=dataset)
|
|
64
|
+
tc = PerturbedDatasetReclustering(
|
|
65
|
+
duplicate_detection_algorithm_object=dda,
|
|
66
|
+
perturbations_per_vector=3,
|
|
67
|
+
perturbation_scale=0.05,
|
|
68
|
+
)
|
|
69
|
+
tc.create_perturbed_dataset()
|
|
70
|
+
dda.tolerance = tc.calculate_tolerance()
|
|
71
|
+
unique = dda.deduplicate()
|