From 8745886b259fbea291ee021906921c0068fc4224 Mon Sep 17 00:00:00 2001 From: Thibault Hallouin <thibault.hallouin@inrae.fr> Date: Tue, 7 Feb 2023 08:57:55 +0100 Subject: [PATCH] deal with 0 divide in skill scores to return -INF in particular, BSS was returning 0 when BS reference was null, but 0 is a meaningful value for such score, so it is preferable to return -INF to indicate that the denominator was null and hence the division undefined the same philosophy is also used where relevant (i.e. in AWN, AWI, WSS) --- include/evalhyd/detail/probabilist/brier.hpp | 4 +++- include/evalhyd/detail/probabilist/intervals.hpp | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/evalhyd/detail/probabilist/brier.hpp b/include/evalhyd/detail/probabilist/brier.hpp index 626b71a..51554ad 100644 --- a/include/evalhyd/detail/probabilist/brier.hpp +++ b/include/evalhyd/detail/probabilist/brier.hpp @@ -5,6 +5,8 @@ #ifndef EVALHYD_PROBABILIST_BRIER_HPP #define EVALHYD_PROBABILIST_BRIER_HPP +#include <limits> + #include <xtensor/xtensor.hpp> #include <xtensor/xview.hpp> #include <xtensor/xmasked_view.hpp> @@ -790,7 +792,7 @@ namespace evalhyd xt::nanmean( xt::where( xt::equal(bs_ref, 0), - 0, + - std::numeric_limits<double>::infinity(), 1 - (bs_masked_sampled / bs_ref) ), -1 diff --git a/include/evalhyd/detail/probabilist/intervals.hpp b/include/evalhyd/detail/probabilist/intervals.hpp index d1f451e..8d30246 100644 --- a/include/evalhyd/detail/probabilist/intervals.hpp +++ b/include/evalhyd/detail/probabilist/intervals.hpp @@ -5,6 +5,8 @@ #ifndef EVALHYD_PROBABILIST_INTERVALS_HPP #define EVALHYD_PROBABILIST_INTERVALS_HPP +#include <limits> + #include <xtensor/xtensor.hpp> #include <xtensor/xview.hpp> #include <xtensor/xindex_view.hpp> @@ -470,7 +472,9 @@ namespace evalhyd } } - return (AW / mean_obs); + return xt::where(mean_obs > 0, + AW / mean_obs, + - std::numeric_limits<double>::infinity()); } /// Compute the Average Width Index (AWI). @@ -496,7 +500,9 @@ namespace evalhyd - xt::view(clim_bnds, xt::all(), xt::all(), xt::all(), xt::all(), xt::all(), 0); - return 1 - (AW / AW_clim); + return xt::where(AW_clim > 0, + 1 - (AW / AW_clim), + - std::numeric_limits<double>::infinity()); } /// Compute the Winkler scores (WS), also known as interval score. @@ -623,7 +629,9 @@ namespace evalhyd } // compute the Winkler skill score - return 1 - (WS / WS_clim); + return xt::where(WS_clim > 0, + 1 - (WS / WS_clim), + - std::numeric_limits<double>::infinity()); } } } -- GitLab