deduplicate-lib 0.0.4__tar.gz → 0.1.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.
Files changed (23) hide show
  1. {deduplicate_lib-0.0.4/src/deduplicate_lib.egg-info → deduplicate_lib-0.1.0}/PKG-INFO +3 -3
  2. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/README.md +2 -2
  3. deduplicate_lib-0.1.0/src/deduplicate_lib/__init__.py +1 -0
  4. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib/core/duplicate_detection_algorithm.py +37 -10
  5. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib/core/tolerance_calculator.py +4 -1
  6. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/distance_matrix.py +5 -6
  7. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/multi_hashing.py +81 -41
  8. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib/plugins/tolerance_calculators/natural_tolerance_plateau_probe.py +36 -11
  9. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib/plugins/tolerance_calculators/perturbed_dataset_reclustering.py +2 -1
  10. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0/src/deduplicate_lib.egg-info}/PKG-INFO +3 -3
  11. deduplicate_lib-0.0.4/src/deduplicate_lib/__init__.py +0 -1
  12. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/LICENSE +0 -0
  13. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/pyproject.toml +0 -0
  14. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/setup.cfg +0 -0
  15. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib/core/__init__.py +0 -0
  16. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib/core/plugin_registry.py +0 -0
  17. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib/plugins/__init__.py +0 -0
  18. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib/plugins/duplicate_detection_algorithms/__init__.py +0 -0
  19. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib/plugins/tolerance_calculators/__init__.py +0 -0
  20. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib.egg-info/SOURCES.txt +0 -0
  21. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib.egg-info/dependency_links.txt +0 -0
  22. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/src/deduplicate_lib.egg-info/requires.txt +0 -0
  23. {deduplicate_lib-0.0.4 → deduplicate_lib-0.1.0}/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.1.0
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.1.0"
@@ -81,6 +81,8 @@ class DuplicateDetectionAlgorithm(ABC):
81
81
  self.distance_metric = distance_metric
82
82
  self.unique_vector_indices = unique_vector_indices
83
83
  self.max_vector_array_size = max_vector_array_size
84
+ self._dirty = True # auxiliary structures (distance matrix, hash dict, ...) need (re)building
85
+ self.vector_count = 0
84
86
 
85
87
  self.set_dataset_array(dataset_array) if dataset_array.size > 0 else None
86
88
 
@@ -145,14 +147,27 @@ class DuplicateDetectionAlgorithm(ABC):
145
147
  self.distance_matrix[:, self.vector_count] = np.pad(new_distances, (0, self.max_vector_array_size - len(new_distances)), constant_values=0)
146
148
 
147
149
 
148
- def pre_dda_processing(
149
- self, input_dataset_array: np.ndarray | None = None, *args, **kwargs
150
- ) -> None:
151
- """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."""
150
+ def pre_dda_processing(self, *args, **kwargs) -> None:
151
+ """Ensure the dataset array and any algorithm-specific auxiliary structures (e.g. distance matrix, hash dictionary) are preallocated and up to date before duplication checks.
152
+
153
+ This is idempotent: auxiliary structures are only rebuilt via `_rebuild_auxiliary_structures()` if the dataset has changed (`_dirty`) since they were last built. Child classes should implement `_rebuild_auxiliary_structures()` rather than overriding this method.
154
+ """
155
+ self.preinitialize_dataset_array()
156
+ if self._dirty:
157
+ self._rebuild_auxiliary_structures()
158
+ self._dirty = False
159
+
160
+ def _rebuild_auxiliary_structures(self) -> None:
161
+ """Rebuild any algorithm-specific auxiliary structures from the current dataset array. Overridden by child classes."""
152
162
  pass
153
163
 
154
164
  def add_input_vector_to_dda(self) -> None:
155
- """Add the input vector to the dataset array and update the distance matrix accordingly."""
165
+ """Add the input vector to the dataset array and update any auxiliary structures accordingly."""
166
+ self.pre_dda_processing()
167
+ self._append_vector_to_structures()
168
+
169
+ def _append_vector_to_structures(self) -> None:
170
+ """Append `input_vector` to the dataset array and incrementally update any auxiliary structures. Overridden by child classes."""
156
171
  pass
157
172
 
158
173
  def get_unique_vector_indices(self) -> np.ndarray:
@@ -182,24 +197,30 @@ class DuplicateDetectionAlgorithm(ABC):
182
197
  def set_dataset_array(self, new_dataset_array: np.ndarray) -> None:
183
198
  """Create new dataset array with correct shape and vector count
184
199
  if the input vector and dataset are both empty then the vector length cannot be determined, so we initialize an empty dataset array"""
200
+ current_dataset_array = self._dataset_array[: self.vector_count]
201
+ if new_dataset_array.shape == current_dataset_array.shape and np.array_equal(
202
+ new_dataset_array, current_dataset_array
203
+ ):
204
+ return
205
+
185
206
  if new_dataset_array.shape[0] > self.max_vector_array_size:
186
207
  raise ValueError("New dataset array size exceeds maximum allowed size.")
187
208
 
188
209
  self.vector_count = new_dataset_array.shape[0]
189
210
  if new_dataset_array.size == 0 and self.input_vector.size > 0:
190
211
  self.initialize_dataset_array(len(self.input_vector))
191
- elif new_dataset_array.size > 0:
212
+ elif new_dataset_array.size > 0:
192
213
  self.initialize_dataset_array(new_dataset_array.shape[1])
193
214
  self._dataset_array[: self.vector_count] = new_dataset_array
194
215
  else:
195
216
  self._dataset_array = new_dataset_array
217
+
218
+ self._dirty = True
196
219
 
197
220
  def get_vector_length(self) -> int:
198
221
  has_input = self.input_vector.size > 0
199
222
  has_dataset = self._dataset_array.size > 0
200
- print(f"has_input: {has_input}, has_dataset: {has_dataset}")
201
- print(f"input_vector: {self.input_vector}, dataset_array: {self._dataset_array}")
202
-
223
+
203
224
  if has_input and has_dataset:
204
225
  print(self.input_vector.shape, self._dataset_array.shape)
205
226
  if self.input_vector.shape[0] != self._dataset_array.shape[1]:
@@ -209,6 +230,8 @@ class DuplicateDetectionAlgorithm(ABC):
209
230
  vector_length = self.input_vector.shape[0]
210
231
  elif has_dataset:
211
232
  vector_length = self._dataset_array.shape[1]
233
+ elif has_input:
234
+ vector_length = len(self.input_vector)
212
235
  else:
213
236
  raise ValueError(
214
237
  "Cannot determine vector length from input vector or dataset array. "
@@ -219,10 +242,14 @@ class DuplicateDetectionAlgorithm(ABC):
219
242
 
220
243
  def preinitialize_dataset_array(self) -> None:
221
244
  vector_length=self.get_vector_length()
222
-
245
+
223
246
  if self._dataset_array.shape[0] > self.max_vector_array_size:
224
247
  raise ValueError("Dataset array size exceeds maximum allowed size.")
225
248
 
249
+ if self._dataset_array.size == 0:
250
+ self.initialize_dataset_array(vector_length)
251
+ self.vector_count = 0
252
+
226
253
  if self._dataset_array.shape[0] != self.max_vector_array_size:
227
254
  existing_data = self._dataset_array.copy()
228
255
  self.vector_count = existing_data.shape[0]
@@ -29,7 +29,7 @@ class ToleranceCalculator(ABC):
29
29
  yield
30
30
  finally:
31
31
  setattr(obj, attr, original)
32
-
32
+
33
33
  def binary_search_tolerance(
34
34
  self,
35
35
  target_unique_vectors: int,
@@ -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):
@@ -65,6 +66,7 @@ class ToleranceCalculator(ABC):
65
66
 
66
67
  unique_vectors = self.duplicate_detection_algorithm_object.get_dataset_unique_structures()
67
68
 
69
+
68
70
  results_dict[tolerance] = unique_vectors
69
71
  if unique_vectors < target_unique_vectors: # loosen tolerance
70
72
  best_max = tolerance
@@ -82,6 +84,7 @@ class ToleranceCalculator(ABC):
82
84
  best_min = tolerance
83
85
  else:
84
86
  best_max = tolerance
87
+ print(f"Tolerance: {tolerance}, Unique Vectors: {unique_vectors}")
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
@@ -22,6 +22,7 @@ class DistanceMatrix(DuplicateDetectionAlgorithm):
22
22
  return f"DistanceMatrix(tolerance={self.tolerance}, distance_metric={self.distance_metric})"
23
23
 
24
24
  def duplicate_check(self) -> bool:
25
+ self.preinitialize_dataset_array()
25
26
  return bool(
26
27
  np.any(
27
28
  self.get_new_distance_matrix_column(self.dataset_array) < self.tolerance
@@ -29,6 +30,7 @@ class DistanceMatrix(DuplicateDetectionAlgorithm):
29
30
  )
30
31
 
31
32
  def get_dataset_unique_structures(self) -> int:
33
+ self.pre_dda_processing()
32
34
  self.unique_vector_indices = np.zeros(self.vector_count, dtype=bool)
33
35
  self.unique_vector_indices[0] = True # the first vector is always unique
34
36
  for i in range(1, self.vector_count):
@@ -37,14 +39,11 @@ class DistanceMatrix(DuplicateDetectionAlgorithm):
37
39
  self.unique_vector_indices[i] = True
38
40
  return np.sum(self.unique_vector_indices)
39
41
 
40
- def pre_dda_processing(self, *args, **kwargs) -> None:
41
- self.preinitialize_dataset_array()
42
- self.initialize_distance_matrix()
42
+ def _rebuild_auxiliary_structures(self) -> None:
43
43
  self.compute_distance_matrix(self.dataset_array)
44
-
45
- def add_input_vector_to_dda(self) -> None:
44
+
45
+ def _append_vector_to_structures(self) -> None:
46
46
  """Add the input vector to the dataset array and update the distance matrix accordingly."""
47
47
  self.add_new_vector_to_distance_matrix(self.dataset_array)
48
48
  self._dataset_array[self.vector_count] = self.input_vector
49
49
  self.vector_count += 1
50
-
@@ -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:
@@ -66,6 +65,8 @@ class MultiHashing(DuplicateDetectionAlgorithm):
66
65
  self.perturbation_array = np.abs(
67
66
  rng.normal(loc=0.0, scale=1.0, size=self.perturbations)
68
67
  )
68
+ # self.perturbation_array = rng.normal(loc=0.0, scale=1.0, size=self.perturbations)
69
+
69
70
 
70
71
  def _ensure_perturbation_array(self):
71
72
 
@@ -98,39 +99,41 @@ class MultiHashing(DuplicateDetectionAlgorithm):
98
99
  input_vector = self.input_vector
99
100
  self._ensure_perturbation_array()
100
101
  rounded_and_perturbed = fast_round_and_perturb(input_vector, self.perturbation_array, self.tolerance)
102
+ rounded_and_perturbed = np.where(rounded_and_perturbed == 0, 0.0, rounded_and_perturbed) # ensure that any -0.0 values are converted to 0.0 otherwise they hash differently
101
103
  hash_vector = np.zeros(self.perturbations, dtype=int)
102
104
  for i in range(self.perturbations):
103
105
  hash_vector[i] = hash(rounded_and_perturbed[i].tobytes())
104
106
  return hash_vector
105
107
 
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.
108
+ def initialize_hash_vector_dictionary(self) -> None:
109
+ self.hash_dict = {i: {} for i in range(self.perturbations)}
108
110
 
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()
111
+ def compute_hash_vector_dictionary(self) -> dict:
112
+ self.initialize_hash_vector_dictionary()
114
113
  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)
114
+ self.add_input_vector_hashes_to_dictionary(input_vector=self._dataset_array[i], input_index=i)
115
+
116
+ return self.hash_dict
123
117
 
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]
118
+ def add_input_vector_hashes_to_dictionary(self, input_vector: np.ndarray | None = None, input_index: int | None = None) -> None:
119
+ if input_vector is None:
120
+ input_vector = self.input_vector
121
+ if input_index is None:
122
+ input_index = self.vector_count
127
123
 
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()
124
+ hash_vector = self.create_hash_vector(input_vector)
125
+ self.warn_if_vector_dict_mismatch(hash_vector)
126
+
127
+ for hash_index, hash_value in enumerate(hash_vector):
128
+ if hash_value not in self.hash_dict[hash_index]:
129
+ self.hash_dict[hash_index][hash_value] = {input_index: True} # if first time seeing this hash value, add index with True (indicating a unique structure for this perturbation)
130
+ else:
131
+ self.hash_dict[hash_index][hash_value][input_index] = False # if hash value already exists, add index with False (indicating a clash for this perturbation)
132
+
133
+ def warn_if_vector_dict_mismatch(self, hash_vector: np.ndarray):
134
+ if len(self.hash_dict) != len(hash_vector):
135
+ 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.")
136
+ self.compute_hash_vector_dictionary()
134
137
 
135
138
  def duplicate_check(self) -> bool:
136
139
  """duplicate check against dataset using multi-hashing approach.
@@ -138,12 +141,13 @@ class MultiHashing(DuplicateDetectionAlgorithm):
138
141
  Returns:
139
142
  bool: True if a duplicate is detected, False otherwise.
140
143
  """
141
- self._ensure_hash_vector_array()
144
+ self.pre_dda_processing()
142
145
  hash_vector = self.create_hash_vector()
146
+ self.warn_if_vector_dict_mismatch(hash_vector)
143
147
 
144
148
  clash_vector = np.zeros(self.perturbations, dtype=bool)
145
149
  for hash_index, hash_value in enumerate(hash_vector):
146
- if hash_value in self.hash_vector_array[: self.vector_count, hash_index]:
150
+ if hash_value in self.hash_dict[hash_index]:
147
151
  clash_vector[hash_index] = True
148
152
  duplicate_vote_array = np.sum(clash_vector) / self.perturbations
149
153
 
@@ -152,37 +156,73 @@ class MultiHashing(DuplicateDetectionAlgorithm):
152
156
  return bool(duplicate_structure)
153
157
 
154
158
  def get_uniqueness_score(self) -> float:
155
- self._ensure_hash_vector_array()
159
+ self.pre_dda_processing()
156
160
  hash_vector = self.create_hash_vector()
161
+ self.warn_if_vector_dict_mismatch(hash_vector)
157
162
  clash_vector = np.zeros(self.perturbations, dtype=bool)
158
163
  for hash_index, hash_value in enumerate(hash_vector):
159
- if hash_value in self.hash_vector_array[: self.vector_count, hash_index]:
164
+ if hash_value in self.hash_dict[hash_index]:
160
165
  clash_vector[hash_index] = True
161
166
  uniqueness_score = 1 - np.sum(clash_vector) / self.perturbations
162
167
 
163
168
  return uniqueness_score
164
169
 
170
+
165
171
  def get_dataset_unique_structures(self) -> int:
166
172
  """Counts the number of unique structures in the dataset by checking for hash value clashes across the dataset for each perturbation.
167
173
 
168
174
  Returns:
169
175
  int: The number of unique structures in the dataset.
170
176
  """
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
177
+ self.pre_dda_processing()
178
+ u_list_of_lists = []
179
+ for i in range(self.perturbations):
180
+ u_list_of_dicts = [self.hash_dict[i][hash_value] for hash_value in self.hash_dict[i]]
181
+ u_list = [unique_index for d in u_list_of_dicts for unique_index, is_unique in d.items() if is_unique]
182
+ u_list_of_lists.append(u_list)
183
+
184
+ # count the number of times each index appears across all perturbations
185
+ index_counts = {}
186
+ for i in range(self.vector_count):
187
+ for u_list in u_list_of_lists:
188
+ if i in u_list:
189
+ if i not in index_counts:
190
+ index_counts[i] = 1
191
+ else:
192
+ index_counts[i] += 1
175
193
 
194
+ # get indexes that appear in at least acceptance_threshold * perturbations perturbations
195
+ index_filter = [index for index, count in index_counts.items() if count / self.perturbations >= self.acceptance_threshold]
196
+
197
+ # convert to boolean array for indexing
198
+ self.unique_vector_indices = np.zeros(self.vector_count, dtype=bool)
199
+ self.unique_vector_indices[index_filter] = True
200
+
176
201
  return np.sum(self.unique_vector_indices)
177
202
 
203
+ def _perturbation_array_stale(self) -> bool:
204
+ return (
205
+ self.perturbation_array.shape[0] != self.perturbations
206
+ or self.seed != getattr(self, "_hash_dict_seed", None)
207
+ )
208
+
178
209
  def pre_dda_processing(self, *args, **kwargs) -> None:
179
- self.preinitialize_dataset_array()
180
- self.set_perturbation_array()
210
+ if (
211
+ self.tolerance != getattr(self, "_hash_dict_tolerance", None)
212
+ or self._perturbation_array_stale()
213
+ ):
214
+ self._dirty = True
215
+ super().pre_dda_processing(*args, **kwargs)
216
+
217
+ def _rebuild_auxiliary_structures(self) -> None:
218
+ if self._perturbation_array_stale():
219
+ self.set_perturbation_array()
220
+ self.compute_hash_vector_dictionary()
221
+ self._hash_dict_tolerance = self.tolerance
222
+ self._hash_dict_seed = self.seed
181
223
 
182
- def add_input_vector_to_dda(self) -> None:
224
+ def _append_vector_to_structures(self) -> None:
183
225
  """Add the input vector to the dataset array and update the hash vector array accordingly."""
184
- self._ensure_hash_vector_array()
185
226
  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
227
+ self.add_input_vector_hashes_to_dictionary(self.input_vector)
188
228
  self.vector_count += 1
@@ -100,18 +100,43 @@ class NaturalTolerancePlateauProbe(ToleranceCalculator):
100
100
  sorted_tols,
101
101
  tolerance_results,
102
102
  )
103
-
103
+ print(f'plateau log: {plateau_log}')
104
+
104
105
  plateau_lengths = []
105
- for i in range(len(plateau_log)):
106
- if plateau_log[i]:
107
- if not plateau_log[i - 1]:
108
- start = i
109
- else:
110
- if plateau_log[i - 1]:
111
- end = i
112
- plateau_lengths.append(
113
- (sorted_tols[start], sorted_tols[end], end - start)
114
- )
106
+ starts=[]
107
+ ends=[]
108
+ # find starts
109
+ for i in range(1, len(plateau_log)):
110
+ if plateau_log[i] and not plateau_log[i - 1]:
111
+ starts.append(i)
112
+
113
+ # find ends
114
+ for i in range(1, len(plateau_log)):
115
+ if not plateau_log[i] and plateau_log[i - 1]:
116
+ ends.append(i)
117
+
118
+ # handle if starts and ends are mismatched due to starting or ending in a plateau
119
+ if len(starts) > len(ends):
120
+ ends.append(len(plateau_log))
121
+ elif len(ends) > len(starts):
122
+ starts.insert(0, 0)
123
+
124
+ # find lengths
125
+ for start, end in zip(starts, ends):
126
+ plateau_lengths.append(
127
+ (sorted_tols[start], sorted_tols[end], end - start)
128
+ )
129
+
130
+ # for i in range(len(plateau_log)):
131
+ # if plateau_log[i]:
132
+ # if not plateau_log[i - 1]:
133
+ # start = i
134
+ # else:
135
+ # if plateau_log[i - 1]:
136
+ # end = i
137
+ # plateau_lengths.append(
138
+ # (sorted_tols[start], sorted_tols[end], end - start)
139
+ # )
115
140
 
116
141
  return plateau_lengths
117
142
 
@@ -56,7 +56,8 @@ class PerturbedDatasetReclustering(ToleranceCalculator):
56
56
  Returns:
57
57
  float: The calculated tolerance value.
58
58
  """
59
- self._ensure_perturbed_dataset()
59
+ self.duplicate_detection_algorithm_object.pre_dda_processing()
60
+ print(self.duplicate_detection_algorithm_object.vector_count)
60
61
  if self.target_unique_vectors_threshold == "average":
61
62
  low_tolerance = self.binary_search_tolerance(
62
63
  target_unique_vectors=self.target_unique_vectors,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deduplicate_lib
3
- Version: 0.0.4
3
+ Version: 0.1.0
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