-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sample-replace empty drifting centroid abstractions
- Loading branch information
Showing
7 changed files
with
91 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,39 @@ | ||
use crate::clustering::histogram::Histogram; | ||
|
||
/// TODO this is now a full shallow wrapper around a Histogram | ||
/// originaly i thought we shoud separate the last and next Histograms | ||
/// but then the mutation loop changed such that it's not necessary | ||
/// | ||
/// `Centroid` is a wrapper around two histograms. | ||
/// We use it to swap the current and next histograms | ||
/// after each iteration of kmeans clustering. | ||
pub struct Centroid { | ||
last: Histogram, | ||
next: Histogram, | ||
// next: Histogram, | ||
} | ||
|
||
impl Centroid { | ||
pub fn reset(&mut self) { | ||
self.last.destroy(); | ||
std::mem::swap(&mut self.last, &mut self.next); | ||
// std::mem::swap(&mut self.last, &mut self.next); | ||
} | ||
pub fn absorb(&mut self, h: &Histogram) { | ||
self.next.absorb(h); | ||
self.last.absorb(h); | ||
// self.next.absorb(h); | ||
} | ||
pub fn reveal(&self) -> &Histogram { | ||
pub fn histogram(&self) -> &Histogram { | ||
&self.last | ||
} | ||
pub fn is_empty(&self) -> bool { | ||
self.last.is_empty() | ||
} | ||
} | ||
|
||
impl From<Histogram> for Centroid { | ||
fn from(h: Histogram) -> Self { | ||
Self { | ||
last: h, | ||
next: Histogram::default(), | ||
// next: Histogram::default(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters