An error occurred while loading the file. Please try again.
-
Thibault Hallouin authored
including: - extracting the element/intermediate/metric calculations from the `determinist::Evaluator` class - introducing new getter methods in `determinist::Evaluator` class that handle the element/intermediate/metric inter-dependencies internally to the object - removing external inter-dependencies handling from `evald`
b4abca9f
#ifndef EVALHYD_UTILS_HPP
#define EVALHYD_UTILS_HPP
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <stdexcept>
#include <xtensor/xtensor.hpp>
#include <xtensor/xrandom.hpp>
namespace evalhyd
{
namespace utils
{
/// Procedure to check that all elements in the list of metrics are
/// valid metrics.
///
/// \param [in] requested_metrics:
/// Vector of strings for the metric(s) to be computed.
/// \param [in] valid_metrics:
/// Vector of strings for the metric(s) to can be computed.
inline void check_metrics (
const std::vector<std::string>& requested_metrics,
const std::vector<std::string>& valid_metrics
)
{
for (const auto& metric : requested_metrics)
{
if (std::find(valid_metrics.begin(), valid_metrics.end(), metric)
== valid_metrics.end())
{
throw std::runtime_error(
"invalid evaluation metric: " + metric
);
}
}
}
/// Procedure to check that all elements for a bootstrap experiment
/// are provided and valid.
///
/// \param [in] bootstrap:
/// Map of parameters for the bootstrap experiment.
inline void check_bootstrap (
const std::unordered_map<std::string, int>& bootstrap
)
{
// check n_samples
if (bootstrap.find("n_samples") == bootstrap.end())
{
throw std::runtime_error(
"number of samples missing for bootstrap"
);
}
// check len_sample
if (bootstrap.find("len_sample") == bootstrap.end())
{
throw std::runtime_error(
"length of sample missing for bootstrap"
);
}
// check summary
if (bootstrap.find("summary") == bootstrap.end())
{
throw std::runtime_error(
"summary missing for bootstrap"
);
}
auto s = bootstrap.find("summary")->second;
// TODO: change upper bound when mean+stddev and quantiles implemented
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
if ((s < 0) || (s > 0))
{
throw std::runtime_error(
"invalid value for bootstrap summary"
);
}
// set seed
if (bootstrap.find("seed") == bootstrap.end())
{
xt::random::seed(time(nullptr));
}
else
{
xt::random::seed(bootstrap.find("seed")->second);
}
}
namespace evalp
{
/// Procedure to check that optional parameters are provided
/// as arguments when required metrics need them.
///
/// \param [in] metrics:
/// Vector of strings for the metric(s) to be computed.
/// \param [in] thresholds:
/// Array of thresholds for metrics based on exceedance events.
inline void check_optionals (
const std::vector<std::string>& metrics,
const xt::xtensor<double, 2>& thresholds
)
{
std::vector<std::string>threshold_metrics =
{"BS", "BS_CRD", "BS_LBD", "BSS"};
for (const auto& metric : metrics)
{
if (std::find(threshold_metrics.begin(), threshold_metrics.end(),
metric) != threshold_metrics.end())
{
if (thresholds.size() < 1)
{
throw std::runtime_error(
"missing thresholds *q_thr* required to "
"compute " + metric
);
}
}
}
}
}
}
}
#endif //EVALHYD_UTILS_HPP