deduplicate-lib 0.0.4__tar.gz → 0.0.5__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.
Files changed (23) hide show
  1. {deduplicate_lib-0.0.4/src/deduplicate_lib.egg-info → deduplicate_lib-0.0.5}/PKG-INFO +3 -3
  2. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/README.md +2 -2
  3. deduplicate_lib-0.0.5/src/deduplicate_lib/__init__.py +1 -0
  4. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib/core/tolerance_calculator.py +3 -0
  5. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/multi_hashing.py +57 -39
  6. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5/src/deduplicate_lib.egg-info}/PKG-INFO +3 -3
  7. deduplicate_lib-0.0.4/src/deduplicate_lib/__init__.py +0 -1
  8. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/LICENSE +0 -0
  9. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/pyproject.toml +0 -0
  10. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/setup.cfg +0 -0
  11. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib/core/__init__.py +0 -0
  12. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib/core/duplicate_detection_algorithm.py +0 -0
  13. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib/core/plugin_registry.py +0 -0
  14. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib/plugins/__init__.py +0 -0
  15. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/__init__.py +0 -0
  16. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/distance_matrix.py +0 -0
  17. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib/plugins/tolerance_calculators/__init__.py +0 -0
  18. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib/plugins/tolerance_calculators/natural_tolerance_plateau_probe.py +0 -0
  19. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib/plugins/tolerance_calculators/perturbed_dataset_reclustering.py +0 -0
  20. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib.egg-info/SOURCES.txt +0 -0
  21. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib.egg-info/dependency_links.txt +0 -0
  22. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib.egg-info/requires.txt +0 -0
  23. {deduplicate_lib-0.0.4 → deduplicate_lib-0.0.5}/src/deduplicate_lib.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deduplicate_lib
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: A Python package for deduplicating data.
5
5
  Author-email: Julian Holland <holland@fhi.mpg.de>
6
6
  Requires-Python: >=3.8
@@ -125,7 +125,7 @@ If you use deduplicate_lib in your research, please cite:
125
125
  author={Julian Holland},
126
126
  year={2026},
127
127
  url={https://github.com/julianholland/deduplicate},
128
- version={0.0.2dev}
128
+ version={0.0.5}
129
129
  }
130
130
  ```
131
131
 
@@ -154,4 +154,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
154
154
  - [x] Speedup slow tasks with Numba
155
155
  - [ ] Set up Read the Docs
156
156
  - [x] Create general deduplicate function
157
- - [ ] Speed up NTPP
157
+ - [x] Speed up NTPP
@@ -102,7 +102,7 @@ If you use deduplicate_lib in your research, please cite:
102
102
  author={Julian Holland},
103
103
  year={2026},
104
104
  url={https://github.com/julianholland/deduplicate},
105
- version={0.0.2dev}
105
+ version={0.0.5}
106
106
  }
107
107
  ```
108
108
 
@@ -131,4 +131,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
131
131
  - [x] Speedup slow tasks with Numba
132
132
  - [ ] Set up Read the Docs
133
133
  - [x] Create general deduplicate function
134
- - [ ] Speed up NTPP
134
+ - [x] Speed up NTPP
@@ -0,0 +1 @@
1
+ __version__ = "0.0.5"
@@ -55,6 +55,7 @@ class ToleranceCalculator(ABC):
55
55
  old_array=self.duplicate_detection_algorithm_object.get_filled_dataset_array()
56
56
  old_vector_count=self.duplicate_detection_algorithm_object.vector_count
57
57
  self.duplicate_detection_algorithm_object.set_dataset_array(self.tolerance_dataset_array)
58
+
58
59
  self.duplicate_detection_algorithm_object.pre_dda_processing()
59
60
 
60
61
  for _ in range(self.binary_search_steps):
@@ -64,6 +65,7 @@ class ToleranceCalculator(ABC):
64
65
  ):
65
66
 
66
67
  unique_vectors = self.duplicate_detection_algorithm_object.get_dataset_unique_structures()
68
+
67
69
 
68
70
  results_dict[tolerance] = unique_vectors
69
71
  if unique_vectors < target_unique_vectors: # loosen tolerance
@@ -82,6 +84,7 @@ class ToleranceCalculator(ABC):
82
84
  best_min = tolerance
83
85
  else:
84
86
  best_max = tolerance
87
+
85
88
  tolerance = (best_min + best_max) / 2
86
89
 
87
90
  # reset the dataset_array to the original dataset array after the search is complete
@@ -37,7 +37,6 @@ class MultiHashing(DuplicateDetectionAlgorithm):
37
37
  distance_metric: str = "hamming",
38
38
  sigma_accepatnce_threshold: int = 1,
39
39
  distance_matrix: np.ndarray = np.array([]),
40
- hash_vector_array: np.ndarray = np.array([]),
41
40
  unique_vector_indices: np.ndarray = np.array([]),
42
41
  max_vector_array_size: int = 10000,
43
42
  ) -> None:
@@ -53,9 +52,9 @@ class MultiHashing(DuplicateDetectionAlgorithm):
53
52
  self.seed = seed
54
53
  self.sigma_accepatnce_threshold = sigma_accepatnce_threshold
55
54
  self.perturbations = perturbations
56
- self.hash_vector_array = hash_vector_array
57
55
  self.perturbation_array = pertrubation_array
58
-
56
+
57
+ self.initialize_hash_vector_dictionary()
59
58
  self.set_acceptance_threshold()
60
59
 
61
60
  def __str__(self) -> str:
@@ -103,34 +102,35 @@ class MultiHashing(DuplicateDetectionAlgorithm):
103
102
  hash_vector[i] = hash(rounded_and_perturbed[i].tobytes())
104
103
  return hash_vector
105
104
 
106
- def compute_hash_vector_array(self) -> np.ndarray:
107
- """Creates the hash vector array for the dataset. Only unique hash values are stored for each perturbation.
105
+ def initialize_hash_vector_dictionary(self) -> None:
106
+ self.hash_dict = {i: {} for i in range(self.perturbations)}
108
107
 
109
- Returns:
110
- np.ndarray: A 2D array containing the hash values for each vector in the dataset for each perturbation.
111
- """
112
- self.initialize_hash_vector_array()
113
- self._ensure_perturbation_array()
108
+ def compute_hash_vector_dictionary(self) -> dict:
109
+ self.initialize_hash_vector_dictionary()
114
110
  for i in range(self.vector_count):
115
- hash_vector = self.create_hash_vector(self.dataset_array[i])
116
- for j in range(self.perturbations):
117
- if hash_vector[j] not in self.hash_vector_array[:, j]:
118
- self.hash_vector_array[i, j] = hash_vector[j]
119
- return self.hash_vector_array
120
-
121
- def initialize_hash_vector_array(self) -> None:
122
- self.hash_vector_array = np.zeros((self.max_vector_array_size, self.perturbations), dtype=int)
111
+ self.add_input_vector_hashes_to_dictionary(input_vector=self._dataset_array[i], input_index=i)
112
+
113
+ return self.hash_dict
123
114
 
124
- def get_filled_hash_vector_array(self) -> np.ndarray:
125
- """Returns the filled portion of the hash vector array corresponding to the current dataset size."""
126
- return self.hash_vector_array[: self.vector_count]
115
+ def add_input_vector_hashes_to_dictionary(self, input_vector: np.ndarray | None = None, input_index: int = None) -> None:
116
+ if input_vector is None:
117
+ input_vector = self.input_vector
118
+ if input_index is None:
119
+ input_index = self.vector_count
127
120
 
128
- def _ensure_hash_vector_array(self):
129
- if self.hash_vector_array.shape[0] != self.dataset_array.shape[0]:
130
- warnings.warn(
131
- "Hash vector array shape does not match dataset; recomputing."
132
- )
133
- self.compute_hash_vector_array()
121
+ hash_vector = self.create_hash_vector(input_vector)
122
+ self.warn_if_vector_dict_mismatch(hash_vector)
123
+
124
+ for hash_index, hash_value in enumerate(hash_vector):
125
+ if hash_value not in self.hash_dict[hash_index]:
126
+ self.hash_dict[hash_index][hash_value] = [input_index]
127
+ else:
128
+ self.hash_dict[hash_index][hash_value].append(input_index) # maybe replace with pre init boolean np array
129
+
130
+ def warn_if_vector_dict_mismatch(self, hash_vector: np.ndarray):
131
+ if len(self.hash_dict) != len(hash_vector):
132
+ warnings.warn("Hash vector dictionary length does not match number of perturbations; recomputing. \nAssign the perturbation array and compute the hash vector dictionary prior to duplication checks to avoid this warning.")
133
+ self.compute_hash_vector_dictionary()
134
134
 
135
135
  def duplicate_check(self) -> bool:
136
136
  """duplicate check against dataset using multi-hashing approach.
@@ -138,12 +138,12 @@ class MultiHashing(DuplicateDetectionAlgorithm):
138
138
  Returns:
139
139
  bool: True if a duplicate is detected, False otherwise.
140
140
  """
141
- self._ensure_hash_vector_array()
142
141
  hash_vector = self.create_hash_vector()
142
+ self.warn_if_vector_dict_mismatch(hash_vector)
143
143
 
144
144
  clash_vector = np.zeros(self.perturbations, dtype=bool)
145
145
  for hash_index, hash_value in enumerate(hash_vector):
146
- if hash_value in self.hash_vector_array[: self.vector_count, hash_index]:
146
+ if hash_value in self.hash_dict[hash_index]:
147
147
  clash_vector[hash_index] = True
148
148
  duplicate_vote_array = np.sum(clash_vector) / self.perturbations
149
149
 
@@ -152,37 +152,55 @@ class MultiHashing(DuplicateDetectionAlgorithm):
152
152
  return bool(duplicate_structure)
153
153
 
154
154
  def get_uniqueness_score(self) -> float:
155
- self._ensure_hash_vector_array()
156
155
  hash_vector = self.create_hash_vector()
156
+ self.warn_if_vector_dict_mismatch(hash_vector)
157
157
  clash_vector = np.zeros(self.perturbations, dtype=bool)
158
158
  for hash_index, hash_value in enumerate(hash_vector):
159
- if hash_value in self.hash_vector_array[: self.vector_count, hash_index]:
159
+ if hash_value in self.hash_dict[hash_index]:
160
160
  clash_vector[hash_index] = True
161
161
  uniqueness_score = 1 - np.sum(clash_vector) / self.perturbations
162
162
 
163
163
  return uniqueness_score
164
164
 
165
+
165
166
  def get_dataset_unique_structures(self) -> int:
166
167
  """Counts the number of unique structures in the dataset by checking for hash value clashes across the dataset for each perturbation.
167
168
 
168
169
  Returns:
169
170
  int: The number of unique structures in the dataset.
170
171
  """
171
- self.compute_hash_vector_array()
172
- clash_array = np.zeros((self.hash_vector_array[: self.vector_count].shape), dtype=bool)
173
- clash_array[np.nonzero(self.hash_vector_array[: self.vector_count])] = True
174
- self.unique_vector_indices = np.sum(clash_array, axis=1) / self.perturbations >= self.acceptance_threshold
172
+ self.compute_hash_vector_dictionary()
173
+ u_list_of_lists = []
174
+ for i in range(self.perturbations):
175
+ u_list = [self.hash_dict[i][hash_value][0] for hash_value in self.hash_dict[i]]
176
+ u_list_of_lists.append(u_list)
177
+
178
+ # count the number of times each index appears across all perturbations
179
+ index_counts = {}
180
+ for i in range(self.vector_count):
181
+ for u_list in u_list_of_lists:
182
+ if i in u_list:
183
+ if i not in index_counts:
184
+ index_counts[i] = 1
185
+ else:
186
+ index_counts[i] += 1
175
187
 
188
+ # get indexes that appear in at least acceptance_threshold * perturbations perturbations
189
+ index_filter = [index for index, count in index_counts.items() if count / self.perturbations >= self.acceptance_threshold]
190
+
191
+ # convert to boolean array for indexing
192
+ self.unique_vector_indices = np.zeros(self.vector_count, dtype=bool)
193
+ self.unique_vector_indices[index_filter] = True
194
+
176
195
  return np.sum(self.unique_vector_indices)
177
196
 
178
197
  def pre_dda_processing(self, *args, **kwargs) -> None:
179
- self.preinitialize_dataset_array()
180
198
  self.set_perturbation_array()
199
+ self.compute_hash_vector_dictionary()
200
+
181
201
 
182
202
  def add_input_vector_to_dda(self) -> None:
183
203
  """Add the input vector to the dataset array and update the hash vector array accordingly."""
184
- self._ensure_hash_vector_array()
185
204
  self._dataset_array[self.vector_count] = self.input_vector
186
- new_hash_vector = self.create_hash_vector()
187
- self.hash_vector_array[self.vector_count] = new_hash_vector
205
+ self.add_input_vector_hashes_to_dictionary(self.input_vector)
188
206
  self.vector_count += 1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deduplicate_lib
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: A Python package for deduplicating data.
5
5
  Author-email: Julian Holland <holland@fhi.mpg.de>
6
6
  Requires-Python: >=3.8
@@ -125,7 +125,7 @@ If you use deduplicate_lib in your research, please cite:
125
125
  author={Julian Holland},
126
126
  year={2026},
127
127
  url={https://github.com/julianholland/deduplicate},
128
- version={0.0.2dev}
128
+ version={0.0.5}
129
129
  }
130
130
  ```
131
131
 
@@ -154,4 +154,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
154
154
  - [x] Speedup slow tasks with Numba
155
155
  - [ ] Set up Read the Docs
156
156
  - [x] Create general deduplicate function
157
- - [ ] Speed up NTPP
157
+ - [x] Speed up NTPP
@@ -1 +0,0 @@
1
- __version__ = "0.0.4"
File without changes