-
-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gaussian mixture model bench (#68)
The benchmark for the gaussian mixture model was missing
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use criterion::{ | ||
black_box, criterion_group, criterion_main, AxisScale, Criterion, ParameterizedBenchmark, | ||
PlotConfiguration, | ||
}; | ||
use linfa::traits::Fit; | ||
use linfa::Dataset; | ||
use linfa_clustering::{generate_blobs, GaussianMixtureModel}; | ||
use ndarray::Array2; | ||
use ndarray_rand::rand::SeedableRng; | ||
use ndarray_rand::rand_distr::Uniform; | ||
use ndarray_rand::RandomExt; | ||
use rand_isaac::Isaac64Rng; | ||
|
||
fn gaussian_mixture_bench(c: &mut Criterion) { | ||
let mut rng = Isaac64Rng::seed_from_u64(40); | ||
let cluster_sizes = vec![10, 100, 1000, 10000]; | ||
|
||
let benchmark = ParameterizedBenchmark::new( | ||
"gaussian_mixture", | ||
move |bencher, &cluster_size| { | ||
let n_clusters = 4; | ||
let n_features = 3; | ||
let centroids = | ||
Array2::random_using((n_clusters, n_features), Uniform::new(-30., 30.), &mut rng); | ||
let dataset = Dataset::from(generate_blobs(cluster_size, ¢roids, &mut rng)); | ||
bencher.iter(|| { | ||
black_box( | ||
GaussianMixtureModel::params(n_clusters) | ||
.with_rng(rng.clone()) | ||
.with_tolerance(1e-3) | ||
.with_max_n_iterations(1000) | ||
.fit(&dataset) | ||
.expect("GMM fitting fail"), | ||
) | ||
}); | ||
}, | ||
cluster_sizes, | ||
) | ||
.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic)); | ||
c.bench("gaussian_mixture", benchmark); | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = Criterion::default(); | ||
targets = gaussian_mixture_bench | ||
} | ||
criterion_main!(benches); |