diff --git a/include/evalhyd/probabilist.hpp b/include/evalhyd/probabilist.hpp index f66ade2b033a351acf986c0e5e7db7fa914d69c2..95cfdd914dc1a81203450fd25259290e099f1073 100644 --- a/include/evalhyd/probabilist.hpp +++ b/include/evalhyd/probabilist.hpp @@ -42,7 +42,7 @@ namespace evalhyd // check that the metrics to be computed are valid utils::check_metrics( metrics, - {"bs", "bss", "bs_crd", "bs_lbd", "QS", "CRPS"} + {"BS", "BSS", "BS_CRD", "BS_LBD", "QS", "CRPS"} ); // instantiate probabilist evaluator @@ -53,14 +53,14 @@ namespace evalhyd std::unordered_map<std::string, std::vector<std::string>> dep; // register potentially recurring computation elements across metrics - elt["bs"] = {"o_k", "y_k"}; - elt["bss"] = {"o_k", "bar_o"}; - elt["bs_crd"] = {"o_k", "bar_o", "y_k"}; - elt["bs_lbd"] = {"o_k", "y_k"}; - elt["qs"] = {"q_qnt"}; + elt["BS"] = {"o_k", "y_k"}; + elt["BSS"] = {"o_k", "bar_o"}; + elt["BS_CRD"] = {"o_k", "bar_o", "y_k"}; + elt["BS_LBD"] = {"o_k", "y_k"}; + elt["QS"] = {"q_qnt"}; // register nested metrics (i.e. metric dependent on another metric) - dep["bss"] = {"bs"}; + dep["BSS"] = {"BS"}; dep["QS"] = {"qs"}; dep["CRPS"] = {"qs", "crps"}; @@ -86,8 +86,8 @@ namespace evalhyd // pre-compute required dep for (const auto& dependency : req_dep) { - if ( dependency == "bs" ) - evaluator.calc_bs(); + if ( dependency == "BS" ) + evaluator.calc_BS(); else if ( dependency == "qs" ) evaluator.calc_qs(); else if ( dependency == "crps" ) @@ -99,33 +99,33 @@ namespace evalhyd for (const auto& metric : metrics) { - if ( metric == "bs" ) + if ( metric == "BS" ) { if (std::find(req_dep.begin(), req_dep.end(), metric) == req_dep.end()) - evaluator.calc_bs(); - r.emplace_back(evaluator.bs); + evaluator.calc_BS(); + r.emplace_back(evaluator.BS); } - else if ( metric == "bss" ) + else if ( metric == "BSS" ) { if (std::find(req_dep.begin(), req_dep.end(), metric) == req_dep.end()) - evaluator.calc_bss(); - r.emplace_back(evaluator.bss); + evaluator.calc_BSS(); + r.emplace_back(evaluator.BSS); } - else if ( metric == "bs_crd" ) + else if ( metric == "BS_CRD" ) { if (std::find(req_dep.begin(), req_dep.end(), metric) == req_dep.end()) - evaluator.calc_bs_crd(); - r.emplace_back(evaluator.bs_crd); + evaluator.calc_BS_CRD(); + r.emplace_back(evaluator.BS_CRD); } - else if ( metric == "bs_lbd" ) + else if ( metric == "BS_LBD" ) { if (std::find(req_dep.begin(), req_dep.end(), metric) == req_dep.end()) - evaluator.calc_bs_lbd(); - r.emplace_back(evaluator.bs_lbd); + evaluator.calc_BS_LBD(); + r.emplace_back(evaluator.BS_LBD); } else if ( metric == "QS" ) { diff --git a/include/evalhyd/probabilist/evaluator.h b/include/evalhyd/probabilist/evaluator.h index d35730de2420d049b8f92fab6c1614d60d2190da..c5d5b990664706c8162408cfd3aeab177837cd86 100644 --- a/include/evalhyd/probabilist/evaluator.h +++ b/include/evalhyd/probabilist/evaluator.h @@ -34,10 +34,10 @@ namespace evalhyd xt::xtensor<double, 2> crps; // members for evaluation metrics - xt::xtensor<double, 2> bs; - xt::xtensor<double, 2> bs_crd; - xt::xtensor<double, 2> bs_lbd; - xt::xtensor<double, 2> bss; + xt::xtensor<double, 2> BS; + xt::xtensor<double, 2> BS_CRD; + xt::xtensor<double, 2> BS_LBD; + xt::xtensor<double, 2> BSS; xt::xtensor<double, 2> QS; xt::xtensor<double, 2> CRPS; @@ -54,10 +54,10 @@ namespace evalhyd void calc_crps(); // methods to compute metrics - void calc_bs(); - void calc_bs_crd(); - void calc_bs_lbd(); - void calc_bss(); + void calc_BS(); + void calc_BS_CRD(); + void calc_BS_LBD(); + void calc_BSS(); void calc_QS(); void calc_CRPS(); }; diff --git a/include/evalhyd/probabilist/evaluator_brier.cpp b/include/evalhyd/probabilist/evaluator_brier.cpp index cbfe7e36bb23a56332f80b6b20f54cd63718bbf1..af2372b89fc791a90267b53299a5957fbfda5214 100644 --- a/include/evalhyd/probabilist/evaluator_brier.cpp +++ b/include/evalhyd/probabilist/evaluator_brier.cpp @@ -25,14 +25,14 @@ namespace evalhyd // \require y_k: // Event probability forecast. // shape: (thresholds, time) - // \assign bs: + // \assign BS: // 2D array of Brier score for each threshold. // shape: (thresholds, 1) - void Evaluator::calc_bs() + void Evaluator::calc_BS() { // return computed Brier score(s) // $BS = \frac{1}{n} \sum_{k=1}^{n} (o_k - y_k)^2$ - bs = xt::mean(xt::square(o_k - y_k), -1, xt::keep_dims); + BS = xt::mean(xt::square(o_k - y_k), -1, xt::keep_dims); } // Compute the calibration-refinement decomposition of the Brier score @@ -49,11 +49,11 @@ namespace evalhyd // \require y_k: // Event probability forecast. // shape: (thresholds, time) - // \assign bs_crd: + // \assign BS_CRD: // 2D array of Brier score components (reliability, resolution, // uncertainty) for each threshold. // shape: (thresholds, components) - void Evaluator::calc_bs_crd() + void Evaluator::calc_BS_CRD() { // declare internal variables // shape: (bins, thresholds, time) @@ -71,7 +71,7 @@ namespace evalhyd // initialise output variable // shape: (components, thresholds) - bs_crd = xt::zeros<double>({n_thr, n_cmp}); + BS_CRD = xt::zeros<double>({n_thr, n_cmp}); // compute range of forecast values $y_i$ y_i = xt::arange<double>(double(n_mbr + 1)) / n_mbr; @@ -103,7 +103,7 @@ namespace evalhyd // calculate reliability = // $\frac{1}{n} \sum_{i=1}^{I} N_i (y_i - \bar{o_i})^2$ - xt::col(bs_crd, 0) = + xt::col(BS_CRD, 0) = xt::sum( xt::square( xt::view(y_i, xt::all(), xt::newaxis()) @@ -114,7 +114,7 @@ namespace evalhyd // calculate resolution = // $\frac{1}{n} \sum_{i=1}^{I} N_i (\bar{o_i} - \bar{o})^2$ - xt::col(bs_crd, 1) = + xt::col(BS_CRD, 1) = xt::sum( xt::square( bar_o_i - bar_o @@ -123,7 +123,7 @@ namespace evalhyd ) / n; // calculate uncertainty = $\bar{o} (1 - \bar{o})$ - xt::col(bs_crd, 2) = bar_o * (1 - bar_o); + xt::col(BS_CRD, 2) = bar_o * (1 - bar_o); } // Compute the likelihood-base rate decomposition of the Brier score @@ -137,11 +137,11 @@ namespace evalhyd // \require y_k: // Event probability forecast. // shape: (thresholds, time) - // \return bs_lbd: + // \return BS_LBD: // 2D array of Brier score components (type 2 bias, discrimination, // sharpness) for each threshold. // shape: (thresholds, components) - void Evaluator::calc_bs_lbd() + void Evaluator::calc_BS_LBD() { // declare internal variables // shape: (bins, thresholds, time) @@ -160,7 +160,7 @@ namespace evalhyd // declare and initialise output variable // shape: (components, thresholds) - bs_lbd = xt::zeros<double>({n_thr, n_cmp}); + BS_LBD = xt::zeros<double>({n_thr, n_cmp}); // set the range of observed values $o_j$ o_j = {0., 1.}; @@ -196,7 +196,7 @@ namespace evalhyd // calculate type 2 bias = // $\frac{1}{n} \sum_{j=1}^{J} M_j (o_j - \bar{y_j})^2$ - xt::col(bs_lbd, 0) = + xt::col(BS_LBD, 0) = xt::sum( xt::square( xt::view(o_j, xt::all(), xt::newaxis()) @@ -207,7 +207,7 @@ namespace evalhyd // calculate discrimination = // $\frac{1}{n} \sum_{j=1}^{J} M_j (\bar{y_j} - \bar{y})^2$ - xt::col(bs_lbd, 1) = + xt::col(BS_LBD, 1) = xt::sum( xt::square( bar_y_j - bar_y @@ -217,7 +217,7 @@ namespace evalhyd // calculate sharpness = // $\frac{1}{n} \sum_{k=1}^{n} (\bar{y_k} - \bar{y})^2$ - xt::col(bs_lbd, 2) = + xt::col(BS_LBD, 2) = xt::sum( xt::square( y_k - @@ -235,13 +235,13 @@ namespace evalhyd // \require bar_o: // Mean event observed outcome. // shape: (thresholds,) - // \require bs: + // \require BS: // Brier score(s). // shape: (thresholds,) - // \assign bss: + // \assign BSS: // 2D array of Brier skill score for each threshold. // shape: (thresholds, 1) - void Evaluator::calc_bss() + void Evaluator::calc_BSS() { // calculate reference Brier score(s) // $BS_{ref} = \frac{1}{n} \sum_{k=1}^{n} (o_k - \bar{o})^2$ @@ -256,7 +256,7 @@ namespace evalhyd // return computed Brier skill score(s) // $BSS = 1 - \frac{BS}{BS_{ref}} - bss = 1 - (bs / bs_ref); + BSS = 1 - (BS / bs_ref); } } } diff --git a/tests/test_probabilist.cpp b/tests/test_probabilist.cpp index 67870f41acdbcac69264d3c47ef1c3a52574cfbf..8cb117467d8ee9e6cde87cb989bb7426180606c5 100644 --- a/tests/test_probabilist.cpp +++ b/tests/test_probabilist.cpp @@ -24,7 +24,7 @@ TEST(ProbabilistTests, TestBrier) { std::vector<xt::xtensor<double, 2>> metrics = evalhyd::probabilist::evaluate( - {"bs", "bss", "bs_crd", "bs_lbd"}, + {"BS", "BSS", "BS_CRD", "BS_LBD"}, xt::transpose(observed), xt::transpose(forecast), thresholds );