Skip to content

Commit

Permalink
create new function for intersection and union size
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Aug 3, 2020
1 parent 16fdbbb commit 884454c
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions src/core/src/sketch/nodegraph.rs
Expand Up @@ -303,38 +303,42 @@ impl Comparable<&Nodegraph> for Nodegraph {

impl Comparable<Nodegraph> for Nodegraph {
fn similarity(&self, other: &Nodegraph) -> f64 {
let intersection: usize = self
.bs
.iter()
.zip(&other.bs)
.map(|(bs, bs_other)| bs.intersection(bs_other).count())
.sum();
let union: usize = self
.bs
.iter()
.zip(&other.bs)
.map(|(bs, bs_other)| bs.union(bs_other).count())
.sum();
intersection as f64 / union as f64
intersection_size(&self, &other) as f64 / union_size(&self, &other) as f64
}

fn containment(&self, other: &Nodegraph) -> f64 {
let result: usize = self
.bs
.iter()
.zip(&other.bs)
.map(|(bs, bs_other)| {
bs.as_slice()
.iter()
.zip(bs_other.as_slice().iter())
.map(|(x, y)| (x & y).count_ones() as usize)
.sum::<usize>()
})
.sum();
result as f64 / self.occupied_bins as f64
intersection_size(&self, &other) as f64 / self.occupied_bins as f64
}
}

fn intersection_size(me: &Nodegraph, other: &Nodegraph) -> usize {
me.bs
.iter()
.zip(&other.bs)
.map(|(bs, bs_other)| {
bs.as_slice()
.iter()
.zip(bs_other.as_slice().iter())
.map(|(x, y)| (x & y).count_ones() as usize)
.sum::<usize>()
})
.sum()
}

fn union_size(me: &Nodegraph, other: &Nodegraph) -> usize {
me.bs
.iter()
.zip(&other.bs)
.map(|(bs, bs_other)| {
bs.as_slice()
.iter()
.zip(bs_other.as_slice().iter())
.map(|(x, y)| (x | y).count_ones() as usize)
.sum::<usize>()
})
.sum()
}

impl Comparable<KmerMinHash> for Nodegraph {
fn similarity(&self, other: &KmerMinHash) -> f64 {
unimplemented!()
Expand Down

0 comments on commit 884454c

Please sign in to comment.