From 140243f275b0cfd493470ab2058e1501dcd83679 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 5 Dec 2009 19:07:20 +0000 Subject: [PATCH] Added a missing check for division by zero. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403306 --- dlib/svm/krls.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/dlib/svm/krls.h b/dlib/svm/krls.h index b90c12cda..b7272bf8b 100644 --- a/dlib/svm/krls.h +++ b/dlib/svm/krls.h @@ -94,17 +94,21 @@ namespace dlib const scalar_type kx = kern(x,x); if (alpha.size() == 0) { - // set initial state since this is the first training example we have seen + // just ignore this sample if it is the zero vector (or really close to being zero) + if (std::abs(kx) > std::numeric_limits::epsilon()) + { + // set initial state since this is the first training example we have seen - K_inv.set_size(1,1); - K_inv(0,0) = 1/kx; - K.set_size(1,1); - K(0,0) = kx; + K_inv.set_size(1,1); + K_inv(0,0) = 1/kx; + K.set_size(1,1); + K(0,0) = kx; - alpha.push_back(y/kx); - dictionary.push_back(x); - P.set_size(1,1); - P(0,0) = 1; + alpha.push_back(y/kx); + dictionary.push_back(x); + P.set_size(1,1); + P(0,0) = 1; + } } else {