Skip to content

Commit ad84778

Browse files
committed
fix(knng): fix recall calculation for the knng example
1 parent 227c99d commit ad84778

3 files changed

Lines changed: 12 additions & 15 deletions

File tree

‎cpp/bench/CMakeLists.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ endif()
1111

1212
add_executable(bench_static_data ${PROJECT_SOURCE_DIR}/src/bench_static_data.cpp)
1313
target_include_directories(bench_static_data PRIVATE ${PROJECT_SOURCE_DIR}/include)
14-
target_link_libraries(bench_static_data PUBLIC DEG_LIB compile-options fmt::fmt-header-only)
14+
target_link_libraries(bench_static_data PUBLIC DEG_LIB compile-options fmt::fmt)
1515
target_compile_definitions(bench_static_data PUBLIC "DATA_PATH=\"${DATA_PATH}\"")
1616

1717
add_executable(bench_dynamic_data ${PROJECT_SOURCE_DIR}/src/bench_dynamic_data.cpp)
1818
target_include_directories(bench_dynamic_data PRIVATE ${PROJECT_SOURCE_DIR}/include)
19-
target_link_libraries(bench_dynamic_data PUBLIC DEG_LIB compile-options fmt::fmt-header-only)
19+
target_link_libraries(bench_dynamic_data PUBLIC DEG_LIB compile-options fmt::fmt)
2020
target_compile_definitions(bench_dynamic_data PUBLIC "DATA_PATH=\"${DATA_PATH}\"")

‎cpp/deglib/include/deglib/graph/sizebounded_graph.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ class SizeBoundedGraph : public deglib::graph::MutableGraph {
732732
/**
733733
* Load the graph
734734
*/
735-
auto load_sizebounded_graph(const char* path_graph, uint32_t new_max_size = 0)
735+
inline auto load_sizebounded_graph(const char* path_graph, uint32_t new_max_size = 0)
736736
{
737737
std::error_code ec{};
738738
auto file_size = std::filesystem::file_size(path_graph, ec);

‎examples/knng/main.py‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,15 @@
2626
from deglib.distances import FloatSpace, Metric, quantize_batch
2727
from dataset_utils import load_hdf5_dataset, ensure_small_dataset, DEFAULT_CACHE_DIR
2828

29-
3029
DEFAULT_K_TOP = 15
31-
DEFAULT_K_GRAPH = 18
32-
DEFAULT_K_EXT = 41
33-
DEFAULT_NON_ZEROS = 768
34-
DEFAULT_MAX_DIST = 586
35-
DEFAULT_EVP_K = 78
36-
DEFAULT_PRUNE_WORST = 9
30+
DEFAULT_K_GRAPH = 16
31+
DEFAULT_K_EXT = 32
32+
DEFAULT_NON_ZEROS = 700
33+
DEFAULT_MAX_DIST = 400
34+
DEFAULT_EVP_K = 50
35+
DEFAULT_PRUNE_WORST = 6
3736
DEFAULT_THREADS = 8
3837

39-
4038
def prune_worst_edges(graph: deglib.DynamicExplorationGraph, prune_worst: int) -> None:
4139
"""
4240
Prunes the worst (highest-weight) `prune_worst` neighbors of each vertex
@@ -73,9 +71,6 @@ def construct_knng(
7371
Constructs and evaluates a k-Nearest Neighbor Graph (k-NNG) using DEG.
7472
"""
7573
n_vecs, dims = train_vectors.shape
76-
if train_vectors.dtype == np.float16:
77-
train_vectors = train_vectors.view(np.uint16)
78-
7974
print(f"Dataset shape: {n_vecs} vectors, {dims} dimensions (dtype: {train_vectors.dtype})")
8075
print(f"k-NNG Construction Config: k_top={k_top}, k_graph={k_graph}, non_zeros={non_zeros}, max_dist={max_dist}, evp_k={evp_k}, prune_worst={prune_worst}, threads={threads}")
8176

@@ -142,7 +137,9 @@ def construct_knng(
142137
correct = 0
143138
total_gt = 0
144139
for i in range(n_vecs):
145-
gt_set = set(ground_truth[i, :k_top])
140+
# Ground truth list clean-up: remove self-references (i) if present
141+
gt_row = [idx for idx in ground_truth[i] if idx != i][:k_top]
142+
gt_set = set(gt_row)
146143
pred_set = set(final_knng_edges[i])
147144
correct += len(gt_set.intersection(pred_set))
148145
total_gt += len(gt_set)

0 commit comments

Comments
 (0)