PLSSVM - Parallel Least Squares Support Vector Machine  2.0.0
A Least Squares Support Vector Machine implementation using different backends.
data_set_variants.hpp
Go to the documentation of this file.
1 
12 #ifndef PLSSVM_DETAIL_CMD_DATA_SET_VARIANTS_HPP_
13 #define PLSSVM_DETAIL_CMD_DATA_SET_VARIANTS_HPP_
14 #pragma once
15 
16 #include "plssvm/data_set.hpp" // plssvm::data_set
17 #include "plssvm/detail/cmd/parser_predict.hpp" // plssvm::detail::cmd::parser_predict
18 #include "plssvm/detail/cmd/parser_scale.hpp" // plssvm::detail::cmd::parser_scale
19 #include "plssvm/detail/cmd/parser_train.hpp" // plssvm::detail::cmd::parser_train
20 
21 #include <string> // std::string
22 #include <variant> // std::variant
23 
24 namespace plssvm::detail::cmd {
25 
26 // clang-format off
31 using data_set_variants = std::variant<plssvm::data_set<float, int>, plssvm::data_set<float, std::string>,
33 // clang-format on
34 
42 template <typename real_type, typename label_type = typename data_set<real_type>::label_type>
43 [[nodiscard]] inline data_set_variants data_set_factory_impl(const cmd::parser_train &cmd_parser) {
45 }
53 template <typename real_type, typename label_type = typename data_set<real_type>::label_type>
54 [[nodiscard]] inline data_set_variants data_set_factory_impl(const cmd::parser_predict &cmd_parser) {
56 }
64 template <typename real_type, typename label_type = typename data_set<real_type>::label_type>
65 [[nodiscard]] inline data_set_variants data_set_factory_impl(const cmd::parser_scale &cmd_parser) {
66  if (!cmd_parser.restore_filename.empty()) {
68  } else {
69  return data_set_variants{ plssvm::data_set<real_type, label_type>{ cmd_parser.input_filename, { static_cast<real_type>(cmd_parser.lower), static_cast<real_type>(cmd_parser.upper) } } };
70  }
71 }
72 
79 template <typename cmd_parser_type>
80 [[nodiscard]] inline data_set_variants data_set_factory(const cmd_parser_type &cmd_parser) {
81  if (cmd_parser.float_as_real_type && cmd_parser.strings_as_labels) {
82  return data_set_factory_impl<float, std::string>(cmd_parser);
83  } else if (cmd_parser.float_as_real_type && !cmd_parser.strings_as_labels) {
84  return data_set_factory_impl<float>(cmd_parser);
85  } else if (!cmd_parser.float_as_real_type && cmd_parser.strings_as_labels) {
86  return data_set_factory_impl<double, std::string>(cmd_parser);
87  } else {
88  return data_set_factory_impl<double>(cmd_parser);
89  }
90 }
91 } // namespace plssvm::detail::cmd
92 
93 #endif // PLSSVM_DETAIL_CMD_DATA_SET_VARIANTS_HPP_
Encapsulate all necessary data that is needed for training or predicting using an SVM.
Definition: data_set.hpp:69
Class for encapsulating all necessary parameters for prediction; normally provided through command li...
Definition: parser_predict.hpp:28
std::string input_filename
The name of the data file to predict.
Definition: parser_predict.hpp:52
Class for encapsulating all necessary parameters for scaling a data set; normally provided through co...
Definition: parser_scale.hpp:26
double lower
The lower bound of the scaled data values.
Definition: parser_scale.hpp:37
std::string input_filename
The name of the data file to scale.
Definition: parser_scale.hpp:49
std::string restore_filename
The name of the file from which the scaling factors should be restored.
Definition: parser_scale.hpp:55
double upper
The upper bound of the scaled data values.
Definition: parser_scale.hpp:39
Class for encapsulating all necessary parameters for training; normally provided through command line...
Definition: parser_train.hpp:32
std::string input_filename
The name of the data/test file to parse.
Definition: parser_train.hpp:66
Implements a data set class encapsulating all data points, features, and potential labels.
Namespace containing implementation details for the command line interface functionality....
Definition: core.hpp:46
data_set_variants data_set_factory(const cmd_parser_type &cmd_parser)
Based on the provided command line cmd_parser, return the correct plssvm::data_set type.
Definition: data_set_variants.hpp:80
std::variant< plssvm::data_set< float, int >, plssvm::data_set< float, std::string >, plssvm::data_set< double, int >, plssvm::data_set< double, std::string > > data_set_variants
Four different type combinations are allowed in the command line invocation: float + int,...
Definition: data_set_variants.hpp:32
data_set_variants data_set_factory_impl(const cmd::parser_train &cmd_parser)
Return the correct data set type based on the plssvm::detail::cmd::parser_train command line options.
Definition: data_set_variants.hpp:43
Implements a class encapsulating all necessary parameters for predicting using the C-SVM possibly pro...
Implements a class encapsulating all necessary parameters for scaling a data set possibly provided th...
Implements a class encapsulating all necessary parameters for training the C-SVM possibly provided th...