pe.histogram.nearest_neighbor_backend package
Submodules
pe.histogram.nearest_neighbor_backend.auto module
- pe.histogram.nearest_neighbor_backend.auto.search(syn_embedding, priv_embedding, num_nearest_neighbors, mode)[source]
Compute the nearest neighbors of the private embedding in the synthetic embedding using Faiss. If Faiss is not installed or an error occurs, fall back to the sklearn backend.
- Parameters:
syn_embedding (np.ndarray) – The synthetic embedding
priv_embedding (np.ndarray) – The private embedding
num_nearest_neighbors (int) – The number of nearest neighbors to search
mode (str) – The distance metric to use for finding the nearest neighbors. It should be one of the following: “l2” (l2 distance), “cos_sim” (cosine similarity), “ip” (inner product, not supported by sklearn)
- Raises:
ValueError – If the mode is unknown
- Returns:
The distances and indices of the nearest neighbors
- Return type:
tuple[np.ndarray, np.ndarray]
pe.histogram.nearest_neighbor_backend.faiss module
- pe.histogram.nearest_neighbor_backend.faiss.search(syn_embedding, priv_embedding, num_nearest_neighbors, mode)[source]
Compute the nearest neighbors of the private embedding in the synthetic embedding using FAISS.
- Parameters:
syn_embedding (np.ndarray) – The synthetic embedding
priv_embedding (np.ndarray) – The private embedding
num_nearest_neighbors (int) – The number of nearest neighbors to search
mode (str) – The distance metric to use for finding the nearest neighbors. It should be one of the following: “l2” (l2 distance), “cos_sim” (cosine similarity), “ip” (inner product)
- Raises:
ValueError – If the mode is unknown
- Returns:
The distances and indices of the nearest neighbors
- Return type:
tuple[np.ndarray, np.ndarray]
pe.histogram.nearest_neighbor_backend.sklearn module
- pe.histogram.nearest_neighbor_backend.sklearn.search(syn_embedding, priv_embedding, num_nearest_neighbors, mode)[source]
Compute the nearest neighbors of the private embedding in the synthetic embedding using sklearn.
- Parameters:
syn_embedding (np.ndarray) – The synthetic embedding
priv_embedding (np.ndarray) – The private embedding
num_nearest_neighbors (int) – The number of nearest neighbors to search
mode (str) – The distance metric to use for finding the nearest neighbors. It should be one of the following: “l2” (l2 distance), “cos_sim” (cosine similarity)
- Raises:
ValueError – If the mode is unknown
- Returns:
The distances and indices of the nearest neighbors
- Return type:
tuple[np.ndarray, np.ndarray]