20#ifndef KO_WRAP_PARAMS_HPP
21#define KO_WRAP_PARAMS_HPP
57 if(id_cv==
CV_algo::CV2){
return "cross validation on regularization parameter";}
58 if(id_cv==
CV_algo::CV3){
return "cross validation on number of PPCs";}
59 if(id_cv==
CV_algo::CV4){
return "cross validation on both regularization parameter and number of PPCs";}
62 std::string error_message =
"Wrong input string";
63 throw std::invalid_argument(error_message);
77 if(threshold_ppc<=0 || threshold_ppc>=1)
79 std::string error_message =
"threshold_ppc has to be in (0,1)";
80 throw std::invalid_argument(error_message);
96 std::string error_message =
"alpha has to be a positive real number";
97 throw std::invalid_argument(error_message);
114 std::string error_message =
"k has to be a positive integer or 0";
115 throw std::invalid_argument(error_message);
119 std::string error_message =
"k has to be lower than the maximum number of PPCs";
120 throw std::invalid_argument(error_message);
136 if(solver_ex ==
false)
140 std::string error_message =
"GEP solver can be used only if the number of PPCs is imposed or retrieved through CV";
141 throw std::invalid_argument(error_message);
159 if(alpha_vec.isNull())
161 std::vector<double> alphas;
164 std::iota(alphas.begin(),alphas.end(),
static_cast<double>(-10));
165 std::transform(alphas.begin(),alphas.end(),alphas.begin(),[](
double el){return(pow(static_cast<double>(10),el));});
170 std::vector<double> alphas = Rcpp::as<std::vector<double>>(alpha_vec);
173 std::sort(alphas.begin(), alphas.end());
177 std::string error_message =
"Every alpha has to be a positive real number";
178 throw std::invalid_argument(error_message);
195wrap_k_vec(Rcpp::Nullable<Rcpp::IntegerVector> k_vec,
int k_max)
200 std::vector<int> k_s;
203 std::iota(k_s.begin(),k_s.end(),
static_cast<int>(1));
208 std::vector<int> k_s = Rcpp::as<std::vector<int>>(k_vec);
211 std::sort(k_s.begin(), k_s.end());
216 std::string error_message1 =
"k has to be at least 1";
217 throw std::invalid_argument(error_message1);
219 if(k_s.back() > k_max)
221 std::string error_message2 =
"k cannot be greater than the number of discrete evaluation of the functional object in the domain (" + std::to_string(k_max) +
")";
222 throw std::invalid_argument(error_message2);
241wrap_disc_ev(Rcpp::Nullable<Rcpp::NumericVector> disc_ev,
double a,
double b,
int dim)
246 std::string error_message1 =
"Left extreme of the domain has to be smaller than the right one";
247 throw std::invalid_argument(error_message1);
256 return grid_func_data.
nodes();
260 std::vector<double> disc_ev_points = Rcpp::as<std::vector<double>>(disc_ev);
261 std::sort(disc_ev_points.begin(),disc_ev_points.end());
264 if(disc_ev_points[0] < a || disc_ev_points.back() > b)
266 std::string error_message2 =
"The points in which there are the discrete evaluations of the functiona data have to in the domain (" + std::to_string(a) +
"," + std::to_string(b) +
")";
267 throw std::invalid_argument(error_message2);
271 if(disc_ev_points.size()!=dim)
273 std::string error_message3 =
"In the grid are needed " + std::to_string(dim) +
" points";
274 throw std::invalid_argument(error_message3);
277 return disc_ev_points;
295wrap_sizes_set_CV(Rcpp::Nullable<int> min_size_ts, Rcpp::Nullable<int> max_size_ts,
int number_time_instants)
298 int min_dim_ts = min_size_ts.isNull() ?
static_cast<int>(std::ceil(
static_cast<double>(number_time_instants)/
static_cast<double>(2))) : Rcpp::as<int>(min_size_ts);
300 int max_dim_ts = max_size_ts.isNull() ? number_time_instants : (Rcpp::as<int>(max_size_ts)+1);
305 std::string error_message1 =
"Min size of train set has to be at least 2";
306 throw std::invalid_argument(error_message1);
309 if (!(max_dim_ts<=number_time_instants))
311 std::string error_message2 =
"Max size of train set has to be at most the total number of time instants (" + std::to_string(number_time_instants) +
") minus 1 (to leave room for the validation set)";
312 throw std::invalid_argument(error_message2);
315 if(min_dim_ts >= max_dim_ts)
317 std::string error_message =
"Min size of train set (" + std::to_string(min_dim_ts) +
" has to be less than the max one (" + std::to_string(max_dim_ts) +
")";
318 throw std::invalid_argument(error_message);
321 return std::make_pair(min_dim_ts,max_dim_ts);
342 int max_n_t = omp_get_num_procs();
344 if(num_threads.isNull())
350 int n_t = Rcpp::as<int>(num_threads);
351 if(n_t < 1 || n_t > max_n_t){
return max_n_t;}
383 if(id_rem_nan.isNull())
387 if(Rcpp::as< std::string >(id_rem_nan) ==
"NO")
391 if(Rcpp::as< std::string >(id_rem_nan) ==
"MR")
395 if(Rcpp::as< std::string >(id_rem_nan) ==
"ZR")
401 std::string error_message =
"Wrong input string for handling NANs";
402 throw std::invalid_argument(error_message);
std::vector< double > nodes() const
The nodes.
Definition mesh.hpp:73
Contains the class for an unidimensioanl mesh.
REM_NAN wrap_id_rem_nans(Rcpp::Nullable< std::string > id_rem_nan)
Wrapping the strategy for handling non-dummy NaNs.
Definition parameters_wrapper.hpp:381
std::vector< double > wrap_alpha_vec(Rcpp::Nullable< Rcpp::NumericVector > alpha_vec)
Wrapping the R-vector representing the regularization parameter input space into a coherent C++ objec...
Definition parameters_wrapper.hpp:156
void check_solver(bool solver_ex, const std::string &id_cv, int k)
Check if, if using 'gep_solver', the number of PPCs is not retrieved through explanatory power criter...
Definition parameters_wrapper.hpp:134
std::string wrap_string_CV_to_be_printed(const std::string &id_cv)
Creating a string to print on the screen which PPCKO version is being used.
Definition parameters_wrapper.hpp:54
std::pair< int, int > wrap_sizes_set_CV(Rcpp::Nullable< int > min_size_ts, Rcpp::Nullable< int > max_size_ts, int number_time_instants)
Wrapping the minimum and maximum dimension of the training set, checking their consitency,...
Definition parameters_wrapper.hpp:295
void check_threshold_ppc(const double &threshold_ppc)
Check if 'threshold_ppc' input is between 0 and 1. Eventually, raises and error.
Definition parameters_wrapper.hpp:75
int wrap_num_thread(Rcpp::Nullable< int > num_threads)
Wrapping the number of threads for OMP.
Definition parameters_wrapper.hpp:335
void check_k(const int &k, const int &max_k)
Check if 'k' input is an integer between 0 and the number of available evaluations of the functional ...
Definition parameters_wrapper.hpp:110
std::vector< double > wrap_disc_ev(Rcpp::Nullable< Rcpp::NumericVector > disc_ev, double a, double b, int dim)
Wrapping the points over which the discrete evaluations of the functional object are available....
Definition parameters_wrapper.hpp:241
void check_alpha(const double &alpha)
Check if 'alpha' input is greater than 0. Eventually, raises and error.
Definition parameters_wrapper.hpp:92
std::vector< int > wrap_k_vec(Rcpp::Nullable< Rcpp::IntegerVector > k_vec, int k_max)
Wrapping the R-vector representing the number of PPCs input space into a coherent C++ object,...
Definition parameters_wrapper.hpp:195
REM_NAN
The available strategy for removing non-dummy NaNs.
Definition parameters_wrapper.hpp:366
@ ZR
Replacing nans with 0s (could change the sd of the distribution)
Definition parameters_wrapper.hpp:369
@ MR
Replacing nans with mean (could change the mean of the distribution)
Definition parameters_wrapper.hpp:368
@ NR
Not replacing NaN: not to be used by the user, necessary for handling dummy NaNs.
Definition parameters_wrapper.hpp:367
static constexpr std::string CV1
No cv for parameters.
Definition traits_ko.hpp:64
static constexpr std::string CV4
Cv for both regularization parameter and number of retained PPCs.
Definition traits_ko.hpp:67
static constexpr std::string CV2
Cv for regularization parameter.
Definition traits_ko.hpp:65
static constexpr std::string CV3
Cv for number of retained PPCs.
Definition traits_ko.hpp:66
Contains customized types and enumerator for customized template parameters, exploited in the algorit...