1#![allow(dead_code)]
2
3#[cfg(test)]
4use approx::*;
5
6pub mod clustering;
7pub mod log2cache;
8pub mod loss;
9pub mod optimize;
10pub mod psm;
11
12use crate::clustering::Clusterings;
13use dahl_partition::*;
14
15pub type CountType = u32; pub type LabelType = u16; const MAX_LABEL: u16 = u16::MAX - 1; #[derive(Copy, Clone)]
20pub enum PartitionDistributionInformation<'a> {
21 Draws(&'a Clusterings),
22 PairwiseSimilarityMatrix(&'a SquareMatrixBorrower<'a>),
23}
24
25impl<'a> PartitionDistributionInformation<'a> {
26 pub fn draws(self) -> &'a Clusterings {
27 match self {
28 PartitionDistributionInformation::Draws(d) => d,
29 _ => panic!("Not available."),
30 }
31 }
32 pub fn psm(self) -> &'a SquareMatrixBorrower<'a> {
33 match self {
34 PartitionDistributionInformation::PairwiseSimilarityMatrix(p) => p,
35 _ => panic!("Not available."),
36 }
37 }
38}
39
40#[derive(Debug, Copy, Clone)]
41pub enum LossFunction {
42 BinderDraws(f64),
43 BinderPSM,
44 OneMinusARI,
45 OneMinusARIapprox,
46 VI(f64),
47 VIlb,
48 NVI,
49 ID,
50 NID,
51}
52
53impl LossFunction {
54 pub fn from_code(x: i32, a: f64) -> Option<LossFunction> {
55 match x {
56 0 => Some(LossFunction::BinderDraws(a)),
57 1 => Some(LossFunction::BinderPSM),
58 2 => Some(LossFunction::OneMinusARI),
59 3 => Some(LossFunction::OneMinusARIapprox),
60 4 => Some(LossFunction::VI(a)),
61 5 => Some(LossFunction::VIlb),
62 6 => Some(LossFunction::NVI),
63 7 => Some(LossFunction::ID),
64 8 => Some(LossFunction::NID),
65 _ => None,
66 }
67 }
68}
69
70#[derive(Debug, Copy, Clone, PartialEq)]
71pub enum InitializationMethod {
72 SequentialFromEmpty,
73 SequentialFromSingletons,
74 SampleOne2MaxWithReplacement,
75}
76
77impl InitializationMethod {
78 pub fn to_code(&self) -> u32 {
79 match self {
80 Self::SequentialFromEmpty => 0,
81 Self::SequentialFromSingletons => 1,
82 Self::SampleOne2MaxWithReplacement => 2,
83 }
84 }
85}