From 1e340d509f229120eb3aaa98c91028dc3c0d3305 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Mon, 25 Aug 2014 14:38:03 +0200 Subject: rename msvmmaj to gensvm --- src/gensvm_sv.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/gensvm_sv.c (limited to 'src/gensvm_sv.c') diff --git a/src/gensvm_sv.c b/src/gensvm_sv.c new file mode 100644 index 0000000..787b869 --- /dev/null +++ b/src/gensvm_sv.c @@ -0,0 +1,45 @@ +/** + * @file gensvm_sv.c + * @author Gertjan van den Burg + * @date May, 2014 + * @brief Calculate the number of support vectors + * + * @details + * The function in this file can be used to calculate the number of support + * vectors are left in a model. + * + */ + +#include "gensvm.h" +#include "gensvm_matrix.h" + +/** + * @brief Calculate the number of support vectors in a model + * + * @details + * If an object is correctly classified, the number of classes for which the + * error q is larger than 1, is K-1 (i.e., there is no error w.r.t. any of the + * other classes). All objects for which this is not the case are thus support + * vectors. + * + * @param[in] model GenModel with solution + * @param[in] data GenData to be used + * @return number of support vectors with this solution + * + */ +long gensvm_num_sv(struct GenModel *model, struct GenData *data) +{ + long i, j, num_correct, num_sv = 0; + double value; + + for (i=0; in; i++) { + num_correct = 0; + for (j=0; jK; j++) { + value = matrix_get(model->Q, data->K, i, j); + num_correct += (value > 1); + } + num_sv += (num_correct < data->K - 1); + } + + return num_sv; +} -- cgit v1.2.3