]> granicus.if.org Git - liblinear/commitdiff
In get_decfun_coef and get_decfun_bias, a zero value is returned in all invalid
authorYu-Chin <guestwalk@gmail.com>
Tue, 21 Oct 2014 19:32:51 +0000 (03:32 +0800)
committerYu-Chin <guestwalk@gmail.com>
Tue, 21 Oct 2014 19:32:56 +0000 (03:32 +0800)
cases. We decide not to return NaN because we are not sure if it can be
properly assigned in all platforms. (For example, ``double nan = 0.0/0.0;''
won't compile in Visual Studio.)

README
linear.cpp

diff --git a/README b/README
index 256028798ac90c0baa5ac2ac97586012a3f69330..9ea3381c2d6a6e8ce66ba4860a27a026e32bbe88 100644 (file)
--- a/README
+++ b/README
@@ -453,15 +453,18 @@ Library Usage
 
     This function gives the coefficient for the feature with feature index =
     feat_idx and the class with label index = label_idx. Note that feat_idx
-    starts from 1, while label_idx starts from 0. If label_idx is not in the
-    valid range (0 to nr_class-1), then a NaN will be returned; and if feat_idx
-    is not in the valid range (1 to nr_feature), then a zero value will be
-    returned. For regression models, label_idx is ignored.
+    starts from 1, while label_idx starts from 0. If feat_idx is not in the
+    valid range (1 to nr_feature), then a zero value will be returned. For
+    classification models, if label_idx is not in the valid range (0 to
+    nr_class-1), then a zero value will be returned; for regression models,
+    label_idx is ignored.
 
 - Function: double get_decfun_bias(const struct model *model_, int label_idx);
 
-    This function gives the bias term corresponding to the class with the 
-    label_idx. For regression models, label_idx is ignored.
+    This function gives the bias term corresponding to the class with the
+    label_idx. For classification models, if label_idx is not in a valid range
+    (0 to nr_class-1), then a zero value will be returned; for regression
+    models, label_idx is ignored.
 
 - Function: const char *check_parameter(const struct problem *prob,
             const struct parameter *param);
index 52d670095d880f232445ca409e1495f43f2f364a..302e1e1b9449e878524abcf0f8db4dbca2f16f15 100644 (file)
@@ -2767,17 +2767,14 @@ static inline double get_w_value(const struct model *model_, int idx, int label_
        int solver_type = model_->param.solver_type;
        const double *w = model_->w;
 
-       if(!check_regression_model(model_) && (label_idx < 0 || label_idx >= nr_class)) 
-       {
-               const double nan = 0.0/0.0;
-               return nan;
-       }
        if(idx < 0 || idx > model_->nr_feature)
                return 0;
        if(check_regression_model(model_))
                return w[idx];
        else 
        {
+               if(label_idx < 0 || label_idx >= nr_class)
+                       return 0;
                if(nr_class == 2 && solver_type != MCSVM_CS)
                {
                        if(label_idx == 0)