From: Yu-Chin Date: Tue, 21 Oct 2014 19:32:51 +0000 (+0800) Subject: In get_decfun_coef and get_decfun_bias, a zero value is returned in all invalid X-Git-Tag: v195~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9c13dff5ad1b32e4a67eaed77c13365a86c68d7;p=liblinear In get_decfun_coef and get_decfun_bias, a zero value is returned in all invalid 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.) --- diff --git a/README b/README index 2560287..9ea3381 100644 --- 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); diff --git a/linear.cpp b/linear.cpp index 52d6700..302e1e1 100644 --- a/linear.cpp +++ b/linear.cpp @@ -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)