|
kodama-cpp
Standalone float32 KODAMA kernels for CPU, CUDA, and Apple Metal
|
An installed consumer can use find_package(kodama-cpp CONFIG REQUIRED) and link kodama::kodama_cpp.
result.res stores one row-major label vector per independent run; result.acc stores its raw cross-validated accuracy. Select a run from those internal scores, not from external reference labels.
KODAMAMatrixResult owns one NeighborGraph. With the default apply_kodama_dissimilarity = true, the base distances are corrected in place and the final graph is moved into result.knn. To retain the base graph and defer correction:
The in-place function accepts the public one-based graph convention and does not allocate a second graph. result.knn_is_kodama_corrected describes the state produced by KODAMAMatrix; result.graph_storage_bytes reports the retained index-distance capacity.
The standalone preprocessing API accepts row-major training data and an optional test matrix. Test data always reuse the training PQN reference or the training centering/scaling statistics.
Normalization methods are PQN, Sum, Median, Sqrt, and None. Scaling methods are None, Centering, Autoscaling, RangeScaling, and ParetoScaling. The implementation deliberately preserves the historical KODAMA train/test conventions, including signed training sums and absolute test sums for sum normalization. Division by zero and missing-value behavior follow the original formulas; the library does not insert an epsilon or silently impute values.
Normalization_CPU and Scaling_CPU parallelize independent rows and columns. Their CUDA and Metal counterparts compute statistics, PQN medians, and transformations on device and throw when their requested backend is not compiled or available; they never fall back to CPU.
Use an explicit resident handle when several searches share one training matrix:
The move-only handle owns the device training matrix, projection, centroids, and inverted lists. Self-search does not upload the training matrix again; external queries upload only their query rows. Neighbor identifiers returned by both calls are one-based.
GraphClusterOptions::n_threads, KNNOptions::n_threads, and the wrapper argument n.cores control both native HNSW construction and querying. The implementation uses lock-protected concurrent insertion and batched parallel queries over contiguous float32 storage:
Parallel HNSW insertion is approximate and its graph can vary slightly with thread scheduling. The maintained regression test requires at least 0.99 recall against exact neighbors rather than bitwise identity with a serial graph.
Install the portable R source package from the checkout:
The matrix call builds the full-data graph once before all M searches. It also computes one PCA with the selected matrix backend, derives both UMAP and openTSNE starts from those scores, and stores the graph and starts in fit. The visualization call reuses a stored start only when its backend matches the requested embedding backend. Check fit$graph_builds (normally 1) and fit$timing$visual_init_seconds when profiling. Landmark selection is retained separately for every independent run in fit$landmark_seconds; its sum, mean, and median appear in fit$timing. Do not attribute this stage to the KNN or PLS-LDA classifier core. To visualize on another backend, pass the raw matrix so initialization is recomputed there. Native UMAP and openTSNE are available on CPU, CUDA, and Metal; no visualization backend is silently substituted for another:
An explicit init always wins. Without explicit, raw, or backend-matched stored initialization, UMAP uses its graph-spectral start and openTSNE uses its deterministic random start.
The complete installation and R CMD check procedure is in split-repos/KODAMA/inst/INSTALL.md.
kodama.matrix() stores raw-data PCA starts by default. Pass raw_data=x to kodama.visualization() when changing the CPU/CUDA/Metal visualization backend, or pass init= to provide coordinates explicitly.
CUDA is enabled with -DKODAMA_ENABLE_CUDA=ON; build and run against the same CUDA Toolkit runtime. Metal is enabled with -DKODAMA_ENABLE_METAL=ON on macOS. Call KODAMA.diagnostics() in R or kodama.diagnostics() in Python to inspect the linked wrapper environment. A requested accelerator that is absent or cannot initialize raises an error instead of changing the backend.