![]() |
PLSSVM - Parallel Least Squares Support Vector Machine
2.0.0
A Least Squares Support Vector Machine implementation using different backends.
|
Base class for all C-SVM backends. More...
#include <csvm.hpp>
Public Member Functions | |
csvm (parameter params={}) | |
Construct a C-SVM using the SVM parameter params . More... | |
template<typename... Args> | |
csvm (Args &&...args) | |
Construct a C-SVM forwarding all parameters args to the plssvm::parameter constructor. More... | |
csvm (const csvm &)=delete | |
Delete copy-constructor since a CSVM is a move-only type. | |
csvm (csvm &&) noexcept=default | |
Default move-constructor since a virtual destructor has been declared. | |
csvm & | operator= (const csvm &)=delete |
Delete copy-assignment operator since a CSVM is a move-only type. More... | |
csvm & | operator= (csvm &&) noexcept=default |
Default move-assignment operator since a virtual destructor has been declared. More... | |
virtual | ~csvm ()=default |
Virtual destructor to enable safe inheritance. | |
target_platform | get_target_platform () const noexcept |
Return the target platform (i.e, CPU or GPU including the vendor) this SVM runs on. More... | |
parameter | get_params () const noexcept |
Return the currently used SVM parameter. More... | |
void | set_params (parameter params) noexcept |
Override the old SVM parameter with the new plssvm::parameter params . More... | |
template<typename... Args, PLSSVM_REQUIRES(detail::has_only_parameter_named_args_v< Args... >) > | |
void | set_params (Args &&...named_args) |
Override the old SVM parameter with the new ones given as named parameters in named_args . More... | |
template<typename real_type , typename label_type , typename... Args> | |
model< real_type, label_type > | fit (const data_set< real_type, label_type > &data, Args &&...named_args) const |
Fit a model using the current SVM on the data . More... | |
template<typename real_type , typename label_type > | |
std::vector< label_type > | predict (const model< real_type, label_type > &model, const data_set< real_type, label_type > &data) const |
Predict the labels for the data set using the model . More... | |
template<typename real_type , typename label_type > | |
real_type | score (const model< real_type, label_type > &model) const |
Calculate the accuracy of the model . More... | |
template<typename real_type , typename label_type > | |
real_type | score (const model< real_type, label_type > &model, const data_set< real_type, label_type > &data) const |
Calculate the accuracy of the labeled data set using the model . More... | |
Protected Member Functions | |
virtual 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 =0 |
Solves the equation \(Ax = b\) using the Conjugated Gradients algorithm. More... | |
virtual 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 =0 |
Solves the equation \(Ax = b\) using the Conjugated Gradients algorithm. More... | |
virtual 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 =0 |
Uses the already learned model to predict the class of multiple (new) data points. More... | |
virtual 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 =0 |
Uses the already learned model to predict the class of multiple (new) data points. More... | |
Protected Attributes | |
target_platform | target_ { plssvm::target_platform::automatic } |
The target platform of this SVM. | |
Private Member Functions | |
void | sanity_check_parameter () const |
Perform some sanity checks on the passed SVM parameters. More... | |
Private Attributes | |
parameter | params_ {} |
The SVM parameter (e.g., cost, degree, gamma, coef0) currently in use. | |
Base class for all C-SVM backends.
This class implements all features shared between all C-SVM backends. It defines the whole public API of a C-SVM.
|
inlineexplicit |
Construct a C-SVM using the SVM parameter params
.
Uses the default SVM parameter if none are provided.
[in] | params | the SVM parameter |
|
explicit |
Construct a C-SVM forwarding all parameters args
to the plssvm::parameter constructor.
Args | the type of the (named-)parameters |
[in] | args | the parameters used to construct a plssvm::parameter |
Delete copy-assignment operator since a CSVM is a move-only type.
*this
Default move-assignment operator since a virtual destructor has been declared.
*this
|
inlinenoexcept |
Return the target platform (i.e, CPU or GPU including the vendor) this SVM runs on.
[[nodiscard]]
)
|
inlinenoexcept |
Return the currently used SVM parameter.
[[nodiscard]]
)
|
inlinenoexcept |
Override the old SVM parameter with the new plssvm::parameter params
.
[in] | params | the new SVM parameter to use |
void plssvm::csvm::set_params | ( | Args &&... | named_args | ) |
Override the old SVM parameter with the new ones given as named parameters in named_args
.
Args | the type of the named-parameters |
[in] | named_args | the potential named-parameters |
model< real_type, label_type > plssvm::csvm::fit | ( | const data_set< real_type, label_type > & | data, |
Args &&... | named_args | ||
) | const |
Fit a model using the current SVM on the data
.
real_type | the type of the data (float or double ) |
label_type | the type of the label (an arithmetic type or std::string ) |
Args | the type of the potential additional parameters |
[in] | data | the data used to train the SVM model |
[in] | named_args | the potential additional parameters (epsilon and/or max_iter ) |
plssvm::invalid_parameter_exception | if the provided value for epsilon is greater or equal than zero |
plssvm::invlaid_parameter_exception | if the provided maximum number of iterations is less or equal than zero |
plssvm::invalid_parameter_exception | if the training data does not include labels |
plssvm::exception | any exception thrown in the respective backend's implementation of plssvm::csvm::solve_system_of_linear_equations |
[[nodiscard]]
) std::vector< label_type > plssvm::csvm::predict | ( | const model< real_type, label_type > & | model, |
const data_set< real_type, label_type > & | data | ||
) | const |
Predict the labels for the data
set using the model
.
real_type | the type of the data (float or double ) |
label_type | the type of the label (an arithmetic type or std::string ) |
[in] | model | a previously learned model |
[in] | data | the data to predict the labels for |
plssvm::invalid_parameter_exception | if the number of features in the model's support vectors don't match the number of features in the data set |
plssvm::exception | any exception thrown in the respective backend's implementation of plssvm::csvm::predict_values |
[[nodiscard]]
) real_type plssvm::csvm::score | ( | const model< real_type, label_type > & | model | ) | const |
Calculate the accuracy of the model
.
real_type | the type of the data (float or double ) |
label_type | the type of the label (an arithmetic type or std::string ) |
[in] | model | a previously learned model |
plssvm::exception | any exception thrown in the respective backend's implementation of plssvm::csvm::predict_values |
[[nodiscard]]
) real_type plssvm::csvm::score | ( | const model< real_type, label_type > & | model, |
const data_set< real_type, label_type > & | data | ||
) | const |
Calculate the accuracy of the labeled data
set using the model
.
real_type | the type of the data (float or double ) |
label_type | the type of the label (an arithmetic type or std::string ) |
[in] | model | a previously learned model |
[in] | data | the labeled data set to score |
plssvm::invalid_parameter_exception | if the data to score has no labels |
plssvm::invalid_parameter_exception | if the number of features in the model's support vectors don't match the number of features in the data set |
plssvm::exception | any exception thrown in the respective backend's implementation of plssvm::csvm::predict_values |
data
([[nodiscard]]
)
|
protectedpure virtual |
Solves the equation \(Ax = b\) using the Conjugated Gradients algorithm.
Uses a slightly modified version of the CG algorithm described by Jonathan Richard Shewchuk:
[in] | params | the SVM parameters used in the respective kernel functions |
[in] | A | the matrix of the equation \(Ax = b\) (symmetric positive definite) |
[in] | b | the right-hand side of the equation \(Ax = b\) |
[in] | eps | the error tolerance |
[in] | max_iter | the maximum number of CG iterations |
plssvm::exception | any exception thrown by the backend's implementation |
[[nodiscard]]
) Implemented in plssvm::detail::gpu_csvm< device_ptr_t, queue_t >, plssvm::detail::gpu_csvm< detail::device_ptr, int >, plssvm::detail::gpu_csvm< detail::device_ptr, detail::command_queue >, plssvm::detail::gpu_csvm< detail::device_ptr, detail::queue >, and plssvm::openmp::csvm.
|
protectedpure virtual |
Solves the equation \(Ax = b\) using the Conjugated Gradients algorithm.
Uses a slightly modified version of the CG algorithm described by Jonathan Richard Shewchuk:
[in] | params | the SVM parameters used in the respective kernel functions |
[in] | A | the matrix of the equation \(Ax = b\) (symmetric positive definite) |
[in] | b | the right-hand side of the equation \(Ax = b\) |
[in] | eps | the error tolerance |
[in] | max_iter | the maximum number of CG iterations |
plssvm::exception | any exception thrown by the backend's implementation |
[[nodiscard]]
) Implemented in plssvm::detail::gpu_csvm< device_ptr_t, queue_t >, plssvm::detail::gpu_csvm< detail::device_ptr, int >, plssvm::detail::gpu_csvm< detail::device_ptr, detail::command_queue >, plssvm::detail::gpu_csvm< detail::device_ptr, detail::queue >, and plssvm::openmp::csvm.
|
protectedpure virtual |
Uses the already learned model to predict the class of multiple (new) data points.
[in] | params | the SVM parameters used in the respective kernel functions |
[in] | support_vectors | the previously learned support vectors |
[in] | alpha | the alpha values (weights) associated with the support vectors |
[in] | rho | the rho value determined after training the model |
[in,out] | w | the normal vector to speedup prediction in case of the linear kernel function, an empty vector in case of the polynomial or rbf kernel |
[in] | predict_points | the points to predict |
plssvm::exception | any exception thrown by the backend's implementation |
[[nodiscard]]
) Implemented in plssvm::detail::gpu_csvm< device_ptr_t, queue_t >, plssvm::detail::gpu_csvm< detail::device_ptr, int >, plssvm::detail::gpu_csvm< detail::device_ptr, detail::command_queue >, plssvm::detail::gpu_csvm< detail::device_ptr, detail::queue >, and plssvm::openmp::csvm.
|
protectedpure virtual |
Uses the already learned model to predict the class of multiple (new) data points.
[in] | params | the SVM parameters used in the respective kernel functions |
[in] | support_vectors | the previously learned support vectors |
[in] | alpha | the alpha values (weights) associated with the support vectors |
[in] | rho | the rho value determined after training the model |
[in,out] | w | the normal vector to speedup prediction in case of the linear kernel function, an empty vector in case of the polynomial or rbf kernel |
[in] | predict_points | the points to predict |
plssvm::exception | any exception thrown by the backend's implementation |
[[nodiscard]]
) Implemented in plssvm::detail::gpu_csvm< device_ptr_t, queue_t >, plssvm::detail::gpu_csvm< detail::device_ptr, int >, plssvm::detail::gpu_csvm< detail::device_ptr, detail::command_queue >, plssvm::detail::gpu_csvm< detail::device_ptr, detail::queue >, and plssvm::openmp::csvm.
|
inlineprivate |
Perform some sanity checks on the passed SVM parameters.
plssvm::invalid_parameter_exception | if the kernel function is invalid |
plssvm::invalid_parameter_exception | if the gamma value for the polynomial or radial basis function kernel is not greater than zero |