From 3d2f4f71fa6a9c15df154d4ed90a8e75b995a92a Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Wed, 24 Aug 2022 13:40:22 +0100 Subject: [PATCH] Add example for FastPair (#144) * Add example * Move to top * Add imports to example * Fix imports --- src/algorithm/neighbour/fastpair.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/algorithm/neighbour/fastpair.rs b/src/algorithm/neighbour/fastpair.rs index dfc6f58..e14c2b3 100644 --- a/src/algorithm/neighbour/fastpair.rs +++ b/src/algorithm/neighbour/fastpair.rs @@ -1,12 +1,30 @@ #![allow(non_snake_case)] use itertools::Itertools; /// -/// FastPair: Data-structure for the dynamic closest-pair problem. +/// # FastPair: Data-structure for the dynamic closest-pair problem. /// /// Reference: /// Eppstein, David: Fast hierarchical clustering and other applications of /// dynamic closest pairs. Journal of Experimental Algorithmics 5 (2000) 1. /// +/// Example: +/// ``` +/// use smartcore::algorithm::neighbour::distances::PairwiseDistance; +/// use smartcore::linalg::naive::dense_matrix::DenseMatrix; +/// use smartcore::algorithm::neighbour::fastpair::FastPair; +/// let x = DenseMatrix::::from_2d_array(&[ +/// &[5.1, 3.5, 1.4, 0.2], +/// &[4.9, 3.0, 1.4, 0.2], +/// &[4.7, 3.2, 1.3, 0.2], +/// &[4.6, 3.1, 1.5, 0.2], +/// &[5.0, 3.6, 1.4, 0.2], +/// &[5.4, 3.9, 1.7, 0.4], +/// ]); +/// let fastpair = FastPair::new(&x); +/// let closest_pair: PairwiseDistance = fastpair.unwrap().closest_pair(); +/// ``` +/// +/// use std::collections::HashMap; use crate::algorithm::neighbour::distances::PairwiseDistance; @@ -16,9 +34,7 @@ use crate::math::distance::euclidian::Euclidian; use crate::math::num::RealNumber; /// -/// FastPair -/// -/// Ported from Python implementation: +/// Inspired by Python implementation: /// /// MIT License (MIT) Copyright (c) 2016 Carson Farmer ///