Deep Learning Algorithm Implementations 1.0.0
C++ implementations of fundamental deep learning algorithms
Loading...
Searching...
No Matches
ml::SVM< T > Class Template Reference

#include <svm.hpp>

Public Member Functions

 SVM (KernelType kernel_type=KernelType::RBF, T C=1.0, T gamma=1.0, int degree=3, T coef0=0.0, T tol=1e-3, size_t max_iter=1000, T learning_rate=0.01)
 Constructor.
 
void fit (const Matrix< T > &X, const std::vector< int > &y)
 Fit the SVM model to training data using automatic differentiation.
 
std::vector< intpredict (const Matrix< T > &X) const
 Predict class labels for samples.
 
Matrix< T > predict_proba (const Matrix< T > &X) const
 Predict class probabilities for samples.
 
std::vector< T > decision_function (const Matrix< T > &X) const
 Compute the decision function for samples.
 
Matrix< T > support_vectors () const
 Get support vectors.
 
std::vector< size_tsupport () const
 Get support vector indices.
 
std::vector< T > dual_coef () const
 Get dual coefficients.
 
intercept () const
 Get intercept term.
 
std::vector< T > loss_history () const
 Get training loss history.
 

Detailed Description

template<typename T>
class ml::SVM< T >

Definition at line 52 of file svm.hpp.

Constructor & Destructor Documentation

◆ SVM()

template<typename T >
ml::SVM< T >::SVM ( KernelType  kernel_type = KernelType::RBF,
C = 1.0,
gamma = 1.0,
int  degree = 3,
coef0 = 0.0,
tol = 1e-3,
size_t  max_iter = 1000,
learning_rate = 0.01 
)

Constructor.

Parameters
kernel_typeType of kernel function to use
CRegularization parameter
gammaKernel coefficient for RBF, polynomial and sigmoid kernels
degreeDegree for polynomial kernel
coef0Independent term for polynomial and sigmoid kernels
tolTolerance for stopping criterion
max_iterMaximum number of iterations
learning_rateLearning rate for gradient descent

Definition at line 12 of file svm.cpp.

Member Function Documentation

◆ decision_function()

template<typename T >
std::vector< T > ml::SVM< T >::decision_function ( const Matrix< T > &  X) const

Compute the decision function for samples.

Parameters
XInput samples matrix (n_samples x n_features)
Returns
Vector of decision function values
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/svm.hpp.

Definition at line 290 of file svm.cpp.

◆ dual_coef()

template<typename T >
std::vector< T > ml::SVM< T >::dual_coef ( ) const

Get dual coefficients.

Returns
Vector of dual coefficients
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/svm.hpp.

Definition at line 342 of file svm.cpp.

◆ fit()

template<typename T >
void ml::SVM< T >::fit ( const Matrix< T > &  X,
const std::vector< int > &  y 
)

Fit the SVM model to training data using automatic differentiation.

Parameters
XTraining features matrix (n_samples x n_features)
yTraining labels vector
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/svm.hpp.

Definition at line 31 of file svm.cpp.

◆ intercept()

template<typename T >
T ml::SVM< T >::intercept ( ) const

Get intercept term.

Returns
Intercept value
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/svm.hpp.

Definition at line 347 of file svm.cpp.

◆ loss_history()

template<typename T >
std::vector< T > ml::SVM< T >::loss_history ( ) const
inline

Get training loss history.

Returns
Vector of loss values during training
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/svm.hpp.

Definition at line 124 of file svm.hpp.

◆ predict()

template<typename T >
std::vector< int > ml::SVM< T >::predict ( const Matrix< T > &  X) const

Predict class labels for samples.

Parameters
XInput samples matrix (n_samples x n_features)
Returns
Vector of predicted class labels
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/svm.hpp.

Definition at line 274 of file svm.cpp.

◆ predict_proba()

template<typename T >
Matrix< T > ml::SVM< T >::predict_proba ( const Matrix< T > &  X) const

Predict class probabilities for samples.

Parameters
XInput samples matrix (n_samples x n_features)
Returns
Matrix of class probabilities (n_samples x n_classes)
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/svm.hpp.

Definition at line 317 of file svm.cpp.

◆ support()

template<typename T >
std::vector< size_t > ml::SVM< T >::support ( ) const

Get support vector indices.

Returns
Vector of support vector indices
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/svm.hpp.

Definition at line 337 of file svm.cpp.

◆ support_vectors()

template<typename T >
Matrix< T > ml::SVM< T >::support_vectors ( ) const

Get support vectors.

Returns
Matrix of support vectors
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/svm.hpp.

Definition at line 332 of file svm.cpp.


The documentation for this class was generated from the following files: