MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / svm_binary_svc_probability

Function svm_binary_svc_probability

ml/src/svm.cpp:2188–2285  ·  view source on GitHub ↗

Cross-validation decision values for probability estimates

Source from the content-addressed store, hash-verified

2186
2187// Cross-validation decision values for probability estimates
2188static void
2189svm_binary_svc_probability(const svm_problem* prob,
2190 const svm_parameter* param,
2191 double Cp,
2192 double Cn,
2193 double& probA,
2194 double& probB)
2195{
2196 int nr_fold = 5;
2197 int* perm = Malloc(int, prob->l);
2198 double* dec_values = Malloc(double, prob->l);
2199
2200 // random shuffle
2201
2202 for (int i = 0; i < prob->l; i++)
2203 perm[i] = i;
2204
2205 for (int i = 0; i < prob->l; i++) {
2206 int j = i + rand() % (prob->l - i);
2207 swap(perm[i], perm[j]);
2208 }
2209
2210 for (int i = 0; i < nr_fold; i++) {
2211 int begin = i * prob->l / nr_fold;
2212 int end = (i + 1) * prob->l / nr_fold;
2213
2214 struct svm_problem subprob;
2215
2216 subprob.l = prob->l - (end - begin);
2217 subprob.x = Malloc(struct svm_node*, subprob.l);
2218 subprob.y = Malloc(double, subprob.l);
2219
2220 int k = 0;
2221
2222 for (int j = 0; j < begin; j++) {
2223 subprob.x[k] = prob->x[perm[j]];
2224 subprob.y[k] = prob->y[perm[j]];
2225 ++k;
2226 }
2227
2228 for (int j = end; j < prob->l; j++) {
2229 subprob.x[k] = prob->x[perm[j]];
2230 subprob.y[k] = prob->y[perm[j]];
2231 ++k;
2232 }
2233
2234 int p_count = 0, n_count = 0;
2235
2236 for (int j = 0; j < k; j++)
2237 if (subprob.y[j] > 0)
2238 p_count++;
2239 else
2240 n_count++;
2241
2242 if (p_count == 0 && n_count == 0)
2243 for (int j = begin; j < end; j++)
2244 dec_values[perm[j]] = 0;
2245 else if (p_count > 0 && n_count == 0)

Callers 1

svm_trainFunction · 0.85

Calls 6

svm_trainFunction · 0.85
svm_predict_valuesFunction · 0.85
svm_destroy_paramFunction · 0.85
sigmoid_trainFunction · 0.85
swapFunction · 0.70

Tested by

no test coverage detected