ext/numo/libsvm/libsvmext.hpp in numo-libsvm-2.0.1 vs ext/numo/libsvm/libsvmext.hpp in numo-libsvm-2.1.0
- old
+ new
@@ -46,10 +46,12 @@
typedef struct svm_parameter LibSvmParameter;
typedef struct svm_problem LibSvmProblem;
void printNull(const char* s) {}
+#define NR_MARKS 10
+
/** CONVERTERS */
VALUE convertVectorXiToNArray(const int* const arr, const int size) {
size_t shape[1] = {(size_t)size};
VALUE vec_val = rb_narray_new(numo_cInt32, 1, shape);
int32_t* vec_ptr = (int32_t*)na_get_pointer_for_write(vec_val);
@@ -213,10 +215,12 @@
model->rho = convertNArrayToVectorXd(el);
el = rb_hash_aref(model_hash, ID2SYM(rb_intern("probA")));
model->probA = convertNArrayToVectorXd(el);
el = rb_hash_aref(model_hash, ID2SYM(rb_intern("probB")));
model->probB = convertNArrayToVectorXd(el);
+ el = rb_hash_aref(model_hash, ID2SYM(rb_intern("prob_density_marks")));
+ model->prob_density_marks = convertNArrayToVectorXd(el);
el = rb_hash_aref(model_hash, ID2SYM(rb_intern("sv_indices")));
model->sv_indices = convertNArrayToVectorXi(el);
el = rb_hash_aref(model_hash, ID2SYM(rb_intern("label")));
model->label = convertNArrayToVectorXi(el);
el = rb_hash_aref(model_hash, ID2SYM(rb_intern("nSV")));
@@ -232,10 +236,11 @@
VALUE support_vecs = model->SV ? convertLibSvmNodeToNArray(model->SV, n_support_vecs) : Qnil;
VALUE coefficients = model->sv_coef ? convertMatrixXdToNArray(model->sv_coef, n_classes - 1, n_support_vecs) : Qnil;
VALUE intercepts = model->rho ? convertVectorXdToNArray(model->rho, n_classes * (n_classes - 1) / 2) : Qnil;
VALUE prob_alpha = model->probA ? convertVectorXdToNArray(model->probA, n_classes * (n_classes - 1) / 2) : Qnil;
VALUE prob_beta = model->probB ? convertVectorXdToNArray(model->probB, n_classes * (n_classes - 1) / 2) : Qnil;
+ VALUE prob_density_marks = model->prob_density_marks ? convertVectorXdToNArray(model->prob_density_marks, NR_MARKS) : Qnil;
VALUE sv_indices = model->sv_indices ? convertVectorXiToNArray(model->sv_indices, n_support_vecs) : Qnil;
VALUE labels = model->label ? convertVectorXiToNArray(model->label, n_classes) : Qnil;
VALUE n_support_vecs_each_class = model->nSV ? convertVectorXiToNArray(model->nSV, n_classes) : Qnil;
VALUE model_hash = rb_hash_new();
rb_hash_aset(model_hash, ID2SYM(rb_intern("nr_class")), INT2NUM(n_classes));
@@ -243,10 +248,11 @@
rb_hash_aset(model_hash, ID2SYM(rb_intern("SV")), support_vecs);
rb_hash_aset(model_hash, ID2SYM(rb_intern("sv_coef")), coefficients);
rb_hash_aset(model_hash, ID2SYM(rb_intern("rho")), intercepts);
rb_hash_aset(model_hash, ID2SYM(rb_intern("probA")), prob_alpha);
rb_hash_aset(model_hash, ID2SYM(rb_intern("probB")), prob_beta);
+ rb_hash_aset(model_hash, ID2SYM(rb_intern("prob_density_marks")), prob_density_marks);
rb_hash_aset(model_hash, ID2SYM(rb_intern("sv_indices")), sv_indices);
rb_hash_aset(model_hash, ID2SYM(rb_intern("label")), labels);
rb_hash_aset(model_hash, ID2SYM(rb_intern("nSV")), n_support_vecs_each_class);
rb_hash_aset(model_hash, ID2SYM(rb_intern("free_sv")), INT2NUM(model->free_sv));
return model_hash;
@@ -375,13 +381,11 @@
/** UTILITIES */
bool isSignleOutputModel(LibSvmModel* model) {
return (model->param.svm_type == ONE_CLASS || model->param.svm_type == EPSILON_SVR || model->param.svm_type == NU_SVR);
}
-bool isProbabilisticModel(LibSvmModel* model) {
- return ((model->param.svm_type == C_SVC || model->param.svm_type == NU_SVC) && model->probA != NULL && model->probB != NULL);
-}
+bool isProbabilisticModel(LibSvmModel* model) { return svm_check_probability_model(model) != 0; }
void deleteLibSvmModel(LibSvmModel* model) {
if (model) {
if (model->SV) {
for (int i = 0; i < model->l; i++) xfree(model->SV[i]);
@@ -397,9 +401,11 @@
model->rho = NULL;
xfree(model->probA);
model->probA = NULL;
xfree(model->probB);
model->probB = NULL;
+ xfree(model->prob_density_marks);
+ model->prob_density_marks = NULL;
xfree(model->sv_indices);
model->sv_indices = NULL;
xfree(model->label);
model->label = NULL;
xfree(model->nSV);