Commit 0178de2f authored by François Bourgin's avatar François Bourgin
Browse files

Merge branch '6-evaluation-of-quantiles-prediction' into 'dev'

Resolve "evaluation of quantiles prediction"

See merge request !4
1 merge request!4Resolve "evaluation of quantiles prediction"
Pipeline #63746 passed with stage
in 4 minutes and 25 seconds
Showing with 31 additions and 1 deletion
+31 -1
Subproject commit 6f17c3e0f32f935c0a4f34dc1d3c6a9ee780497b Subproject commit 8e78a67e961001b479f65879119f7abe752b87d1
...@@ -14,6 +14,7 @@ def evalp(q_obs: NDArray[dtype('float64')], ...@@ -14,6 +14,7 @@ def evalp(q_obs: NDArray[dtype('float64')],
q_thr: NDArray[dtype('float64')] = None, q_thr: NDArray[dtype('float64')] = None,
events: str = None, events: str = None,
c_lvl: NDArray[dtype('float64')] = None, c_lvl: NDArray[dtype('float64')] = None,
q_lvl: NDArray[dtype('float64')] = None,
t_msk: NDArray[dtype('bool')] = None, t_msk: NDArray[dtype('bool')] = None,
m_cdt: NDArray[dtype('|S32')] = None, m_cdt: NDArray[dtype('|S32')] = None,
bootstrap: Dict[str, int] = None, bootstrap: Dict[str, int] = None,
...@@ -36,6 +37,8 @@ def evalp(q_obs: NDArray[dtype('float64')], ...@@ -36,6 +37,8 @@ def evalp(q_obs: NDArray[dtype('float64')],
kwargs['events'] = events kwargs['events'] = events
if c_lvl is not None: if c_lvl is not None:
kwargs['c_lvl'] = c_lvl kwargs['c_lvl'] = c_lvl
if q_lvl is not None:
kwargs['q_lvl'] = q_lvl
if t_msk is not None: if t_msk is not None:
kwargs['t_msk'] = t_msk kwargs['t_msk'] = t_msk
if m_cdt is not None: if m_cdt is not None:
...@@ -55,6 +58,7 @@ def evalp(q_obs: NDArray[dtype('float64')], ...@@ -55,6 +58,7 @@ def evalp(q_obs: NDArray[dtype('float64')],
'q_prd': 4, 'q_prd': 4,
'q_thr': 2, 'q_thr': 2,
'c_lvl': 1, 'c_lvl': 1,
'q_lvl': 1,
't_msk': 4, 't_msk': 4,
'm_cdt': 2, 'm_cdt': 2,
'dts': 1 'dts': 1
......
...@@ -63,6 +63,7 @@ auto evalp( ...@@ -63,6 +63,7 @@ auto evalp(
const xt::pytensor<double, 2>& q_thr, const xt::pytensor<double, 2>& q_thr,
std::optional<std::string> events, std::optional<std::string> events,
const std::vector<double>& c_lvl, const std::vector<double>& c_lvl,
const std::vector<double>& q_lvl,
const xt::pytensor<bool, 4>& t_msk, const xt::pytensor<bool, 4>& t_msk,
const xt::pytensor<std::array<char, 32>, 2>& m_cdt, const xt::pytensor<std::array<char, 32>, 2>& m_cdt,
std::optional<std::unordered_map<std::string, int>> bootstrap, std::optional<std::unordered_map<std::string, int>> bootstrap,
...@@ -78,6 +79,7 @@ auto evalp( ...@@ -78,6 +79,7 @@ auto evalp(
q_thr, q_thr,
(events.has_value()) ? events.value() : xtl::missing<std::string>(), (events.has_value()) ? events.value() : xtl::missing<std::string>(),
c_lvl, c_lvl,
q_lvl,
t_msk, t_msk,
m_cdt, m_cdt,
(bootstrap.has_value()) (bootstrap.has_value())
...@@ -130,6 +132,7 @@ PYBIND11_MODULE(_evalhyd, m) ...@@ -130,6 +132,7 @@ PYBIND11_MODULE(_evalhyd, m)
py::arg("q_thr") = xt::pytensor<double, 2>({0}), py::arg("q_thr") = xt::pytensor<double, 2>({0}),
py::arg("events") = py::none(), py::arg("events") = py::none(),
py::arg("c_lvl") = py::list(), py::arg("c_lvl") = py::list(),
py::arg("q_lvl") = py::list(),
py::arg("t_msk") = xt::pytensor<bool, 4>({0}), py::arg("t_msk") = xt::pytensor<bool, 4>({0}),
py::arg("m_cdt") = xt::pytensor<std::array<char, 32>, 2>({0}), py::arg("m_cdt") = xt::pytensor<std::array<char, 32>, 2>({0}),
py::arg("bootstrap") = py::none(), py::arg("bootstrap") = py::none(),
......
0.00643087,0.0514469
...@@ -90,6 +90,13 @@ class TestMetrics(unittest.TestCase): ...@@ -90,6 +90,13 @@ class TestMetrics(unittest.TestCase):
) for metric in ('CR', 'AW', 'AWN', 'WS') ) for metric in ('CR', 'AW', 'AWN', 'WS')
} }
expected_itv_qlvl = {
metric: (
numpy.genfromtxt(f"./expected/evalp/{metric}_QLVL.csv", delimiter=',')
[numpy.newaxis, numpy.newaxis, numpy.newaxis, numpy.newaxis, ...]
) for metric in ('CR',)
}
expected_mvr = { expected_mvr = {
metric: ( metric: (
numpy.genfromtxt(f"./expected/evalp/{metric}.csv", delimiter=',') numpy.genfromtxt(f"./expected/evalp/{metric}.csv", delimiter=',')
...@@ -153,6 +160,21 @@ class TestMetrics(unittest.TestCase): ...@@ -153,6 +160,21 @@ class TestMetrics(unittest.TestCase):
self.expected_itv[metric] self.expected_itv[metric]
) )
def test_intervals_qlvl_metrics(self):
lvl = numpy.array([50., 80.])
qlvl = numpy.array([10., 25., 75., 90])
for metric in self.expected_itv_qlvl.keys():
numpy.set_printoptions(precision=13)
m = evalhyd.evalp(_obs, _prd[:, :, [0, 15, 30, 50], :], [metric], c_lvl=lvl, q_lvl=qlvl)[0][0, 0, 0]
numpy.savetxt(f"./expected/evalp/{metric}_QLVL.csv", m, delimiter=',', fmt="%.13f")
with self.subTest(metric=metric):
numpy.testing.assert_almost_equal(
evalhyd.evalp(_obs, _prd[:, :, [0, 15, 30, 50], :], [metric], c_lvl=lvl, q_lvl=qlvl)[0],
self.expected_itv_qlvl[metric]
)
def test_multivariate_metrics(self): def test_multivariate_metrics(self):
n_sit = 5 n_sit = 5
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment