MCPcopy Create free account
hub / github.com/davisking/dlib / find_c

Function find_c

dlib/test/auto_train_linear_classifier.cpp:47–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45 // svm_c_linear_dcd_trainer gives df, or 0 if none does.
46 template <typename kernel_type, typename sample_type>
47 double find_c (
48 const decision_function<kernel_type>& df,
49 const std::vector<sample_type>& x,
50 const std::vector<double>& y
51 )
52 {
53 const double num_pos = sum(mat(y) > 0);
54 const double num_neg = y.size() - num_pos;
55 for (int e = -6; e <= 6; ++e)
56 {
57 const double c = std::pow(10.0, e);
58 svm_c_linear_dcd_trainer<kernel_type> by_hand;
59 by_hand.set_c_class1(c*y.size()/(2*num_pos));
60 by_hand.set_c_class2(c*y.size()/(2*num_neg));
61 const auto expected = by_hand.train(x, y);
62 if (max(abs(sparse_to_dense(df.basis_vectors(0)) - sparse_to_dense(expected.basis_vectors(0)))) < 1e-9 &&
63 std::abs(df.b - expected.b) < 1e-9)
64 {
65 return c;
66 }
67 }
68 return 0;
69 }
70
71// ----------------------------------------------------------------------------------------
72

Callers 2

test_sparseFunction · 0.85
test_rare_positivesFunction · 0.85

Calls 9

absFunction · 0.85
sparse_to_denseFunction · 0.85
sumFunction · 0.50
matFunction · 0.50
maxFunction · 0.50
sizeMethod · 0.45
set_c_class1Method · 0.45
set_c_class2Method · 0.45
trainMethod · 0.45

Tested by

no test coverage detected