training class ----------------- ^ \ ------------| | > | | | objective function -----> | svm class | | ^ > | | | | / ------------| kernel functor ---------------Being the svm class the main object to be instantiated by the user, giving the desired selectors.
svm<KernelT,PointsBigContainer,WeightsContainerT,b_Type,AlphasContainerT, TargetsContainer,ErrorContainerT,ToleranceT,CType,SigmaT>
Parameter | Description | Default | Models |
---|---|---|---|
KernelT | Type of kernel selector: linear_kernelS, gaussian_kernelS,polynomial_kernelS, or hyper_tangentS | linear_kernelS | complete type |
PointsBigContainer | Type of the sequence of sequences that contain the training points | std::vector<std::vector<double> > | sequence of sequences |
WeightsContainerT | Selector for the type of sequence that contain the weights | morpho_svm::vecS | complete type |
b_Type | Type for the bias value | double | floating point type |
AlphasContainerT | Selector for the type of sequence that contain the alphas | morpho_svm::vecS | complete type |
TargetsContainer | Type of the sequence that contain the target points | std::vector<double> | sequence |
ErrorContainerT | Selector for the type of sequence that contain the errors | morpho_svm::vecS | complete type |
ToleranceT | Type for the tolerance | double | floating point |
CType | Type for the C value | double | floating point |
SigmaT | Type for the Sigma value | double | floating point |
#include <morpho/svm/Svmtl.hpp>
Kernel Type | Description | svm class Constructor prototype |
---|---|---|
linear_kernelS | Linear kenel: K(x,y) = (x dot y) |
svm(ToleranceT tol, CType e_C, examples_container_t& points, targets_container_t& targets) |
gaussian_kernelS | Gaussian kenel: K(x,y) = (exp (- |x - y|^2 / (2 * sigma^2) ) ) |
svm(const SigmaT e_sigma, const ToleranceT tol, const CType e_C, examples_container_t& points, targets_container_t& targets) |
polynomial_kernelS | Polynomial kernel: K(x,y) = (((x dot y) + bias) ^ degree) |
svm(const SigmaT e_degree, const SigmaT e_kernel_bias, ToleranceT tol, CType e_C, examples_container_t& points, targets_container_t& targets) |
hyper_tangentS | Hyperbolic kernel: K(x,y) = tanh(sigma*(x dot y) - shift) |
svm(const SigmaT e_sigma, const SigmaT e_shift, ToleranceT tol, CType e_C, examples_container_t& points, targets_container_t& targets, const SigmaT dummy) |
Selector | Description |
---|---|
vecS | selects std::vector<> for the container |
listS | selects std::list<> for the container |
morpho_svm::svm<> svm_class(tol, C, training, target); // linear kernellnotes:
svm_class.smo_me(svm_class);At this point, we have calculated the support vectors. What's left is to calculate the separation from the hyperplane these support vectors creates, of the points we want to classify (vectors to be predicted).
//.- For linear kernels: X^T * W - b . X being the points to predict. mult.resize(test.size()); //Multiply: lata::matrix_vector(test.begin(), test.end(),svm_class.weights.begin(),mult.begin(), nin::multiply<double, double>(),nin::assign<double>()); //Substract b: nin::permanent_substract<double, double> subs(svm_class.b); std::for_each(mult.begin(), mult.end(), subs); //.- For non-linear kernels: Sum[1..n.points] (alpha[i] * target[i] * kernel(X[i],point) ) - b for (int j=0; j<test.size(); ++j) { double result(0.0); for (int i=0; i<svm_class.errors.size(); ++i) { result+= svm_class.alphas[i] * target[i] * svm_class.kernel(training.sets[i].begin(),training.sets[i].end(),test.sets[j].begin()); } result-= svm_class.b; all_results.push_back(result); }