diff --git a/main.cpp b/main.cpp index 7968f70..991231f 100644 --- a/main.cpp +++ b/main.cpp @@ -2,11 +2,18 @@ #include "svm_context.h" - +void xor_test(); int main(int argsc, char** args) { + + xor_test(); + getchar(); + return 0; +} +void xor_test() { // XOR test - - // Creating SVM model + + // create the matrix of xor truth table + // inputs: std::vector> attribute(4, std::vector(2)); attribute[0][0] = 0.0; attribute[0][1] = 0.0; @@ -17,18 +24,23 @@ int main(int argsc, char** args) { attribute[3][0] = 1.0; attribute[3][1] = 1.0; + // outputs: std::vector label(4); label[0] = 0; label[1] = 1; label[2] = 1; label[3] = 0; - // initialize svm object with default settings + // initialize svm object with default settings (edit the svm_context::param to change any parameters) + // ideally those settings (especially the kernel parameters) should come from svm training using libsvm library + svm_context _svm; if (_svm.init(attribute, label)) { - LIB_SVM::svm_model *model = _svm.generate_model(); + // create svm model using default settings + LIB_SVM::svm_model *model = _svm.generate_model(); + //testing the resulting model with testing node std::vectorsample(2); sample[0] = 1; sample[1] = 0; @@ -38,6 +50,11 @@ int main(int argsc, char** args) { _svm.predict_probability(sample, prediction, probability); _svm.predict(sample, prediction); + + //display the results to standard output + // libsvm creates probability value for each label and assigns the prediction + // to the label with maximum probability + std::cout << "\n***********************************\n" << "prediction: " << prediction @@ -46,8 +63,4 @@ int main(int argsc, char** args) { } else std::cout << "error in initializing svm" << std::endl; - _svm.release(); - - getchar(); - return 0; } \ No newline at end of file