From aba529b38b413eafc46ae826f1a7b6a57ae18aab Mon Sep 17 00:00:00 2001 From: Davis King Date: Mon, 30 Mar 2009 00:28:57 +0000 Subject: [PATCH] Switched the svm_nu_trainer object's kernel cache from using the type of scalar used by the user supplied kernel to just always use float. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402976 --- dlib/svm/svm.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/dlib/svm/svm.h b/dlib/svm/svm.h index 5af5237f0..3171eac42 100644 --- a/dlib/svm/svm.h +++ b/dlib/svm/svm.h @@ -136,7 +136,9 @@ namespace dlib > class kernel_matrix_cache { - typedef typename K::scalar_type scalar_type; + public: + typedef float scalar_type; + //typedef typename K::scalar_type scalar_type; typedef typename K::sample_type sample_type; typedef typename K::mem_manager_type mem_manager_type; @@ -1076,6 +1078,7 @@ namespace dlib scalar_vector_type alpha; kernel_matrix_cache Q(x,y,kernel_function,cache_size); + typedef typename kernel_matrix_cache::scalar_type cache_type; alpha.set_size(x.nr()); df.set_size(x.nr()); @@ -1090,7 +1093,7 @@ namespace dlib { if (alpha(r) != 0) { - const scalar_type* Q_r = Q.col(r); + const cache_type* Q_r = Q.col(r); for (long c = 0; c < alpha.nr(); ++c) { df(c) += alpha(r)*Q_r[c]; @@ -1111,8 +1114,8 @@ namespace dlib scalar_type delta_alpha_i = alpha(i) - old_alpha_i; scalar_type delta_alpha_j = alpha(j) - old_alpha_j; - const scalar_type* Q_i = Q.col(i); - const scalar_type* Q_j = Q.col(j); + const cache_type* Q_i = Q.col(i); + const cache_type* Q_j = Q.col(j); for(long k = 0; k < df.nr(); ++k) df(k) += Q_i[k]*delta_alpha_i + Q_j[k]*delta_alpha_j; @@ -1257,6 +1260,9 @@ namespace dlib long in = -1; long jn = -1; + + typedef typename kernel_matrix_cache::scalar_type cache_type; + scalar_type ip_val = -numeric_limits::infinity(); scalar_type jp_val = numeric_limits::infinity(); scalar_type in_val = -numeric_limits::infinity(); @@ -1297,9 +1303,9 @@ namespace dlib // As a speed hack, pull out pointers to the columns of the // kernel matrix we will be using below rather than accessing // them through the Q(r,c) syntax. - const scalar_type* Q_ip = 0; - const scalar_type* Q_in = 0; - const scalar_type* Q_diag = Q.diag(); + const cache_type* Q_ip = 0; + const cache_type* Q_in = 0; + const cache_type* Q_diag = Q.diag(); if (ip != -1) Q_ip = Q.col(ip); if (in != -1)