Run p-means on Apple Metal
Place Float32 tensors on M2 explicitly and inspect native p-means closing policy and exhaustive query distances.
// Requires an Apple Silicon development runtime with native Metal clustering.
import aner.ml
import aner.nn
import aner.tensor
import aner.parallel
let x = [[0.0, 0.0], [0.0, 2.0], [10.0, 10.0], [10.0, 12.0]]
let device_x = nn.to(x.astype("Float32"), "mps")
let execution = parallel.local(workers: 4)
let model = ml.fit_pmeans(device_x, 2, 3.0, 42,
execution: execution, closing_length: 0.5)
print(model.summary())
print(model.device())
print(model.closing_mode())
print(model.closing_length())
let query = nn.to([[0.0, 1.0]].astype("Float32"), "mps")
let predicted = model.predict(input: query)
let distances = model.squared_distances(input: query)
print(tensor.value(predicted, 0, 0))
print(tensor.value(distances, 0, 0))
print(model.score(input: query))
Make it your experiment.
Use Aner 0.1.0 or newer. Save this program as examples/pmeans_mps.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/pmeans_mps.aner
aner run examples/pmeans_mps.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Requires Aner 0.1.0 or newer. Complete synthetic tensors are included; no network download, credentials, external service or output file is required. Requires Apple Silicon and the native Metal Float32 clustering backend; Tensor placement explicitly selects mps.
aner check examples/pmeans_mps.aner
aner run examples/pmeans_mps.anerBundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution