Skip to content

Commit

Permalink
chore: renamed U -> T
Browse files Browse the repository at this point in the history
  • Loading branch information
nishaq503 committed Dec 12, 2024
1 parent 245f0a8 commit 25818d1
Show file tree
Hide file tree
Showing 30 changed files with 300 additions and 381 deletions.
80 changes: 40 additions & 40 deletions crates/abd-clam/benches/utils/compare_permuted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,29 @@ use measurement::WallTime;
/// - `Co`: The type of the compressible dataset.
/// - `M`: The type of the metric used to measure distances.
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
pub fn compare_permuted<I, U, M, Me>(
pub fn compare_permuted<I, T, M, Me>(
c: &mut Criterion,
metric: &M,
ball_data: (&Ball<U>, &FlatVec<I, (Me, HashMap<usize, U>)>),
balanced_ball_data: (&Ball<U>, &FlatVec<I, (Me, HashMap<usize, U>)>),
perm_ball_data: (&PermutedBall<U, Ball<U>>, &FlatVec<I, (Me, HashMap<usize, U>)>),
perm_balanced_ball_data: (&PermutedBall<U, Ball<U>>, &FlatVec<I, (Me, HashMap<usize, U>)>),
dec_ball_data: Option<(&SquishyBall<U, Ball<U>>, &CodecData<I, (Me, HashMap<usize, U>)>)>,
dec_balanced_ball_data: Option<(&SquishyBall<U, Ball<U>>, &CodecData<I, (Me, HashMap<usize, U>)>)>,
ball_data: (&Ball<T>, &FlatVec<I, (Me, HashMap<usize, T>)>),
balanced_ball_data: (&Ball<T>, &FlatVec<I, (Me, HashMap<usize, T>)>),
perm_ball_data: (&PermutedBall<T, Ball<T>>, &FlatVec<I, (Me, HashMap<usize, T>)>),
perm_balanced_ball_data: (&PermutedBall<T, Ball<T>>, &FlatVec<I, (Me, HashMap<usize, T>)>),
dec_ball_data: Option<(&SquishyBall<T, Ball<T>>, &CodecData<I, (Me, HashMap<usize, T>)>)>,
dec_balanced_ball_data: Option<(&SquishyBall<T, Ball<T>>, &CodecData<I, (Me, HashMap<usize, T>)>)>,
queries: &[I],
radii: &[U],
radii: &[T],
ks: &[usize],
par_only: bool,
) where
I: Encodable + Decodable + Send + Sync,
U: Number + 'static,
M: ParMetric<I, U>,
T: Number + 'static,
M: ParMetric<I, T>,
Me: Send + Sync,
{
let mut algs: Vec<(
Box<dyn ParSearchAlgorithm<I, U, Ball<U>, M, FlatVec<I, (Me, HashMap<usize, U>)>>>,
Box<dyn ParSearchAlgorithm<I, U, PermutedBall<U, Ball<U>>, M, FlatVec<I, (Me, HashMap<usize, U>)>>>,
Option<Box<dyn ParSearchAlgorithm<I, U, SquishyBall<U, Ball<U>>, M, CodecData<I, (Me, HashMap<usize, U>)>>>>,
Box<dyn ParSearchAlgorithm<I, T, Ball<T>, M, FlatVec<I, (Me, HashMap<usize, T>)>>>,
Box<dyn ParSearchAlgorithm<I, T, PermutedBall<T, Ball<T>>, M, FlatVec<I, (Me, HashMap<usize, T>)>>>,
Option<Box<dyn ParSearchAlgorithm<I, T, SquishyBall<T, Ball<T>>, M, CodecData<I, (Me, HashMap<usize, T>)>>>>,
)> = Vec::new();
for &radius in radii {
algs.push((
Expand All @@ -89,9 +89,9 @@ pub fn compare_permuted<I, U, M, Me>(
Some(Box::new(KnnLinear(k))),
));
algs.push((
Box::new(KnnRepeatedRnn(k, U::ONE.double())),
Box::new(KnnRepeatedRnn(k, U::ONE.double())),
Some(Box::new(KnnRepeatedRnn(k, U::ONE.double()))),
Box::new(KnnRepeatedRnn(k, T::ONE.double())),
Box::new(KnnRepeatedRnn(k, T::ONE.double())),
Some(Box::new(KnnRepeatedRnn(k, T::ONE.double()))),
));
algs.push((
Box::new(KnnBreadthFirst(k)),
Expand Down Expand Up @@ -150,26 +150,26 @@ pub fn compare_permuted<I, U, M, Me>(
}
}

fn bench_cakes<I, U, M, A1, A2, A3, Me>(
fn bench_cakes<I, T, M, A1, A2, A3, Me>(
group: &mut BenchmarkGroup<WallTime>,
alg_1: &A1,
alg_2: &A2,
alg_3: Option<&A3>,
metric: &M,
queries: &[I],
(ball, data): (&Ball<U>, &FlatVec<I, (Me, HashMap<usize, U>)>),
(balanced_ball, balanced_data): (&Ball<U>, &FlatVec<I, (Me, HashMap<usize, U>)>),
(perm_ball, perm_data): (&PermutedBall<U, Ball<U>>, &FlatVec<I, (Me, HashMap<usize, U>)>),
(perm_balanced_ball, perm_balanced_data): (&PermutedBall<U, Ball<U>>, &FlatVec<I, (Me, HashMap<usize, U>)>),
dec_ball_data: Option<(&SquishyBall<U, Ball<U>>, &CodecData<I, (Me, HashMap<usize, U>)>)>,
dec_balanced_ball_data: Option<(&SquishyBall<U, Ball<U>>, &CodecData<I, (Me, HashMap<usize, U>)>)>,
(ball, data): (&Ball<T>, &FlatVec<I, (Me, HashMap<usize, T>)>),
(balanced_ball, balanced_data): (&Ball<T>, &FlatVec<I, (Me, HashMap<usize, T>)>),
(perm_ball, perm_data): (&PermutedBall<T, Ball<T>>, &FlatVec<I, (Me, HashMap<usize, T>)>),
(perm_balanced_ball, perm_balanced_data): (&PermutedBall<T, Ball<T>>, &FlatVec<I, (Me, HashMap<usize, T>)>),
dec_ball_data: Option<(&SquishyBall<T, Ball<T>>, &CodecData<I, (Me, HashMap<usize, T>)>)>,
dec_balanced_ball_data: Option<(&SquishyBall<T, Ball<T>>, &CodecData<I, (Me, HashMap<usize, T>)>)>,
) where
I: Encodable + Decodable,
U: Number,
M: Metric<I, U>,
A1: SearchAlgorithm<I, U, Ball<U>, M, FlatVec<I, (Me, HashMap<usize, U>)>>,
A2: SearchAlgorithm<I, U, PermutedBall<U, Ball<U>>, M, FlatVec<I, (Me, HashMap<usize, U>)>>,
A3: SearchAlgorithm<I, U, SquishyBall<U, Ball<U>>, M, CodecData<I, (Me, HashMap<usize, U>)>>,
T: Number,
M: Metric<I, T>,
A1: SearchAlgorithm<I, T, Ball<T>, M, FlatVec<I, (Me, HashMap<usize, T>)>>,
A2: SearchAlgorithm<I, T, PermutedBall<T, Ball<T>>, M, FlatVec<I, (Me, HashMap<usize, T>)>>,
A3: SearchAlgorithm<I, T, SquishyBall<T, Ball<T>>, M, CodecData<I, (Me, HashMap<usize, T>)>>,
{
let parameter = if alg_1.k() > 0 {
alg_1.k()
Expand Down Expand Up @@ -206,26 +206,26 @@ fn bench_cakes<I, U, M, A1, A2, A3, Me>(
}
}

fn par_bench_cakes<I, U, M, A1, A2, A3, Me>(
fn par_bench_cakes<I, T, M, A1, A2, A3, Me>(
group: &mut BenchmarkGroup<WallTime>,
alg_1: &A1,
alg_2: &A2,
alg_3: Option<&A3>,
metric: &M,
queries: &[I],
(ball, data): (&Ball<U>, &FlatVec<I, (Me, HashMap<usize, U>)>),
(balanced_ball, balanced_data): (&Ball<U>, &FlatVec<I, (Me, HashMap<usize, U>)>),
(perm_ball, perm_data): (&PermutedBall<U, Ball<U>>, &FlatVec<I, (Me, HashMap<usize, U>)>),
(perm_balanced_ball, perm_balanced_data): (&PermutedBall<U, Ball<U>>, &FlatVec<I, (Me, HashMap<usize, U>)>),
dec_ball_data: Option<(&SquishyBall<U, Ball<U>>, &CodecData<I, (Me, HashMap<usize, U>)>)>,
dec_balanced_ball_data: Option<(&SquishyBall<U, Ball<U>>, &CodecData<I, (Me, HashMap<usize, U>)>)>,
(ball, data): (&Ball<T>, &FlatVec<I, (Me, HashMap<usize, T>)>),
(balanced_ball, balanced_data): (&Ball<T>, &FlatVec<I, (Me, HashMap<usize, T>)>),
(perm_ball, perm_data): (&PermutedBall<T, Ball<T>>, &FlatVec<I, (Me, HashMap<usize, T>)>),
(perm_balanced_ball, perm_balanced_data): (&PermutedBall<T, Ball<T>>, &FlatVec<I, (Me, HashMap<usize, T>)>),
dec_ball_data: Option<(&SquishyBall<T, Ball<T>>, &CodecData<I, (Me, HashMap<usize, T>)>)>,
dec_balanced_ball_data: Option<(&SquishyBall<T, Ball<T>>, &CodecData<I, (Me, HashMap<usize, T>)>)>,
) where
I: Encodable + Decodable + Send + Sync,
U: Number,
M: ParMetric<I, U>,
A1: ParSearchAlgorithm<I, U, Ball<U>, M, FlatVec<I, (Me, HashMap<usize, U>)>>,
A2: ParSearchAlgorithm<I, U, PermutedBall<U, Ball<U>>, M, FlatVec<I, (Me, HashMap<usize, U>)>>,
A3: ParSearchAlgorithm<I, U, SquishyBall<U, Ball<U>>, M, CodecData<I, (Me, HashMap<usize, U>)>>,
T: Number,
M: ParMetric<I, T>,
A1: ParSearchAlgorithm<I, T, Ball<T>, M, FlatVec<I, (Me, HashMap<usize, T>)>>,
A2: ParSearchAlgorithm<I, T, PermutedBall<T, Ball<T>>, M, FlatVec<I, (Me, HashMap<usize, T>)>>,
A3: ParSearchAlgorithm<I, T, SquishyBall<T, Ball<T>>, M, CodecData<I, (Me, HashMap<usize, T>)>>,
Me: Send + Sync,
{
let parameter = if alg_1.k() > 0 {
Expand Down
22 changes: 11 additions & 11 deletions crates/abd-clam/src/chaoda/cluster/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::{
#[derive(Serialize, Deserialize)]
pub struct Vertex<T: Number, S: Cluster<T>> {
/// The `Cluster` that was adapted into the `Vertex`.
source: S,
pub(crate) source: S,
/// The children of the `Vertex`.
children: Vec<(usize, T, Box<Self>)>,
/// The anomaly detection properties of the `Vertex`.
Expand Down Expand Up @@ -219,26 +219,26 @@ fn child_params<T: Number, C: Cluster<T>>(parent: &Ratios, child: &C) -> Ratios
}
}

impl<I, U: Number, D: Dataset<I>> BallAdapter<I, U, D, D, Ratios> for Vertex<U, Ball<U>> {
impl<I, T: Number, D: Dataset<I>> BallAdapter<I, T, D, D, Ratios> for Vertex<T, Ball<T>> {
/// Creates a new `OffsetBall` tree from a `Ball` tree.
fn from_ball_tree<M: Metric<I, U>>(ball: Ball<U>, data: D, metric: &M) -> (Self, D) {
fn from_ball_tree<M: Metric<I, T>>(ball: Ball<T>, data: D, metric: &M) -> (Self, D) {
let root = Self::adapt_tree(ball, None, &data, metric);
(root, data)
}
}

impl<I: Send + Sync, U: Number, D: ParDataset<I>> ParBallAdapter<I, U, D, D, Ratios> for Vertex<U, Ball<U>> {
impl<I: Send + Sync, T: Number, D: ParDataset<I>> ParBallAdapter<I, T, D, D, Ratios> for Vertex<T, Ball<T>> {
/// Creates a new `OffsetBall` tree from a `Ball` tree.
fn par_from_ball_tree<M: ParMetric<I, U>>(ball: Ball<U>, data: D, metric: &M) -> (Self, D) {
fn par_from_ball_tree<M: ParMetric<I, T>>(ball: Ball<T>, data: D, metric: &M) -> (Self, D) {
let root = Self::par_adapt_tree(ball, None, &data, metric);
(root, data)
}
}

impl<I, U: Number, D: Dataset<I>, S: Cluster<U>> Adapter<I, U, D, D, S, Ratios> for Vertex<U, S> {
fn new_adapted<M: Metric<I, U>>(
impl<I, T: Number, D: Dataset<I>, S: Cluster<T>> Adapter<I, T, D, D, S, Ratios> for Vertex<T, S> {
fn new_adapted<M: Metric<I, T>>(
source: S,
children: Vec<(usize, U, Box<Self>)>,
children: Vec<(usize, T, Box<Self>)>,
params: Ratios,
_: &D,
_: &M,
Expand Down Expand Up @@ -269,10 +269,10 @@ impl<I, U: Number, D: Dataset<I>, S: Cluster<U>> Adapter<I, U, D, D, S, Ratios>
}
}

impl<I: Send + Sync, U: Number, D: ParDataset<I>, S: ParCluster<U>> ParAdapter<I, U, D, D, S, Ratios> for Vertex<U, S> {
fn par_new_adapted<M: ParMetric<I, U>>(
impl<I: Send + Sync, T: Number, D: ParDataset<I>, S: ParCluster<T>> ParAdapter<I, T, D, D, S, Ratios> for Vertex<T, S> {
fn par_new_adapted<M: ParMetric<I, T>>(
source: S,
children: Vec<(usize, U, Box<Self>)>,
children: Vec<(usize, T, Box<Self>)>,
params: Ratios,
data: &D,
metric: &M,
Expand Down
54 changes: 27 additions & 27 deletions crates/abd-clam/src/chaoda/inference/combination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ impl TrainedCombination {
}

/// Get the meta-ML scorer function in a callable for any number of `Vertex`es.
pub fn meta_ml_scorer<U, S>(&self) -> impl Fn(&[&Vertex<U, S>]) -> Vec<f32> + '_
pub fn meta_ml_scorer<T, S>(&self) -> impl Fn(&[&Vertex<T, S>]) -> Vec<f32> + '_
where
U: Number,
S: Cluster<U>,
T: Number,
S: Cluster<T>,
{
move |clusters| {
let props = clusters.iter().flat_map(|c| c.ratios()).collect::<Vec<_>>();
Expand All @@ -86,18 +86,18 @@ impl TrainedCombination {

/// Create a `Graph` from the `root` with the given `data` and `min_depth`
/// using the `TrainedMetaMLModel`.
pub fn create_graph<'a, I, U, D, M, S>(
pub fn create_graph<'a, I, T, D, M, S>(
&self,
root: &'a Vertex<U, S>,
root: &'a Vertex<T, S>,
data: &D,
metric: &M,
min_depth: usize,
) -> Graph<'a, U, S>
) -> Graph<'a, T, S>
where
U: Number,
T: Number,
D: Dataset<I>,
M: Metric<I, U>,
S: Cluster<U>,
M: Metric<I, T>,
S: Cluster<T>,
{
let cluster_scorer = self.meta_ml_scorer();
Graph::from_root(root, data, metric, cluster_scorer, min_depth)
Expand All @@ -116,18 +116,18 @@ impl TrainedCombination {
/// A tuple of:
/// * The `Graph` constructed from the `root`.
/// * The anomaly scores of the points in the `data`.
pub fn predict<'a, I, U, D, M, S>(
pub fn predict<'a, I, T, D, M, S>(
&self,
root: &'a Vertex<U, S>,
root: &'a Vertex<T, S>,
data: &D,
metric: &M,
min_depth: usize,
) -> (Graph<'a, U, S>, Vec<f32>)
) -> (Graph<'a, T, S>, Vec<f32>)
where
U: Number,
T: Number,
D: Dataset<I>,
M: Metric<I, U>,
S: Cluster<U>,
M: Metric<I, T>,
S: Cluster<T>,
{
ftlog::debug!("Predicting with {}...", self.name());

Expand All @@ -144,38 +144,38 @@ impl TrainedCombination {
}

/// Parallel version of `create_graph`.
pub fn par_create_graph<'a, I, U, D, M, S>(
pub fn par_create_graph<'a, I, T, D, M, S>(
&self,
root: &'a Vertex<U, S>,
root: &'a Vertex<T, S>,
data: &D,
metric: &M,
min_depth: usize,
) -> Graph<'a, U, S>
) -> Graph<'a, T, S>
where
I: Send + Sync,
U: Number,
T: Number,
D: ParDataset<I>,
M: ParMetric<I, U>,
S: ParCluster<U>,
M: ParMetric<I, T>,
S: ParCluster<T>,
{
let cluster_scorer = self.meta_ml_scorer();
Graph::par_from_root(root, data, metric, cluster_scorer, min_depth)
}

/// Parallel version of `predict`.
pub fn par_predict<'a, I, U, D, M, S>(
pub fn par_predict<'a, I, T, D, M, S>(
&self,
root: &'a Vertex<U, S>,
root: &'a Vertex<T, S>,
data: &D,
metric: &M,
min_depth: usize,
) -> (Graph<'a, U, S>, Vec<f32>)
) -> (Graph<'a, T, S>, Vec<f32>)
where
I: Send + Sync,
U: Number,
T: Number,
D: ParDataset<I>,
M: ParMetric<I, U>,
S: ParCluster<U>,
M: ParMetric<I, T>,
S: ParCluster<T>,
{
ftlog::debug!("Predicting with {}...", self.name());

Expand Down
Loading

0 comments on commit 25818d1

Please sign in to comment.