deduplicate-lib 0.0.1__tar.gz → 0.0.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.
- deduplicate_lib-0.0.2/PKG-INFO +151 -0
- deduplicate_lib-0.0.2/README.md +133 -0
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/pyproject.toml +2 -0
- deduplicate_lib-0.0.2/src/deduplicate_lib/__init__.py +1 -0
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib/core/duplicate_detection_algorithm.py +73 -17
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib/core/tolerance_calculator.py +9 -11
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/distance_matrix.py +16 -9
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/multi_hashing.py +27 -12
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib/plugins/tolerance_calculators/natural_tolerance_plateau_probe.py +46 -10
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib/plugins/tolerance_calculators/perturbed_dataset_reclustering.py +22 -2
- deduplicate_lib-0.0.2/src/deduplicate_lib.egg-info/PKG-INFO +151 -0
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib.egg-info/requires.txt +2 -0
- deduplicate_lib-0.0.1/PKG-INFO +0 -59
- deduplicate_lib-0.0.1/README.md +0 -43
- deduplicate_lib-0.0.1/src/deduplicate_lib/__init__.py +0 -1
- deduplicate_lib-0.0.1/src/deduplicate_lib.egg-info/PKG-INFO +0 -59
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/LICENSE +0 -0
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/setup.cfg +0 -0
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib/core/__init__.py +0 -0
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib/core/plugin_registry.py +0 -0
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib/plugins/__init__.py +0 -0
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/__init__.py +0 -0
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib/plugins/tolerance_calculators/__init__.py +0 -0
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib.egg-info/SOURCES.txt +0 -0
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib.egg-info/dependency_links.txt +0 -0
- {deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: deduplicate_lib
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: A Python package for deduplicating data.
|
|
5
|
+
Author-email: Julian Holland <holland@fhi.mpg.de>
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: numpy
|
|
10
|
+
Requires-Dist: numba
|
|
11
|
+
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
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
<h1><code>deduplicate_lib</code></h1>
|
|
21
|
+
<p><i>deduplication algorithms in python</i></p>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
***
|
|
25
|
+
[](https://github.com/julianholland/deduplicate)
|
|
26
|
+
[](https://codecov.io/gh/julianholland/deduplicate)
|
|
27
|
+
[](https://badge.fury.io/py/deduplicate_lib)
|
|
28
|
+
[](https://www.python.org/downloads/)
|
|
29
|
+
[](https://opensource.org/licenses/MIT)
|
|
30
|
+
[](https://github.com/julianholland/deduplicate/actions/workflows/ci.yml)
|
|
31
|
+
[](https://github.com/astral-sh/ruff)
|
|
32
|
+
<!-- [](https://alomancy.readthedocs.io/en/latest/index.html) -->
|
|
33
|
+
|
|
34
|
+
## Key Features
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
- Easy to use deduplication algorithms for any vector array
|
|
38
|
+
- Suite of tolerance tuning algorithms to help you find the right tolerance value for your system
|
|
39
|
+
- Suite of benchmarking tools to ensure rigor, accuracy, and speed (not yet implemented)
|
|
40
|
+
- Factory Plugin architecture, for easy extensibility and modification
|
|
41
|
+
|
|
42
|
+
***
|
|
43
|
+
## Implemented Algorithms
|
|
44
|
+
|
|
45
|
+
- Distance Matrix (Simple, accurate, expensive): Computes the distance matrix for all vectors and determines duplicates by finding those that fall below a given distance
|
|
46
|
+
- Multi Hashing (Fast): Smears and rounds the vectors using a normal distribution and computes the hashes for each which are then used to determine duplicates by proportion of hash clashes.
|
|
47
|
+
<!-- - Locality Sensitive Hashing (Fast, Accurate) -->
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
install using pip
|
|
51
|
+
```bash
|
|
52
|
+
pip install deduplicate_lib
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
load your data into python
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from deduplicate_lib.plugins.deduplication_algorithms.multi_hash import MultiHash
|
|
59
|
+
|
|
60
|
+
# define your paramerters in the MultiHash object
|
|
61
|
+
dda=MultiHash(
|
|
62
|
+
tolerance=0.01,
|
|
63
|
+
dataset_array: your_data_array,
|
|
64
|
+
perturbations: int = 200,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
print(dda.get_dataset_unique_structures())
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
A more detailed example can be seen in the `examples` directory
|
|
71
|
+
|
|
72
|
+
### Dependencies
|
|
73
|
+
|
|
74
|
+
- Python 3.9+
|
|
75
|
+
- `numpy`
|
|
76
|
+
- `numba`
|
|
77
|
+
|
|
78
|
+
## 🤝 Contributing
|
|
79
|
+
|
|
80
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
81
|
+
|
|
82
|
+
### Development Setup
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Clone the repository
|
|
86
|
+
git clone https://github.com/julianholland/deduplicate.git
|
|
87
|
+
cd deduplicate
|
|
88
|
+
|
|
89
|
+
# Install in development mode
|
|
90
|
+
pip install -e ".[dev]"
|
|
91
|
+
|
|
92
|
+
# Run tests
|
|
93
|
+
pytest
|
|
94
|
+
|
|
95
|
+
# Run linting
|
|
96
|
+
ruff check .
|
|
97
|
+
ruff format .
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Running Tests
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# Run all tests
|
|
104
|
+
pytest
|
|
105
|
+
|
|
106
|
+
# Run specific test categories
|
|
107
|
+
pytest tests/core/
|
|
108
|
+
pytest tests/plugins/
|
|
109
|
+
pytest tests/plugins/duplicate_detection_algorithms/distance_matrix
|
|
110
|
+
|
|
111
|
+
# Run with coverage
|
|
112
|
+
pytest --cov
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## 📝 Citation
|
|
116
|
+
|
|
117
|
+
If you use deduplicate_lib in your research, please cite:
|
|
118
|
+
|
|
119
|
+
```bibtex
|
|
120
|
+
@software{alomancy2025,
|
|
121
|
+
title={Deduplicate_lib: Auto Tolerance Finding Deduplication Algorithms in Python},
|
|
122
|
+
author={Julian Holland},
|
|
123
|
+
year={2026},
|
|
124
|
+
url={https://github.com/julianholland/deduplicate},
|
|
125
|
+
version={0.0.1dev}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## 📄 License
|
|
130
|
+
|
|
131
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
132
|
+
|
|
133
|
+
## 🙏 Acknowledgments
|
|
134
|
+
|
|
135
|
+
- The Fritz Haber Institute
|
|
136
|
+
- Juan Manuel Lombardi <3
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
## Project Links
|
|
140
|
+
|
|
141
|
+
- [GitHub Repository](https://github.com/julianholland/deduplicate)
|
|
142
|
+
|
|
143
|
+
## Project To-Do
|
|
144
|
+
|
|
145
|
+
- [x] Add example.ipynb
|
|
146
|
+
- [ ] Create general Pre-allocation protocal
|
|
147
|
+
- [ ] Add benchmarks for time and robustness
|
|
148
|
+
- [ ] Add Locality-Sensitive Hashing as an option
|
|
149
|
+
- [x] Speedup slow tasks with Numba
|
|
150
|
+
- [ ] Set up Read the Docs
|
|
151
|
+
- [x] Create general deduplicate function
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1><code>deduplicate_lib</code></h1>
|
|
3
|
+
<p><i>deduplication algorithms in python</i></p>
|
|
4
|
+
</div>
|
|
5
|
+
|
|
6
|
+
***
|
|
7
|
+
[](https://github.com/julianholland/deduplicate)
|
|
8
|
+
[](https://codecov.io/gh/julianholland/deduplicate)
|
|
9
|
+
[](https://badge.fury.io/py/deduplicate_lib)
|
|
10
|
+
[](https://www.python.org/downloads/)
|
|
11
|
+
[](https://opensource.org/licenses/MIT)
|
|
12
|
+
[](https://github.com/julianholland/deduplicate/actions/workflows/ci.yml)
|
|
13
|
+
[](https://github.com/astral-sh/ruff)
|
|
14
|
+
<!-- [](https://alomancy.readthedocs.io/en/latest/index.html) -->
|
|
15
|
+
|
|
16
|
+
## Key Features
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
- Easy to use deduplication algorithms for any vector array
|
|
20
|
+
- Suite of tolerance tuning algorithms to help you find the right tolerance value for your system
|
|
21
|
+
- Suite of benchmarking tools to ensure rigor, accuracy, and speed (not yet implemented)
|
|
22
|
+
- Factory Plugin architecture, for easy extensibility and modification
|
|
23
|
+
|
|
24
|
+
***
|
|
25
|
+
## Implemented Algorithms
|
|
26
|
+
|
|
27
|
+
- Distance Matrix (Simple, accurate, expensive): Computes the distance matrix for all vectors and determines duplicates by finding those that fall below a given distance
|
|
28
|
+
- Multi Hashing (Fast): Smears and rounds the vectors using a normal distribution and computes the hashes for each which are then used to determine duplicates by proportion of hash clashes.
|
|
29
|
+
<!-- - Locality Sensitive Hashing (Fast, Accurate) -->
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
install using pip
|
|
33
|
+
```bash
|
|
34
|
+
pip install deduplicate_lib
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
load your data into python
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from deduplicate_lib.plugins.deduplication_algorithms.multi_hash import MultiHash
|
|
41
|
+
|
|
42
|
+
# define your paramerters in the MultiHash object
|
|
43
|
+
dda=MultiHash(
|
|
44
|
+
tolerance=0.01,
|
|
45
|
+
dataset_array: your_data_array,
|
|
46
|
+
perturbations: int = 200,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
print(dda.get_dataset_unique_structures())
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
A more detailed example can be seen in the `examples` directory
|
|
53
|
+
|
|
54
|
+
### Dependencies
|
|
55
|
+
|
|
56
|
+
- Python 3.9+
|
|
57
|
+
- `numpy`
|
|
58
|
+
- `numba`
|
|
59
|
+
|
|
60
|
+
## 🤝 Contributing
|
|
61
|
+
|
|
62
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
63
|
+
|
|
64
|
+
### Development Setup
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Clone the repository
|
|
68
|
+
git clone https://github.com/julianholland/deduplicate.git
|
|
69
|
+
cd deduplicate
|
|
70
|
+
|
|
71
|
+
# Install in development mode
|
|
72
|
+
pip install -e ".[dev]"
|
|
73
|
+
|
|
74
|
+
# Run tests
|
|
75
|
+
pytest
|
|
76
|
+
|
|
77
|
+
# Run linting
|
|
78
|
+
ruff check .
|
|
79
|
+
ruff format .
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Running Tests
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Run all tests
|
|
86
|
+
pytest
|
|
87
|
+
|
|
88
|
+
# Run specific test categories
|
|
89
|
+
pytest tests/core/
|
|
90
|
+
pytest tests/plugins/
|
|
91
|
+
pytest tests/plugins/duplicate_detection_algorithms/distance_matrix
|
|
92
|
+
|
|
93
|
+
# Run with coverage
|
|
94
|
+
pytest --cov
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 📝 Citation
|
|
98
|
+
|
|
99
|
+
If you use deduplicate_lib in your research, please cite:
|
|
100
|
+
|
|
101
|
+
```bibtex
|
|
102
|
+
@software{alomancy2025,
|
|
103
|
+
title={Deduplicate_lib: Auto Tolerance Finding Deduplication Algorithms in Python},
|
|
104
|
+
author={Julian Holland},
|
|
105
|
+
year={2026},
|
|
106
|
+
url={https://github.com/julianholland/deduplicate},
|
|
107
|
+
version={0.0.1dev}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## 📄 License
|
|
112
|
+
|
|
113
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
114
|
+
|
|
115
|
+
## 🙏 Acknowledgments
|
|
116
|
+
|
|
117
|
+
- The Fritz Haber Institute
|
|
118
|
+
- Juan Manuel Lombardi <3
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Project Links
|
|
122
|
+
|
|
123
|
+
- [GitHub Repository](https://github.com/julianholland/deduplicate)
|
|
124
|
+
|
|
125
|
+
## Project To-Do
|
|
126
|
+
|
|
127
|
+
- [x] Add example.ipynb
|
|
128
|
+
- [ ] Create general Pre-allocation protocal
|
|
129
|
+
- [ ] Add benchmarks for time and robustness
|
|
130
|
+
- [ ] Add Locality-Sensitive Hashing as an option
|
|
131
|
+
- [x] Speedup slow tasks with Numba
|
|
132
|
+
- [ ] Set up Read the Docs
|
|
133
|
+
- [x] Create general deduplicate function
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.2"
|
|
@@ -1,26 +1,68 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
from abc import ABC, abstractmethod
|
|
3
|
+
from numba import njit
|
|
3
4
|
|
|
5
|
+
|
|
6
|
+
@njit
|
|
7
|
+
def fast_compute_distance_matrix(vector_array, distance_func):
|
|
8
|
+
num_samples = vector_array.shape[0]
|
|
9
|
+
distance_matrix = np.zeros((num_samples, num_samples))
|
|
10
|
+
for i in range(num_samples):
|
|
11
|
+
for j in range(i + 1, num_samples):
|
|
12
|
+
distance = distance_func(vector_array[i], vector_array[j])
|
|
13
|
+
distance_matrix[i, j] = distance
|
|
14
|
+
distance_matrix[j, i] = distance
|
|
15
|
+
return distance_matrix
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@njit
|
|
19
|
+
def fast_get_new_distance_matrix_column(
|
|
20
|
+
input_vector: np.ndarray, vector_array: np.ndarray, distance_func
|
|
21
|
+
) -> np.ndarray:
|
|
22
|
+
"""Calculates the distance matrix for the distances of a new input vector.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
np.ndarray: A 1D array containing the distances from the input vector to each vector in the dataset.
|
|
26
|
+
"""
|
|
27
|
+
num_samples = vector_array.shape[0]
|
|
28
|
+
new_distances = np.zeros(num_samples)
|
|
29
|
+
for i in range(num_samples):
|
|
30
|
+
new_distances[i] = distance_func(input_vector, vector_array[i])
|
|
31
|
+
return new_distances
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# must be jit compatible functions, so defined outside of the class and not as static methods
|
|
35
|
+
@njit
|
|
4
36
|
def euclidean_distance(v1, v2):
|
|
5
37
|
return float(np.linalg.norm(v1 - v2))
|
|
6
38
|
|
|
39
|
+
|
|
40
|
+
@njit
|
|
7
41
|
def manhattan_distance(v1, v2):
|
|
8
42
|
return np.sum(np.abs(v1 - v2))
|
|
9
43
|
|
|
44
|
+
|
|
45
|
+
@njit
|
|
10
46
|
def cosine_distance(v1, v2):
|
|
11
47
|
return 1 - np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2))
|
|
12
48
|
|
|
49
|
+
|
|
50
|
+
@njit
|
|
13
51
|
def hamming_distance(v1, v2):
|
|
14
52
|
return np.sum(v1 != v2)
|
|
15
53
|
|
|
54
|
+
|
|
16
55
|
DISTANCE_FUNCTIONS = {
|
|
17
56
|
"euclidean": euclidean_distance,
|
|
18
57
|
"manhattan": manhattan_distance,
|
|
19
58
|
"cosine": cosine_distance,
|
|
20
59
|
"hamming": hamming_distance,
|
|
21
60
|
}
|
|
61
|
+
|
|
62
|
+
|
|
22
63
|
class DuplicateDetectionAlgorithm(ABC):
|
|
23
64
|
ALLOWED_DISTANCES = DISTANCE_FUNCTIONS
|
|
65
|
+
|
|
24
66
|
def __init__(
|
|
25
67
|
self,
|
|
26
68
|
tolerance: float,
|
|
@@ -28,12 +70,14 @@ class DuplicateDetectionAlgorithm(ABC):
|
|
|
28
70
|
dataset_array: np.ndarray = np.array([]),
|
|
29
71
|
distance_matrix: np.ndarray = np.array([]),
|
|
30
72
|
distance_metric: str = "euclidean",
|
|
73
|
+
unique_vector_indices: np.array = np.array([]),
|
|
31
74
|
) -> None:
|
|
32
75
|
self.tolerance = tolerance
|
|
33
76
|
self.input_vector = input_vector
|
|
34
77
|
self.dataset_array = dataset_array
|
|
35
78
|
self.distance_matrix = distance_matrix
|
|
36
79
|
self.distance_metric = distance_metric
|
|
80
|
+
self.unique_vector_indices = unique_vector_indices
|
|
37
81
|
|
|
38
82
|
# In DuplicateDetectionAlgorithm
|
|
39
83
|
|
|
@@ -50,21 +94,15 @@ class DuplicateDetectionAlgorithm(ABC):
|
|
|
50
94
|
)
|
|
51
95
|
self._distance_metric = value
|
|
52
96
|
self.distance_function = self.ALLOWED_DISTANCES[value]
|
|
53
|
-
|
|
97
|
+
|
|
54
98
|
def calculate_distance(self, vector1: np.ndarray, vector2: np.ndarray) -> float:
|
|
55
99
|
return self.distance_function(vector1, vector2)
|
|
56
100
|
|
|
57
101
|
def compute_distance_matrix(self, vector_array: np.ndarray) -> None:
|
|
58
102
|
"""Compute the distance matrix for the dataset from scratch."""
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
for j in range(i + 1, num_samples):
|
|
63
|
-
distance = self.calculate_distance(
|
|
64
|
-
vector_array[i], vector_array[j]
|
|
65
|
-
)
|
|
66
|
-
self.distance_matrix[i, j] = distance
|
|
67
|
-
self.distance_matrix[j, i] = distance
|
|
103
|
+
self.distance_matrix = fast_compute_distance_matrix(
|
|
104
|
+
vector_array, self.distance_function
|
|
105
|
+
)
|
|
68
106
|
|
|
69
107
|
def get_new_distance_matrix_column(self, vector_array: np.ndarray) -> np.ndarray:
|
|
70
108
|
"""Calculates the distance matrix for the distances of a new input vector.
|
|
@@ -72,13 +110,9 @@ class DuplicateDetectionAlgorithm(ABC):
|
|
|
72
110
|
Returns:
|
|
73
111
|
np.ndarray: A 1D array containing the distances from the input vector to each vector in the dataset.
|
|
74
112
|
"""
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
new_distances[i] = self.calculate_distance(
|
|
79
|
-
self.input_vector, vector_array[i]
|
|
80
|
-
)
|
|
81
|
-
return new_distances
|
|
113
|
+
return fast_get_new_distance_matrix_column(
|
|
114
|
+
self.input_vector, vector_array, self.distance_function
|
|
115
|
+
)
|
|
82
116
|
|
|
83
117
|
def add_new_vector_to_distance_matrix(self, vector_array: np.ndarray) -> None:
|
|
84
118
|
"""Add a new input vector to the distance matrix."""
|
|
@@ -89,6 +123,28 @@ class DuplicateDetectionAlgorithm(ABC):
|
|
|
89
123
|
new_row = np.append(new_distances, 0) # Distance to itself is 0
|
|
90
124
|
self.distance_matrix = np.vstack((self.distance_matrix, new_row))
|
|
91
125
|
|
|
126
|
+
def pre_dda_processing(
|
|
127
|
+
self, input_dataset_array: np.ndarray | None = None, *args, **kwargs
|
|
128
|
+
) -> None:
|
|
129
|
+
"""A method that can be overridden by child classes to perform any necessary processing before duplication checks. For example, this could be used to compute the distance matrix for the dataset before any duplication checks are performed, which would save time if multiple duplication checks are being performed on the same dataset with different input vectors."""
|
|
130
|
+
pass
|
|
131
|
+
|
|
132
|
+
def add_input_vector_to_dda(self) -> None:
|
|
133
|
+
"""Add the input vector to the dataset array and update the distance matrix accordingly."""
|
|
134
|
+
pass
|
|
135
|
+
|
|
136
|
+
def get_unique_vector_indices(self) -> np.ndarray:
|
|
137
|
+
"""Returns the indices of the unique vectors in the dataset."""
|
|
138
|
+
if self.unique_vector_indices.shape[0] != self.dataset_array.shape[0]:
|
|
139
|
+
raise ValueError(
|
|
140
|
+
"Unique vector indices array shape does not match dataset; please run get_dataset_unique_structures() to update the unique vector indices before calling this method."
|
|
141
|
+
)
|
|
142
|
+
return np.where(self.unique_vector_indices)[0]
|
|
143
|
+
|
|
144
|
+
def deduplicate(self):
|
|
145
|
+
"""Finds all unique vectors in the dataset and returns them as a new array."""
|
|
146
|
+
return self.dataset_array[self.get_unique_vector_indices()]
|
|
147
|
+
|
|
92
148
|
@abstractmethod
|
|
93
149
|
def duplicate_check(self) -> bool:
|
|
94
150
|
pass
|
{deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib/core/tolerance_calculator.py
RENAMED
|
@@ -42,17 +42,15 @@ class ToleranceCalculator(ABC):
|
|
|
42
42
|
ptp=np.ptp(self.tolerance_dataset_array)
|
|
43
43
|
abs_std=np.mean(np.std(self.tolerance_dataset_array, axis=0))
|
|
44
44
|
best_max = (ptp + abs_std) * self.duplicate_detection_algorithm_object.dataset_array.shape[1]
|
|
45
|
-
tolerance = best_max
|
|
45
|
+
tolerance = best_max
|
|
46
46
|
|
|
47
47
|
exact_list = []
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
results_dict = {}
|
|
50
49
|
if self.binary_search_steps <= 0:
|
|
51
50
|
warnings.warn(f"Binary search called with {self.binary_search_steps} steps. No binary search performed.\n Returning tolerance of half the range of the perturbed dataset: {tolerance}.")
|
|
52
51
|
return tolerance
|
|
53
52
|
|
|
54
53
|
# temporarily set the dataset_array to the tolerance_dataset_array for the duration of the search
|
|
55
|
-
print(self.duplicate_detection_algorithm_object.distance_matrix.shape)
|
|
56
54
|
with self.temp_attr(
|
|
57
55
|
self.duplicate_detection_algorithm_object,
|
|
58
56
|
"dataset_array",
|
|
@@ -65,7 +63,7 @@ class ToleranceCalculator(ABC):
|
|
|
65
63
|
):
|
|
66
64
|
|
|
67
65
|
unique_vectors = self.duplicate_detection_algorithm_object.get_dataset_unique_structures()
|
|
68
|
-
|
|
66
|
+
results_dict[tolerance] = unique_vectors
|
|
69
67
|
if unique_vectors < target_unique_vectors: # loosen tolerance
|
|
70
68
|
best_max = tolerance
|
|
71
69
|
elif unique_vectors > target_unique_vectors: # tighten tolerance
|
|
@@ -92,14 +90,14 @@ class ToleranceCalculator(ABC):
|
|
|
92
90
|
else:
|
|
93
91
|
tolerance = min(exact_list)
|
|
94
92
|
else:
|
|
95
|
-
|
|
93
|
+
closest_tol = min(results_dict.keys(), key=lambda tol: abs(results_dict[tol] - target_unique_vectors))
|
|
94
|
+
min_diff = results_dict[closest_tol] - target_unique_vectors
|
|
96
95
|
tolerance = [
|
|
97
96
|
tol
|
|
98
|
-
for tol,
|
|
99
|
-
if
|
|
97
|
+
for tol, unique_vectors in results_dict.items()
|
|
98
|
+
if unique_vectors == target_unique_vectors + min_diff
|
|
100
99
|
][0]
|
|
101
|
-
warnings.warn(f"No exact tolerance found for target of {target_unique_vectors} unique vectors during binary search.\n Returning closest tolerance found: {tolerance} with {
|
|
102
|
-
print(all_diff_dict)
|
|
100
|
+
warnings.warn(f"No exact tolerance found for target of {target_unique_vectors} unique vectors during binary search.\n Returning closest tolerance found: {tolerance} with {results_dict[tolerance]} unique vectors.")
|
|
103
101
|
return tolerance
|
|
104
102
|
|
|
105
103
|
def create_perturbed_dataset(self, seed: int = 803):
|
|
@@ -132,7 +130,7 @@ class ToleranceCalculator(ABC):
|
|
|
132
130
|
if (
|
|
133
131
|
self.tolerance_dataset_array.shape[0]
|
|
134
132
|
!= len(self.duplicate_detection_algorithm_object.dataset_array)
|
|
135
|
-
* self.perturbations_per_vector
|
|
133
|
+
* self.perturbations_per_vector and self.perturbations_per_vector > 1
|
|
136
134
|
):
|
|
137
135
|
warnings.warn(
|
|
138
136
|
"Perturbed dataset is not properly initialized. Recreating it.\nEnsure a perturbed dataset is set prior finding tolerance."
|
|
@@ -7,14 +7,15 @@ import numpy as np
|
|
|
7
7
|
class DistanceMatrix(DuplicateDetectionAlgorithm):
|
|
8
8
|
def __init__(
|
|
9
9
|
self,
|
|
10
|
-
tolerance: float,
|
|
11
|
-
input_vector: np.ndarray,
|
|
12
|
-
dataset_array: np.ndarray,
|
|
10
|
+
tolerance: float = 0.1,
|
|
11
|
+
input_vector: np.ndarray = np.array([]),
|
|
12
|
+
dataset_array: np.ndarray = np.array([]),
|
|
13
13
|
distance_matrix: np.ndarray = np.array([]),
|
|
14
14
|
distance_metric: str = "euclidean",
|
|
15
|
+
unique_vector_indices: np.ndarray = np.array([]),
|
|
15
16
|
) -> None:
|
|
16
17
|
super().__init__(
|
|
17
|
-
tolerance, input_vector, dataset_array, distance_matrix, distance_metric
|
|
18
|
+
tolerance, input_vector, dataset_array, distance_matrix, distance_metric, unique_vector_indices
|
|
18
19
|
)
|
|
19
20
|
|
|
20
21
|
def __str__(self) -> str:
|
|
@@ -36,15 +37,21 @@ class DistanceMatrix(DuplicateDetectionAlgorithm):
|
|
|
36
37
|
|
|
37
38
|
def get_dataset_unique_structures(self) -> int:
|
|
38
39
|
self._ensure_distance_matrix()
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
self.unique_vector_indices = np.zeros(self.dataset_array.shape[0], dtype=bool)
|
|
41
|
+
self.unique_vector_indices[0] = True # the first vector is always unique
|
|
41
42
|
for i in range(1, self.distance_matrix.shape[0]):
|
|
42
43
|
imask = np.arange(self.distance_matrix.shape[0]) != i
|
|
43
44
|
if np.all(self.distance_matrix[i][imask] >= self.tolerance):
|
|
44
|
-
|
|
45
|
-
return
|
|
45
|
+
self.unique_vector_indices[i] = True
|
|
46
|
+
return np.sum(self.unique_vector_indices)
|
|
46
47
|
|
|
47
48
|
def pre_dda_processing(self, input_dataset_array: np.ndarray | None = None, *args, **kwargs) -> None:
|
|
48
49
|
if input_dataset_array is None:
|
|
49
50
|
input_dataset_array = self.dataset_array
|
|
50
|
-
self.compute_distance_matrix(input_dataset_array)
|
|
51
|
+
self.compute_distance_matrix(input_dataset_array)
|
|
52
|
+
|
|
53
|
+
def add_input_vector_to_dda(self) -> None:
|
|
54
|
+
"""Add the input vector to the dataset array and update the distance matrix accordingly."""
|
|
55
|
+
self.add_new_vector_to_distance_matrix(self.dataset_array)
|
|
56
|
+
self.dataset_array = np.vstack((self.dataset_array, self.input_vector))
|
|
57
|
+
|
|
@@ -6,7 +6,15 @@ from deduplicate_lib.core.plugin_registry import register_plugin
|
|
|
6
6
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
import warnings
|
|
9
|
+
from numba import njit
|
|
9
10
|
|
|
11
|
+
@njit
|
|
12
|
+
def fast_round_and_perturb(input_vector, perturbation_array, tolerance):
|
|
13
|
+
rounded_vector = np.round(input_vector / tolerance) * tolerance
|
|
14
|
+
round_and_perturb_array = np.zeros((perturbation_array.shape[0], len(input_vector)))
|
|
15
|
+
for i in range(perturbation_array.shape[0]):
|
|
16
|
+
round_and_perturb_array[i] = rounded_vector * perturbation_array[i]
|
|
17
|
+
return round_and_perturb_array
|
|
10
18
|
|
|
11
19
|
@register_plugin(kind="duplicate_detection_algorithm", name="multi_hashing")
|
|
12
20
|
class MultiHashing(DuplicateDetectionAlgorithm):
|
|
@@ -14,9 +22,9 @@ class MultiHashing(DuplicateDetectionAlgorithm):
|
|
|
14
22
|
|
|
15
23
|
def __init__(
|
|
16
24
|
self,
|
|
17
|
-
tolerance: float,
|
|
18
|
-
input_vector: np.ndarray,
|
|
19
|
-
dataset_array: np.ndarray,
|
|
25
|
+
tolerance: float = 0.1,
|
|
26
|
+
input_vector: np.ndarray = np.array([]),
|
|
27
|
+
dataset_array: np.ndarray = np.array([]),
|
|
20
28
|
perturbations: int = 200,
|
|
21
29
|
seed: int = 803,
|
|
22
30
|
pertrubation_array: np.ndarray = np.array([]),
|
|
@@ -24,6 +32,7 @@ class MultiHashing(DuplicateDetectionAlgorithm):
|
|
|
24
32
|
distance_metric: str = "hamming",
|
|
25
33
|
distance_matrix: np.ndarray = np.array([]),
|
|
26
34
|
hash_vector_array: np.ndarray = np.array([]),
|
|
35
|
+
unique_vector_indices: np.ndarray = np.array([]),
|
|
27
36
|
) -> None:
|
|
28
37
|
super().__init__(
|
|
29
38
|
tolerance=tolerance,
|
|
@@ -31,6 +40,7 @@ class MultiHashing(DuplicateDetectionAlgorithm):
|
|
|
31
40
|
dataset_array=dataset_array,
|
|
32
41
|
distance_metric=distance_metric,
|
|
33
42
|
distance_matrix=distance_matrix,
|
|
43
|
+
unique_vector_indices=unique_vector_indices,
|
|
34
44
|
)
|
|
35
45
|
self.seed = seed
|
|
36
46
|
self.acceptance_threshold = acceptance_threshold
|
|
@@ -48,6 +58,7 @@ class MultiHashing(DuplicateDetectionAlgorithm):
|
|
|
48
58
|
)
|
|
49
59
|
|
|
50
60
|
def _ensure_perturbation_array(self):
|
|
61
|
+
|
|
51
62
|
if self.perturbation_array.shape[0] != self.perturbations:
|
|
52
63
|
warnings.warn(
|
|
53
64
|
"Perturbation array shape does not match expected number of perturbations; recomputing. \nAssign the perturbation array prior duplication checks to avoid this warning."
|
|
@@ -60,11 +71,10 @@ class MultiHashing(DuplicateDetectionAlgorithm):
|
|
|
60
71
|
|
|
61
72
|
def create_hash_vector(self) -> np.ndarray:
|
|
62
73
|
self._ensure_perturbation_array()
|
|
63
|
-
|
|
74
|
+
rounded_and_perturbed = fast_round_and_perturb(self.input_vector, self.perturbation_array, self.tolerance)
|
|
75
|
+
hash_vector = np.zeros(self.perturbations, dtype=int)
|
|
64
76
|
for i in range(self.perturbations):
|
|
65
|
-
hash_vector[i] = hash(
|
|
66
|
-
(self.round_to_tolerance() * self.perturbation_array[i]).tobytes()
|
|
67
|
-
)
|
|
77
|
+
hash_vector[i] = hash(rounded_and_perturbed[i].tobytes())
|
|
68
78
|
return hash_vector
|
|
69
79
|
|
|
70
80
|
def create_hash_vector_array(self) -> np.ndarray:
|
|
@@ -120,10 +130,15 @@ class MultiHashing(DuplicateDetectionAlgorithm):
|
|
|
120
130
|
self.create_hash_vector_array()
|
|
121
131
|
clash_array = np.zeros((self.hash_vector_array.shape), dtype=bool)
|
|
122
132
|
clash_array[np.nonzero(self.hash_vector_array)] = True
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
133
|
+
self.unique_vector_indices = np.sum(clash_array, axis=1) / self.perturbations >= self.acceptance_threshold
|
|
134
|
+
|
|
135
|
+
return np.sum(self.unique_vector_indices)
|
|
136
|
+
|
|
128
137
|
def pre_dda_processing(self, *args, **kwargs) -> None:
|
|
129
138
|
self.set_perturbation_array()
|
|
139
|
+
|
|
140
|
+
def add_input_vector_to_dda(self) -> None:
|
|
141
|
+
"""Add the input vector to the dataset array and update the hash vector array accordingly."""
|
|
142
|
+
self.dataset_array = np.vstack((self.dataset_array, self.input_vector))
|
|
143
|
+
new_hash_vector = self.create_hash_vector()
|
|
144
|
+
self.hash_vector_array = np.vstack((self.hash_vector_array, new_hash_vector))
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
1
|
from deduplicate_lib.core.tolerance_calculator import ToleranceCalculator
|
|
3
|
-
from deduplicate_lib.core.duplicate_detection_algorithm import
|
|
2
|
+
from deduplicate_lib.core.duplicate_detection_algorithm import (
|
|
3
|
+
DuplicateDetectionAlgorithm,
|
|
4
|
+
)
|
|
4
5
|
from deduplicate_lib.core.plugin_registry import register_plugin
|
|
5
6
|
import numpy as np
|
|
6
7
|
import warnings
|
|
@@ -16,6 +17,7 @@ class NaturalTolerancePlateauProbe(ToleranceCalculator):
|
|
|
16
17
|
perturbation_scale: float = 0.1,
|
|
17
18
|
binary_search_steps: int = 50,
|
|
18
19
|
probe_steps: int = 100,
|
|
20
|
+
probe_buffer_fraction: float = 0.1,
|
|
19
21
|
) -> None:
|
|
20
22
|
super().__init__(
|
|
21
23
|
duplicate_detection_algorithm_object=duplicate_detection_algorithm_object,
|
|
@@ -25,6 +27,7 @@ class NaturalTolerancePlateauProbe(ToleranceCalculator):
|
|
|
25
27
|
binary_search_steps=binary_search_steps,
|
|
26
28
|
)
|
|
27
29
|
self.probe_steps = probe_steps
|
|
30
|
+
self.probe_buffer_fraction = probe_buffer_fraction
|
|
28
31
|
|
|
29
32
|
def __str__(self) -> str:
|
|
30
33
|
return f"NaturalTolerancePlateauProbe(perturbations_per_vector={self.perturbations_per_vector}, perturbation_scale={self.perturbation_scale}, dda={str(self.duplicate_detection_algorithm_object).split('(')[0]})"
|
|
@@ -45,21 +48,49 @@ class NaturalTolerancePlateauProbe(ToleranceCalculator):
|
|
|
45
48
|
self.duplicate_detection_algorithm_object.tolerance = tol
|
|
46
49
|
unique_structures = self.duplicate_detection_algorithm_object.get_dataset_unique_structures()
|
|
47
50
|
tolerance_results[tol] = unique_structures
|
|
48
|
-
|
|
51
|
+
return tolerance_results
|
|
52
|
+
|
|
53
|
+
def get_plateau_log(
|
|
54
|
+
self,
|
|
55
|
+
tolerance_results: dict,
|
|
56
|
+
datapoints_to_calculate_gradient: int = 3,
|
|
57
|
+
plateau_threshold: float = 1e-3,
|
|
58
|
+
sorted_tols: list | None = None,
|
|
59
|
+
) -> np.ndarray:
|
|
60
|
+
if sorted_tols is None:
|
|
61
|
+
sorted_tols = sorted(tolerance_results.keys())
|
|
49
62
|
|
|
50
|
-
def find_plateaus(self, tolerance_results: dict, datapoints_to_calculate_gradient: int = 3, plateau_threshold: float = 1e-3) -> tuple:
|
|
51
|
-
sorted_tols = sorted(tolerance_results.keys())
|
|
52
63
|
unique_counts = [tolerance_results[tol] for tol in sorted_tols]
|
|
53
64
|
|
|
65
|
+
relative_plateau_threshold = plateau_threshold * max(
|
|
66
|
+
unique_counts
|
|
67
|
+
) # Scale threshold based on the maximum number of unique structures
|
|
54
68
|
# detect plateaus by calculating the gradient of unique_counts with respect to tolerance and finding where it is close to zero
|
|
55
69
|
plateau_log = np.zeros(len(sorted_tols), dtype=bool)
|
|
56
70
|
for i in range(len(unique_counts) - datapoints_to_calculate_gradient):
|
|
57
71
|
gradient = (
|
|
58
72
|
unique_counts[i + datapoints_to_calculate_gradient] - unique_counts[i]
|
|
59
73
|
) / (sorted_tols[i + datapoints_to_calculate_gradient] - sorted_tols[i])
|
|
60
|
-
if
|
|
74
|
+
if (
|
|
75
|
+
abs(gradient) < relative_plateau_threshold
|
|
76
|
+
): # Threshold for plateau detection
|
|
61
77
|
plateau_log[i] = True
|
|
62
|
-
|
|
78
|
+
return plateau_log
|
|
79
|
+
|
|
80
|
+
def find_plateaus(
|
|
81
|
+
self,
|
|
82
|
+
tolerance_results: dict,
|
|
83
|
+
datapoints_to_calculate_gradient: int = 3,
|
|
84
|
+
plateau_threshold: float = 1e-3,
|
|
85
|
+
) -> tuple:
|
|
86
|
+
sorted_tols = sorted(tolerance_results.keys())
|
|
87
|
+
plateau_log = self.get_plateau_log(
|
|
88
|
+
tolerance_results,
|
|
89
|
+
datapoints_to_calculate_gradient,
|
|
90
|
+
plateau_threshold,
|
|
91
|
+
sorted_tols,
|
|
92
|
+
)
|
|
93
|
+
|
|
63
94
|
plateau_lengths = []
|
|
64
95
|
for i in range(len(plateau_log)):
|
|
65
96
|
if plateau_log[i]:
|
|
@@ -77,10 +108,15 @@ class NaturalTolerancePlateauProbe(ToleranceCalculator):
|
|
|
77
108
|
def calculate_tolerance(self) -> float:
|
|
78
109
|
self._ensure_perturbed_dataset()
|
|
79
110
|
all_same_tolerance = self.binary_search_tolerance(
|
|
80
|
-
target_unique_vectors=
|
|
111
|
+
target_unique_vectors=int(
|
|
112
|
+
np.floor(self.probe_buffer_fraction * len(self.tolerance_dataset_array))
|
|
113
|
+
),
|
|
114
|
+
find_largest_tolerance_for_target=False,
|
|
81
115
|
)
|
|
82
116
|
all_different_tolerance = self.binary_search_tolerance(
|
|
83
|
-
target_unique_vectors=len(self.tolerance_dataset_array)
|
|
117
|
+
target_unique_vectors=len(self.tolerance_dataset_array) - int(
|
|
118
|
+
np.floor(self.probe_buffer_fraction * len(self.tolerance_dataset_array))
|
|
119
|
+
),
|
|
84
120
|
find_largest_tolerance_for_target=True,
|
|
85
121
|
)
|
|
86
122
|
probe_results = self.tolerance_probe(
|
|
@@ -89,7 +125,7 @@ class NaturalTolerancePlateauProbe(ToleranceCalculator):
|
|
|
89
125
|
plateaus = self.find_plateaus(probe_results)
|
|
90
126
|
if len(plateaus) == 0:
|
|
91
127
|
warnings.warn(
|
|
92
|
-
"No plateaus found in tolerance probe. Consider adding in perturbed structures and/or increasing dataset size.\nReturning average of all same and all different tolerance as fallback."
|
|
128
|
+
"No plateaus found in tolerance probe. Consider adding in perturbed structures and/or increasing dataset size and/or increaseing probe steps.\nReturning average of all same and all different tolerance as fallback."
|
|
93
129
|
)
|
|
94
130
|
return (all_same_tolerance + all_different_tolerance) / 2
|
|
95
131
|
else:
|
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
from deduplicate_lib.core.tolerance_calculator import ToleranceCalculator
|
|
2
|
+
from deduplicate_lib.core.duplicate_detection_algorithm import DuplicateDetectionAlgorithm
|
|
2
3
|
from deduplicate_lib.core.plugin_registry import register_plugin
|
|
4
|
+
import numpy as np
|
|
3
5
|
|
|
4
6
|
|
|
5
7
|
@register_plugin("tolerance_calculator", "perturbed_dataset_reclustering")
|
|
6
8
|
class PerturbedDatasetReclustering(ToleranceCalculator):
|
|
9
|
+
def __init__(self,
|
|
10
|
+
duplicate_detection_algorithm_object: DuplicateDetectionAlgorithm,
|
|
11
|
+
tolerance_dataset_array: np.ndarray = np.array([]),
|
|
12
|
+
perturbations_per_vector: int = 1,
|
|
13
|
+
perturbation_scale: float = 0.1,
|
|
14
|
+
binary_search_steps: int = 20,
|
|
15
|
+
target_structures: int | None = None,):
|
|
16
|
+
super().__init__(
|
|
17
|
+
duplicate_detection_algorithm_object=duplicate_detection_algorithm_object,
|
|
18
|
+
tolerance_dataset_array=tolerance_dataset_array,
|
|
19
|
+
perturbations_per_vector=perturbations_per_vector,
|
|
20
|
+
perturbation_scale=perturbation_scale,
|
|
21
|
+
binary_search_steps=binary_search_steps,
|
|
22
|
+
)
|
|
23
|
+
if target_structures is None:
|
|
24
|
+
target_structures = len(duplicate_detection_algorithm_object.dataset_array)
|
|
25
|
+
self.target_structures = target_structures
|
|
26
|
+
|
|
7
27
|
def __str__(self) -> str:
|
|
8
28
|
return f"PerturbedDatasetReclustering(perturbations_per_vector={self.perturbations_per_vector}, perturbation_scale={self.perturbation_scale}, dda={str(self.duplicate_detection_algorithm_object).split('(')[0]})"
|
|
9
29
|
|
|
@@ -16,11 +36,11 @@ class PerturbedDatasetReclustering(ToleranceCalculator):
|
|
|
16
36
|
self._ensure_perturbed_dataset()
|
|
17
37
|
|
|
18
38
|
low_tolerance = self.binary_search_tolerance(
|
|
19
|
-
target_unique_vectors=
|
|
39
|
+
target_unique_vectors=self.target_structures,
|
|
20
40
|
find_largest_tolerance_for_target=False,
|
|
21
41
|
)
|
|
22
42
|
high_tolerance = self.binary_search_tolerance(
|
|
23
|
-
target_unique_vectors=
|
|
43
|
+
target_unique_vectors=self.target_structures,
|
|
24
44
|
find_largest_tolerance_for_target=True,
|
|
25
45
|
)
|
|
26
46
|
return (low_tolerance + high_tolerance) / 2
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: deduplicate_lib
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: A Python package for deduplicating data.
|
|
5
|
+
Author-email: Julian Holland <holland@fhi.mpg.de>
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: numpy
|
|
10
|
+
Requires-Dist: numba
|
|
11
|
+
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
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
<h1><code>deduplicate_lib</code></h1>
|
|
21
|
+
<p><i>deduplication algorithms in python</i></p>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
***
|
|
25
|
+
[](https://github.com/julianholland/deduplicate)
|
|
26
|
+
[](https://codecov.io/gh/julianholland/deduplicate)
|
|
27
|
+
[](https://badge.fury.io/py/deduplicate_lib)
|
|
28
|
+
[](https://www.python.org/downloads/)
|
|
29
|
+
[](https://opensource.org/licenses/MIT)
|
|
30
|
+
[](https://github.com/julianholland/deduplicate/actions/workflows/ci.yml)
|
|
31
|
+
[](https://github.com/astral-sh/ruff)
|
|
32
|
+
<!-- [](https://alomancy.readthedocs.io/en/latest/index.html) -->
|
|
33
|
+
|
|
34
|
+
## Key Features
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
- Easy to use deduplication algorithms for any vector array
|
|
38
|
+
- Suite of tolerance tuning algorithms to help you find the right tolerance value for your system
|
|
39
|
+
- Suite of benchmarking tools to ensure rigor, accuracy, and speed (not yet implemented)
|
|
40
|
+
- Factory Plugin architecture, for easy extensibility and modification
|
|
41
|
+
|
|
42
|
+
***
|
|
43
|
+
## Implemented Algorithms
|
|
44
|
+
|
|
45
|
+
- Distance Matrix (Simple, accurate, expensive): Computes the distance matrix for all vectors and determines duplicates by finding those that fall below a given distance
|
|
46
|
+
- Multi Hashing (Fast): Smears and rounds the vectors using a normal distribution and computes the hashes for each which are then used to determine duplicates by proportion of hash clashes.
|
|
47
|
+
<!-- - Locality Sensitive Hashing (Fast, Accurate) -->
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
install using pip
|
|
51
|
+
```bash
|
|
52
|
+
pip install deduplicate_lib
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
load your data into python
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from deduplicate_lib.plugins.deduplication_algorithms.multi_hash import MultiHash
|
|
59
|
+
|
|
60
|
+
# define your paramerters in the MultiHash object
|
|
61
|
+
dda=MultiHash(
|
|
62
|
+
tolerance=0.01,
|
|
63
|
+
dataset_array: your_data_array,
|
|
64
|
+
perturbations: int = 200,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
print(dda.get_dataset_unique_structures())
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
A more detailed example can be seen in the `examples` directory
|
|
71
|
+
|
|
72
|
+
### Dependencies
|
|
73
|
+
|
|
74
|
+
- Python 3.9+
|
|
75
|
+
- `numpy`
|
|
76
|
+
- `numba`
|
|
77
|
+
|
|
78
|
+
## 🤝 Contributing
|
|
79
|
+
|
|
80
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
81
|
+
|
|
82
|
+
### Development Setup
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Clone the repository
|
|
86
|
+
git clone https://github.com/julianholland/deduplicate.git
|
|
87
|
+
cd deduplicate
|
|
88
|
+
|
|
89
|
+
# Install in development mode
|
|
90
|
+
pip install -e ".[dev]"
|
|
91
|
+
|
|
92
|
+
# Run tests
|
|
93
|
+
pytest
|
|
94
|
+
|
|
95
|
+
# Run linting
|
|
96
|
+
ruff check .
|
|
97
|
+
ruff format .
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Running Tests
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# Run all tests
|
|
104
|
+
pytest
|
|
105
|
+
|
|
106
|
+
# Run specific test categories
|
|
107
|
+
pytest tests/core/
|
|
108
|
+
pytest tests/plugins/
|
|
109
|
+
pytest tests/plugins/duplicate_detection_algorithms/distance_matrix
|
|
110
|
+
|
|
111
|
+
# Run with coverage
|
|
112
|
+
pytest --cov
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## 📝 Citation
|
|
116
|
+
|
|
117
|
+
If you use deduplicate_lib in your research, please cite:
|
|
118
|
+
|
|
119
|
+
```bibtex
|
|
120
|
+
@software{alomancy2025,
|
|
121
|
+
title={Deduplicate_lib: Auto Tolerance Finding Deduplication Algorithms in Python},
|
|
122
|
+
author={Julian Holland},
|
|
123
|
+
year={2026},
|
|
124
|
+
url={https://github.com/julianholland/deduplicate},
|
|
125
|
+
version={0.0.1dev}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## 📄 License
|
|
130
|
+
|
|
131
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
132
|
+
|
|
133
|
+
## 🙏 Acknowledgments
|
|
134
|
+
|
|
135
|
+
- The Fritz Haber Institute
|
|
136
|
+
- Juan Manuel Lombardi <3
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
## Project Links
|
|
140
|
+
|
|
141
|
+
- [GitHub Repository](https://github.com/julianholland/deduplicate)
|
|
142
|
+
|
|
143
|
+
## Project To-Do
|
|
144
|
+
|
|
145
|
+
- [x] Add example.ipynb
|
|
146
|
+
- [ ] Create general Pre-allocation protocal
|
|
147
|
+
- [ ] Add benchmarks for time and robustness
|
|
148
|
+
- [ ] Add Locality-Sensitive Hashing as an option
|
|
149
|
+
- [x] Speedup slow tasks with Numba
|
|
150
|
+
- [ ] Set up Read the Docs
|
|
151
|
+
- [x] Create general deduplicate function
|
deduplicate_lib-0.0.1/PKG-INFO
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: deduplicate_lib
|
|
3
|
-
Version: 0.0.1
|
|
4
|
-
Summary: A Python package for deduplicating data.
|
|
5
|
-
Author-email: Julian Holland <holland@fhi.mpg.de>
|
|
6
|
-
Requires-Python: >=3.8
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
License-File: LICENSE
|
|
9
|
-
Requires-Dist: numpy
|
|
10
|
-
Provides-Extra: dev
|
|
11
|
-
Requires-Dist: pytest; extra == "dev"
|
|
12
|
-
Requires-Dist: pytest-mock; extra == "dev"
|
|
13
|
-
Requires-Dist: coverage; extra == "dev"
|
|
14
|
-
Requires-Dist: ruff; extra == "dev"
|
|
15
|
-
Dynamic: license-file
|
|
16
|
-
|
|
17
|
-
<div align="center">
|
|
18
|
-
<h1><code>deduplicate_lib</code></h1>
|
|
19
|
-
<p><i>deduplication algorithms in python</i></p>
|
|
20
|
-
</div>
|
|
21
|
-
|
|
22
|
-
***
|
|
23
|
-
## Key Features
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
- Easy to use deduplication algorithms for any vector array
|
|
27
|
-
- Suite of tolerance tuning algorithms to help you find the right tolerance value for your system
|
|
28
|
-
- Suite of benchmarking tools to ensure rigor, accuracy, and speed (not yet implemented)
|
|
29
|
-
- Factory Plugin architecture, for easy extensibility and modification
|
|
30
|
-
|
|
31
|
-
***
|
|
32
|
-
## Implemented Algorithms
|
|
33
|
-
|
|
34
|
-
- Distance Matrix (Simple, accurate, expensive): Computes the distance matrix for all vectors and determines duplicates by finding those that fall below a given distance
|
|
35
|
-
- Multi Hashing (Fast): Smears and rounds the vectors using a normal distribution and computes the hashes for each which are then used to determine duplicates by proportion of hash clashes.
|
|
36
|
-
<!-- - Locality Sensitive Hashing (Fast, Accurate) -->
|
|
37
|
-
|
|
38
|
-
## Quick Start
|
|
39
|
-
install using pip
|
|
40
|
-
```bash
|
|
41
|
-
pip install deduplicate_lib
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
load your data into python
|
|
45
|
-
|
|
46
|
-
```python
|
|
47
|
-
from deduplicate_lib.plugins.deduplication_algorithms.multi_hash import MultiHash
|
|
48
|
-
|
|
49
|
-
# define your paramerters in the MultiHash object
|
|
50
|
-
dda=MultiHash(
|
|
51
|
-
tolerance=0.01,
|
|
52
|
-
dataset_array: your_data_array,
|
|
53
|
-
perturbations: int = 200,
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
print(dda.get_dataset_unique_structures())
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
A more detailed example can be seen in the `examples` directory
|
deduplicate_lib-0.0.1/README.md
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<h1><code>deduplicate_lib</code></h1>
|
|
3
|
-
<p><i>deduplication algorithms in python</i></p>
|
|
4
|
-
</div>
|
|
5
|
-
|
|
6
|
-
***
|
|
7
|
-
## Key Features
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
- Easy to use deduplication algorithms for any vector array
|
|
11
|
-
- Suite of tolerance tuning algorithms to help you find the right tolerance value for your system
|
|
12
|
-
- Suite of benchmarking tools to ensure rigor, accuracy, and speed (not yet implemented)
|
|
13
|
-
- Factory Plugin architecture, for easy extensibility and modification
|
|
14
|
-
|
|
15
|
-
***
|
|
16
|
-
## Implemented Algorithms
|
|
17
|
-
|
|
18
|
-
- Distance Matrix (Simple, accurate, expensive): Computes the distance matrix for all vectors and determines duplicates by finding those that fall below a given distance
|
|
19
|
-
- Multi Hashing (Fast): Smears and rounds the vectors using a normal distribution and computes the hashes for each which are then used to determine duplicates by proportion of hash clashes.
|
|
20
|
-
<!-- - Locality Sensitive Hashing (Fast, Accurate) -->
|
|
21
|
-
|
|
22
|
-
## Quick Start
|
|
23
|
-
install using pip
|
|
24
|
-
```bash
|
|
25
|
-
pip install deduplicate_lib
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
load your data into python
|
|
29
|
-
|
|
30
|
-
```python
|
|
31
|
-
from deduplicate_lib.plugins.deduplication_algorithms.multi_hash import MultiHash
|
|
32
|
-
|
|
33
|
-
# define your paramerters in the MultiHash object
|
|
34
|
-
dda=MultiHash(
|
|
35
|
-
tolerance=0.01,
|
|
36
|
-
dataset_array: your_data_array,
|
|
37
|
-
perturbations: int = 200,
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
print(dda.get_dataset_unique_structures())
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
A more detailed example can be seen in the `examples` directory
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.0.1"
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: deduplicate_lib
|
|
3
|
-
Version: 0.0.1
|
|
4
|
-
Summary: A Python package for deduplicating data.
|
|
5
|
-
Author-email: Julian Holland <holland@fhi.mpg.de>
|
|
6
|
-
Requires-Python: >=3.8
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
License-File: LICENSE
|
|
9
|
-
Requires-Dist: numpy
|
|
10
|
-
Provides-Extra: dev
|
|
11
|
-
Requires-Dist: pytest; extra == "dev"
|
|
12
|
-
Requires-Dist: pytest-mock; extra == "dev"
|
|
13
|
-
Requires-Dist: coverage; extra == "dev"
|
|
14
|
-
Requires-Dist: ruff; extra == "dev"
|
|
15
|
-
Dynamic: license-file
|
|
16
|
-
|
|
17
|
-
<div align="center">
|
|
18
|
-
<h1><code>deduplicate_lib</code></h1>
|
|
19
|
-
<p><i>deduplication algorithms in python</i></p>
|
|
20
|
-
</div>
|
|
21
|
-
|
|
22
|
-
***
|
|
23
|
-
## Key Features
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
- Easy to use deduplication algorithms for any vector array
|
|
27
|
-
- Suite of tolerance tuning algorithms to help you find the right tolerance value for your system
|
|
28
|
-
- Suite of benchmarking tools to ensure rigor, accuracy, and speed (not yet implemented)
|
|
29
|
-
- Factory Plugin architecture, for easy extensibility and modification
|
|
30
|
-
|
|
31
|
-
***
|
|
32
|
-
## Implemented Algorithms
|
|
33
|
-
|
|
34
|
-
- Distance Matrix (Simple, accurate, expensive): Computes the distance matrix for all vectors and determines duplicates by finding those that fall below a given distance
|
|
35
|
-
- Multi Hashing (Fast): Smears and rounds the vectors using a normal distribution and computes the hashes for each which are then used to determine duplicates by proportion of hash clashes.
|
|
36
|
-
<!-- - Locality Sensitive Hashing (Fast, Accurate) -->
|
|
37
|
-
|
|
38
|
-
## Quick Start
|
|
39
|
-
install using pip
|
|
40
|
-
```bash
|
|
41
|
-
pip install deduplicate_lib
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
load your data into python
|
|
45
|
-
|
|
46
|
-
```python
|
|
47
|
-
from deduplicate_lib.plugins.deduplication_algorithms.multi_hash import MultiHash
|
|
48
|
-
|
|
49
|
-
# define your paramerters in the MultiHash object
|
|
50
|
-
dda=MultiHash(
|
|
51
|
-
tolerance=0.01,
|
|
52
|
-
dataset_array: your_data_array,
|
|
53
|
-
perturbations: int = 200,
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
print(dda.get_dataset_unique_structures())
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
A more detailed example can be seen in the `examples` directory
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{deduplicate_lib-0.0.1 → deduplicate_lib-0.0.2}/src/deduplicate_lib.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|