Definition at line 2125 of file svm.cpp. References C_SVC, svm_problem::l, Malloc, NU_SVC, svm_model::param, svm_parameter::probability, svm_destroy_model(), svm_get_nr_class(), svm_predict(), svm_predict_probability(), svm_train(), svm_parameter::svm_type, swap(), svm_problem::x, and svm_problem::y. Referenced by svm_svr_probability(). 02126 { 02127 int i; 02128 int *perm = Malloc(int,prob->l); 02129 02130 // random shuffle 02131 for(i=0;i<prob->l;i++) perm[i]=i; 02132 for(i=0;i<prob->l;i++) 02133 { 02134 int j = i+rand()%(prob->l-i); 02135 std::swap(perm[i],perm[j]); 02136 } 02137 for(i=0;i<nr_fold;i++) 02138 { 02139 int begin = i*prob->l/nr_fold; 02140 int end = (i+1)*prob->l/nr_fold; 02141 int j,k; 02142 struct svm_problem subprob; 02143 02144 subprob.l = prob->l-(end-begin); 02145 subprob.x = Malloc(struct svm_node*,subprob.l); 02146 subprob.y = Malloc(double,subprob.l); 02147 02148 k=0; 02149 for(j=0;j<begin;j++) 02150 { 02151 subprob.x[k] = prob->x[perm[j]]; 02152 subprob.y[k] = prob->y[perm[j]]; 02153 ++k; 02154 } 02155 for(j=end;j<prob->l;j++) 02156 { 02157 subprob.x[k] = prob->x[perm[j]]; 02158 subprob.y[k] = prob->y[perm[j]]; 02159 ++k; 02160 } 02161 struct svm_model *submodel = svm_train(&subprob,param); 02162 if(param->probability && 02163 (param->svm_type == C_SVC || param->svm_type == NU_SVC)) 02164 { 02165 double *prob_estimates=Malloc(double,svm_get_nr_class(submodel)); 02166 for(j=begin;j<end;j++) 02167 target[perm[j]] = svm_predict_probability(submodel,prob->x[perm[j]],prob_estimates); 02168 free(prob_estimates); 02169 } 02170 else 02171 for(j=begin;j<end;j++) 02172 target[perm[j]] = svm_predict(submodel,prob->x[perm[j]]); 02173 svm_destroy_model(submodel); 02174 free(subprob.x); 02175 free(subprob.y); 02176 } 02177 free(perm); 02178 }
Here is the call graph for this function:
|