Definition at line 2357 of file svm.cpp. References svm_parameter::coef0, svm_parameter::degree, svm_parameter::gamma, svm_parameter::kernel_type, svm_model::l, svm_model::label, svm_model::nr_class, svm_model::param, POLY, RBF, svm_model::rho, SIGMOID, and svm_parameter::svm_type. Referenced by Impala::Core::Training::Svm::SaveModel(). 02358 { 02359 FILE *fp = fopen(model_file_name,"w"); 02360 if(fp==NULL) return -1; 02361 02362 const svm_parameter& param = model->param; 02363 02364 fprintf(fp,"svm_type %s\n", svm_type_table[param.svm_type]); 02365 fprintf(fp,"kernel_type %s\n", kernel_type_table[param.kernel_type]); 02366 02367 if(param.kernel_type == POLY) 02368 fprintf(fp,"degree %g\n", param.degree); 02369 02370 if(param.kernel_type == POLY || param.kernel_type == RBF || param.kernel_type == SIGMOID) 02371 fprintf(fp,"gamma %g\n", param.gamma); 02372 02373 if(param.kernel_type == POLY || param.kernel_type == SIGMOID) 02374 fprintf(fp,"coef0 %g\n", param.coef0); 02375 02376 int nr_class = model->nr_class; 02377 int l = model->l; 02378 fprintf(fp, "nr_class %d\n", nr_class); 02379 fprintf(fp, "total_sv %d\n",l); 02380 02381 { 02382 fprintf(fp, "rho"); 02383 for(int i=0;i<nr_class*(nr_class-1)/2;i++) 02384 fprintf(fp," %g",model->rho[i]); 02385 fprintf(fp, "\n"); 02386 } 02387 02388 if(model->label) 02389 { 02390 fprintf(fp, "label"); 02391 for(int i=0;i<nr_class;i++) 02392 fprintf(fp," %d",model->label[i]); 02393 fprintf(fp, "\n"); 02394 } 02395 02396 if(model->probA) // regression has probA only 02397 { 02398 fprintf(fp, "probA"); 02399 for(int i=0;i<nr_class*(nr_class-1)/2;i++) 02400 fprintf(fp," %g",model->probA[i]); 02401 fprintf(fp, "\n"); 02402 } 02403 if(model->probB) 02404 { 02405 fprintf(fp, "probB"); 02406 for(int i=0;i<nr_class*(nr_class-1)/2;i++) 02407 fprintf(fp," %g",model->probB[i]); 02408 fprintf(fp, "\n"); 02409 } 02410 02411 if(model->nSV) 02412 { 02413 fprintf(fp, "nr_sv"); 02414 for(int i=0;i<nr_class;i++) 02415 fprintf(fp," %d",model->nSV[i]); 02416 fprintf(fp, "\n"); 02417 } 02418 02419 fprintf(fp, "SV\n"); 02420 const double * const *sv_coef = model->sv_coef; 02421 const svm_node * const *SV = model->SV; 02422 02423 for(int i=0;i<l;i++) 02424 { 02425 for(int j=0;j<nr_class-1;j++) 02426 fprintf(fp, "%.16g ",sv_coef[j][i]); 02427 02428 const svm_node *p = SV[i]; 02429 while(p->index != -1) 02430 { 02431 fprintf(fp,"%d:%.8g ",p->index,p->value); 02432 p++; 02433 } 02434 fprintf(fp, "\n"); 02435 } 02436 02437 fclose(fp); 02438 return 0; 02439 }
|