KNN native parallelism and distance weighting
Compare unchanged uniform defaults with exact inverse distance votes and reusable local CPU query execution.
import aner.ml
import aner.parallel
import aner.tensor
let features = [[1.0], [2.0], [3.0]]
let labels = [[10.0], [20.0], [20.0]]
let queries = [[0.0], [1.0]]
let uniform = ml.fit_knn(features, labels, 3)
let weighted = ml.fit_knn(features, labels, 3, weights: "distance")
let execution = parallel.local()
let serial = ml.predict(weighted, queries)
let concurrent = ml.predict(weighted, queries, execution: execution,
max_workspace_bytes: 64 * 1024 * 1024)
print(tensor.value(ml.predict(uniform, queries), 0, 0))
print(tensor.value(serial, 0, 0))
print(tensor.value(concurrent, 0, 0))
print(tensor.value(concurrent, 1, 0))
let probabilities = ml.predict_proba(weighted, queries, execution: execution)
print(tensor.value(probabilities, 0, 0))
print(tensor.value(probabilities, 0, 1))
Make it your experiment.
Use the matching development runtime. Save this program as examples/knn_parallel.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/knn_parallel.aner
aner run examples/knn_parallel.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Requires the matching unreleased Aner development runtime with KNN weights, local execution and max_workspace_bytes controls. Aner 0.0.5 version text alone does not establish these capabilities. Uses CPU Float64 and an admitted local worker pool; GPU and cluster KNN are unavailable. No download, external service or output files are required.
aner check examples/knn_parallel.aner
aner run examples/knn_parallel.anerBundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution