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
#![allow(dead_code)]
#[cfg(test)]
use approx::*;
pub mod clustering;
pub mod log2cache;
pub mod loss;
pub mod optimize;
pub mod psm;
use crate::clustering::Clusterings;
use dahl_partition::*;
pub type CountType = u32;
pub type LabelType = u16;
const MAX_LABEL: u16 = u16::MAX - 1;
#[derive(Copy, Clone)]
pub enum PartitionDistributionInformation<'a> {
Draws(&'a Clusterings),
PairwiseSimilarityMatrix(&'a SquareMatrixBorrower<'a>),
}
impl<'a> PartitionDistributionInformation<'a> {
pub fn draws(self) -> &'a Clusterings {
match self {
PartitionDistributionInformation::Draws(d) => d,
_ => panic!("Not available."),
}
}
pub fn psm(self) -> &'a SquareMatrixBorrower<'a> {
match self {
PartitionDistributionInformation::PairwiseSimilarityMatrix(p) => p,
_ => panic!("Not available."),
}
}
}
#[derive(Debug, Copy, Clone)]
pub enum LossFunction {
BinderDraws(f64),
BinderPSM,
OneMinusARI,
OneMinusARIapprox,
VI(f64),
VIlb,
NVI,
ID,
NID,
}
impl LossFunction {
pub fn from_code(x: i32, a: f64) -> Option<LossFunction> {
match x {
0 => Some(LossFunction::BinderDraws(a)),
1 => Some(LossFunction::BinderPSM),
2 => Some(LossFunction::OneMinusARI),
3 => Some(LossFunction::OneMinusARIapprox),
4 => Some(LossFunction::VI(a)),
5 => Some(LossFunction::VIlb),
6 => Some(LossFunction::NVI),
7 => Some(LossFunction::ID),
8 => Some(LossFunction::NID),
_ => None,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum InitializationMethod {
SequentialFromEmpty,
SequentialFromSingletons,
SampleOne2MaxWithReplacement,
}
impl InitializationMethod {
pub fn to_code(&self) -> u32 {
match self {
Self::SequentialFromEmpty => 0,
Self::SequentialFromSingletons => 1,
Self::SampleOne2MaxWithReplacement => 2,
}
}
}