All examples
Machine learning

Fit native p-means clusters

Fit an experimental recency closing recipe and inspect resolved settings, final distortion and query diagnostics.

pmeans_native.aner
// Complete teaching input; these timings are not a performance benchmark.
import aner.ml
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 execution = parallel.local(workers: 2)
let model = ml.fit_pmeans(features: x, clusters: 2,
    epochs: 3.0, seed: 42, execution: execution, closing_length: 0.5)
print(model.summary())
print(model.recipe())
print(model.closing_mode())
print(model.closing_length())
print(model.batch_size())
print(model.probes())
print(model.inertia())
let queries = [[0.0, 1.0], [10.0, 11.0]]
let predicted = model.predict(input: queries, execution: execution)
let distances = model.squared_distances(input: queries, execution: execution)
print(tensor.value(predicted, 0, 0))
print(tensor.value(distances, 0, 0))
print(model.score(input: queries))
let sizes = model.cluster_sizes()
print(tensor.value(sizes, 0, 0) + tensor.value(sizes, 1, 0))

Make it your experiment.

Use Aner 0.1.0 or newer. Save this program as examples/pmeans_native.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.

Terminal
aner check examples/pmeans_native.aner
aner run examples/pmeans_native.aner

The 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. Uses CPU Float64 and two local workers.

Credential setup
aner check examples/pmeans_native.aner
aner run examples/pmeans_native.aner

Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.

Dataset sources & attribution
Install Aner