Skip to content

Commit 09d9205

Browse files
Mec-iSmorenol
authored andcommitted
Add example for FastPair (#144)
* Add example * Move to top * Add imports to example * Fix imports
1 parent dc7f01d commit 09d9205

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/algorithm/neighbour/fastpair.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
#![allow(non_snake_case)]
22
use itertools::Itertools;
33
///
4-
/// FastPair: Data-structure for the dynamic closest-pair problem.
4+
/// # FastPair: Data-structure for the dynamic closest-pair problem.
55
///
66
/// Reference:
77
/// Eppstein, David: Fast hierarchical clustering and other applications of
88
/// dynamic closest pairs. Journal of Experimental Algorithmics 5 (2000) 1.
99
///
10+
/// Example:
11+
/// ```
12+
/// use smartcore::algorithm::neighbour::distances::PairwiseDistance;
13+
/// use smartcore::linalg::naive::dense_matrix::DenseMatrix;
14+
/// use smartcore::algorithm::neighbour::fastpair::FastPair;
15+
/// let x = DenseMatrix::<f64>::from_2d_array(&[
16+
/// &[5.1, 3.5, 1.4, 0.2],
17+
/// &[4.9, 3.0, 1.4, 0.2],
18+
/// &[4.7, 3.2, 1.3, 0.2],
19+
/// &[4.6, 3.1, 1.5, 0.2],
20+
/// &[5.0, 3.6, 1.4, 0.2],
21+
/// &[5.4, 3.9, 1.7, 0.4],
22+
/// ]);
23+
/// let fastpair = FastPair::new(&x);
24+
/// let closest_pair: PairwiseDistance<f64> = fastpair.unwrap().closest_pair();
25+
/// ```
26+
/// <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
27+
/// <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
1028
use std::collections::HashMap;
1129

1230
use crate::algorithm::neighbour::distances::PairwiseDistance;
@@ -16,9 +34,7 @@ use crate::math::distance::euclidian::Euclidian;
1634
use crate::math::num::RealNumber;
1735

1836
///
19-
/// FastPair
20-
///
21-
/// Ported from Python implementation:
37+
/// Inspired by Python implementation:
2238
/// <https://github.com/carsonfarmer/fastpair/blob/b8b4d3000ab6f795a878936667eee1b557bf353d/fastpair/base.py>
2339
/// MIT License (MIT) Copyright (c) 2016 Carson Farmer
2440
///

0 commit comments

Comments
 (0)