12 #ifndef PLSSVM_BACKENDS_OPENMP_CSVM_HPP_
13 #define PLSSVM_BACKENDS_OPENMP_CSVM_HPP_
21 #include <type_traits>
59 template <
typename... Args,
PLSSVM_REQUIRES(detail::has_only_parameter_named_args_v<Args...>)>
60 explicit csvm(Args &&...named_args) :
61 ::
plssvm::
csvm{ std::forward<Args>(named_args)... } {
73 template <
typename... Args,
PLSSVM_REQUIRES(detail::has_only_parameter_named_args_v<Args...>)>
75 ::
plssvm::
csvm{ std::forward<Args>(named_args)... } {
98 ~
csvm() override = default;
112 template <
typename real_type>
118 [[nodiscard]] std::vector<float>
predict_values(
const detail::parameter<float> ¶ms,
const std::vector<std::vector<float>> &support_vectors,
const std::vector<float> &alpha,
float rho, std::vector<float> &w,
const std::vector<std::vector<float>> &predict_points)
const override {
return this->
predict_values_impl(params, support_vectors, alpha, rho, w, predict_points); }
122 [[nodiscard]] std::vector<double>
predict_values(
const detail::parameter<double> ¶ms,
const std::vector<std::vector<double>> &support_vectors,
const std::vector<double> &alpha,
double rho, std::vector<double> &w,
const std::vector<std::vector<double>> &predict_points)
const override {
return this->
predict_values_impl(params, support_vectors, alpha, rho, w, predict_points); }
126 template <
typename real_type>
127 [[nodiscard]] std::vector<real_type>
predict_values_impl(
const detail::parameter<real_type> ¶ms,
const std::vector<std::vector<real_type>> &support_vectors,
const std::vector<real_type> &alpha, real_type rho, std::vector<real_type> &w,
const std::vector<std::vector<real_type>> &predict_points)
const;
136 template <
typename real_type>
145 template <
typename real_type>
146 [[nodiscard]] std::vector<real_type>
calculate_w(
const std::vector<std::vector<real_type>> &support_vectors,
const std::vector<real_type> &alpha)
const;
159 template <
typename real_type>
160 void run_device_kernel(
const detail::parameter<real_type> ¶ms,
const std::vector<real_type> &q, std::vector<real_type> &ret,
const std::vector<real_type> &d,
const std::vector<std::vector<real_type>> &data, real_type QA_cost, real_type add)
const;
Base class for all C-SVM backends.
Definition: csvm.hpp:50
A C-SVM implementation using OpenMP as backend.
Definition: csvm.hpp:32
void run_device_kernel(const detail::parameter< real_type > ¶ms, const std::vector< real_type > &q, std::vector< real_type > &ret, const std::vector< real_type > &d, const std::vector< std::vector< real_type >> &data, real_type QA_cost, real_type add) const
Select the correct kernel based on the value of plssvm::parameter::kernel_type and run it on the CPU ...
std::vector< real_type > calculate_w(const std::vector< std::vector< real_type >> &support_vectors, const std::vector< real_type > &alpha) const
Precalculate the w vector to speedup up the prediction using the linear kernel function.
std::vector< float > predict_values(const detail::parameter< float > ¶ms, const std::vector< std::vector< float >> &support_vectors, const std::vector< float > &alpha, float rho, std::vector< float > &w, const std::vector< std::vector< float >> &predict_points) const override
Uses the already learned model to predict the class of multiple (new) data points.
Definition: csvm.hpp:118
void init(target_platform target)
Initializes the OpenMP backend and performs some sanity checks.
std::pair< std::vector< real_type >, real_type > solve_system_of_linear_equations_impl(const detail::parameter< real_type > ¶ms, const std::vector< std::vector< real_type >> &A, std::vector< real_type > b, real_type eps, unsigned long long max_iter) const
Solves the equation using the Conjugated Gradients algorithm.
std::vector< real_type > predict_values_impl(const detail::parameter< real_type > ¶ms, const std::vector< std::vector< real_type >> &support_vectors, const std::vector< real_type > &alpha, real_type rho, std::vector< real_type > &w, const std::vector< std::vector< real_type >> &predict_points) const
Uses the already learned model to predict the class of multiple (new) data points.
std::pair< std::vector< double >, double > solve_system_of_linear_equations(const detail::parameter< double > ¶ms, const std::vector< std::vector< double >> &A, std::vector< double > b, double eps, unsigned long long max_iter) const override
Solves the equation using the Conjugated Gradients algorithm.
Definition: csvm.hpp:108
std::vector< real_type > generate_q(const detail::parameter< real_type > ¶ms, const std::vector< std::vector< real_type >> &data) const
Calculate the q vector used in the dimensional reduction.
csvm(Args &&...named_args)
Construct a new C-SVM using the OpenMP backend and the optionally provided named_args.
Definition: csvm.hpp:60
csvm(csvm &&) noexcept=default
Default move-constructor since a virtual destructor has been declared. noexcept
csvm(const csvm &)=delete
Delete copy-constructor since a CSVM is a move-only type.
csvm(const target_platform target, Args &&...named_args)
Construct a new C-SVM using the OpenMP backend on the target platform and the optionally provided nam...
Definition: csvm.hpp:74
csvm(target_platform target, parameter params={})
Construct a new C-SVM using the OpenMP backend on the target platform with the parameters given throu...
csvm(parameter params={})
Construct a new C-SVM using the OpenMP backend with the parameters given through params.
std::pair< std::vector< float >, float > solve_system_of_linear_equations(const detail::parameter< float > ¶ms, const std::vector< std::vector< float >> &A, std::vector< float > b, float eps, unsigned long long max_iter) const override
Solves the equation using the Conjugated Gradients algorithm.
Definition: csvm.hpp:104
std::vector< double > predict_values(const detail::parameter< double > ¶ms, const std::vector< std::vector< double >> &support_vectors, const std::vector< double > &alpha, double rho, std::vector< double > &w, const std::vector< std::vector< double >> &predict_points) const override
Uses the already learned model to predict the class of multiple (new) data points.
Definition: csvm.hpp:122
Defines the base class for all C-SVM backends and implements the functionality shared by all of them.
The main namespace containing all public API functions.
Definition: backend_types.hpp:24
target_platform
Enum class for all possible targets.
Definition: target_platforms.hpp:25
Implements the parameter class encapsulating all important C-SVM parameters.
Sets the value of the value member to true if T is a C-SVM using an available backend....
Definition: csvm.hpp:410
Defines some generic type traits used in the PLSSVM library.
#define PLSSVM_REQUIRES(...)
A shorthand macro for the std::enable_if_t type trait.
Definition: type_traits.hpp:33