From 5f694a7b09de8ad84bcf9deb7bbe048b2bbbb9f4 Mon Sep 17 00:00:00 2001 From: reinterpretcat Date: Sat, 25 Jan 2025 11:05:06 +0100 Subject: [PATCH] Use mse to avoid extra smooth in GSOM --- rosomaxa/src/algorithms/gsom/network.rs | 2 +- rosomaxa/src/population/rosomaxa.rs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/rosomaxa/src/algorithms/gsom/network.rs b/rosomaxa/src/algorithms/gsom/network.rs index 1ef9032e..2b9c393c 100644 --- a/rosomaxa/src/algorithms/gsom/network.rs +++ b/rosomaxa/src/algorithms/gsom/network.rs @@ -483,7 +483,7 @@ where } /// Returns data (weights) dimension. - pub(super) fn dimension(&self) -> usize { + pub fn dimension(&self) -> usize { self.dimension } diff --git a/rosomaxa/src/population/rosomaxa.rs b/rosomaxa/src/population/rosomaxa.rs index 9bd1ff9d..19833aa6 100644 --- a/rosomaxa/src/population/rosomaxa.rs +++ b/rosomaxa/src/population/rosomaxa.rs @@ -310,7 +310,12 @@ where network.set_learning_rate(get_learning_rate(statistics.termination_estimate)); if statistics.generation % config.rebalance_memory == 0 { - network.smooth(external_ctx, 1, |i| i.on_update(external_ctx)); + // set the MSE threshold to a fraction of the maximum possible normalized distance + let mse = network.mse(); + let threshold = 0.5 / (network.dimension() as Float).sqrt(); + if mse > threshold { + network.smooth(external_ctx, 1, |i| i.on_update(external_ctx)); + } } let keep_size = get_keep_size(config.rebalance_memory, statistics.termination_estimate);