From f314c2c59c9c92900c82ad0c73a54b2df51e4632 Mon Sep 17 00:00:00 2001 From: Stefan Kuhn Date: Tue, 20 Aug 2024 15:43:47 +0200 Subject: [PATCH] #62 Floating point numbers should not be tested for equality see SonarRule python:S1244 (https://rules.sonarsource.com/python/RSPEC-1244/) --- trackmania_rl/analysis_metrics.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/trackmania_rl/analysis_metrics.py b/trackmania_rl/analysis_metrics.py index e759fbe8..a43cba2d 100644 --- a/trackmania_rl/analysis_metrics.py +++ b/trackmania_rl/analysis_metrics.py @@ -317,7 +317,7 @@ def distribution_curves(buffer, save_dir, online_network, target_network): quantiles_output = np.sort(quantiles_output.ravel()) quantiles_target = np.sort(quantiles_target.ravel()) - if (np.min(quantiles_output) == np.max(quantiles_output)) and (np.min(quantiles_output) == 0.0): + if np.min(quantiles_output) == np.max(quantiles_output) and _is_min_close_to_zero(quantiles_output): # terminal transition, can't be interpreted as long term continue @@ -393,3 +393,7 @@ def distribution_curves(buffer, save_dir, online_network, target_network): ) ).save(save_dir / "distribution_curves" / f"{i}_{buffer.storage[i].n_steps}.png") plt.close() + + +def _is_min_close_to_zero(quantiles_output): + return np.isclose(np.min(quantiles_output), 0.0, rtol=1e-09, atol=1e-09)