LCOV - code coverage report
Current view: top level - src - gensvm_sv.c (source / functions) Hit Total Coverage
Test: coverage.all Lines: 9 9 100.0 %
Date: 2017-02-21 18:44:20 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file gensvm_sv.c
       3             :  * @author G.J.J. van den Burg
       4             :  * @date 2014-05-01
       5             :  * @brief Calculate the number of support vectors
       6             :  *
       7             :  * @details
       8             :  * The function in this file can be used to calculate the number of support
       9             :  * vectors are left in a model.
      10             :  *
      11             :  * @copyright
      12             :  Copyright 2016, G.J.J. van den Burg.
      13             : 
      14             :  This file is part of GenSVM.
      15             : 
      16             :  GenSVM is free software: you can redistribute it and/or modify
      17             :  it under the terms of the GNU General Public License as published by
      18             :  the Free Software Foundation, either version 3 of the License, or
      19             :  (at your option) any later version.
      20             : 
      21             :  GenSVM is distributed in the hope that it will be useful,
      22             :  but WITHOUT ANY WARRANTY; without even the implied warranty of
      23             :  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      24             :  GNU General Public License for more details.
      25             : 
      26             :  You should have received a copy of the GNU General Public License
      27             :  along with GenSVM. If not, see <http://www.gnu.org/licenses/>.
      28             : 
      29             :  */
      30             : 
      31             : #include "gensvm_sv.h"
      32             : 
      33             : /**
      34             :  * @brief Calculate the number of support vectors in a model
      35             :  *
      36             :  * @details
      37             :  * If an object is correctly classified, the number of classes for which the
      38             :  * error q is larger than 1, is K-1 (i.e., there is no error w.r.t. any of the
      39             :  * other classes).  All objects for which this is not the case are thus support
      40             :  * vectors.
      41             :  *
      42             :  * @param[in]   model   GenModel with solution and up-to-date Q matrix
      43             :  * @return              number of support vectors with this solution
      44             :  *
      45             :  */
      46           4 : long gensvm_num_sv(struct GenModel *model)
      47             : {
      48           4 :         long i, j, num_correct, num_sv = 0;
      49             :         double value;
      50             : 
      51          37 :         for (i=0; i<model->n; i++) {
      52          33 :                 num_correct = 0;
      53         160 :                 for (j=0; j<model->K; j++) {
      54         127 :                         value = matrix_get(model->Q, model->K, i, j);
      55         127 :                         num_correct += (value > 1);
      56             :                 }
      57          33 :                 num_sv += (num_correct < model->K - 1);
      58             :         }
      59             : 
      60           4 :         return num_sv;
      61             : }

Generated by: LCOV version 1.12