1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use linfa::Float;
#[cfg(feature = "serde")]
use serde_crate::{Deserialize, Serialize};
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate")
)]
#[derive(Clone, Debug, PartialEq)]
pub struct AppxDbscanHyperParams<F: Float> {
tolerance: F,
min_points: usize,
slack: F,
appx_tolerance: F,
}
pub struct AppxDbscanHyperParamsBuilder<F: Float> {
tolerance: F,
min_points: usize,
slack: F,
}
impl<F: Float> AppxDbscanHyperParamsBuilder<F> {
pub fn tolerance(mut self, tolerance: F) -> Self {
self.tolerance = tolerance;
self
}
pub fn slack(mut self, slack: F) -> Self {
self.slack = slack;
self
}
pub fn build(&self) -> AppxDbscanHyperParams<F> {
AppxDbscanHyperParams::build(self.tolerance, self.min_points, self.slack)
}
}
impl<F: Float> AppxDbscanHyperParams<F> {
#[allow(clippy::new_ret_no_self)]
pub fn new(min_points: usize) -> AppxDbscanHyperParamsBuilder<F> {
let default_slack = F::from(1e-2).unwrap();
let default_tolerance = F::from(1e-4).unwrap();
AppxDbscanHyperParamsBuilder {
min_points,
tolerance: default_tolerance,
slack: default_slack,
}
}
pub fn tolerance(&self) -> F {
self.tolerance
}
pub fn minimum_points(&self) -> usize {
self.min_points
}
pub fn slack(&self) -> F {
self.slack
}
pub fn appx_tolerance(&self) -> F {
self.appx_tolerance
}
fn build(tolerance: F, min_points: usize, slack: F) -> Self {
if tolerance <= F::from(0.).unwrap() {
panic!("`tolerance` must be greater than 0!");
}
if min_points <= 1 {
panic!("`min_points` must be greater than 1!");
}
if slack <= F::from(0.).unwrap() {
panic!("`slack` must be greater than 0!");
}
Self {
tolerance: tolerance,
min_points: min_points,
slack: slack,
appx_tolerance: tolerance * (F::one() + slack),
}
}
}