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

Function solve_structural_svm_problem_impl

tools/python/src/svm_struct.cpp:75–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73
74template <typename psi_type>
75matrix<double,0,1> solve_structural_svm_problem_impl(
76 py::object problem
77)
78{
79 const double C = problem.attr("C").cast<double>();
80 const bool be_verbose = py::hasattr(problem,"be_verbose") && problem.attr("be_verbose").cast<bool>();
81 const bool use_sparse_feature_vectors = py::hasattr(problem,"use_sparse_feature_vectors") &&
82 problem.attr("use_sparse_feature_vectors").cast<bool>();
83 const bool learns_nonnegative_weights = py::hasattr(problem,"learns_nonnegative_weights") &&
84 problem.attr("learns_nonnegative_weights").cast<bool>();
85
86 double eps = 0.001;
87 unsigned long max_cache_size = 10;
88 if (py::hasattr(problem, "epsilon"))
89 eps = problem.attr("epsilon").cast<double>();
90 if (py::hasattr(problem, "max_cache_size"))
91 max_cache_size = problem.attr("max_cache_size").cast<double>();
92
93 const long num_samples = problem.attr("num_samples").cast<long>();
94 const long num_dimensions = problem.attr("num_dimensions").cast<long>();
95
96 pyassert(num_samples > 0, "You can't train a Structural-SVM if you don't have any training samples.");
97
98 if (be_verbose)
99 {
100 cout << "C: " << C << endl;
101 cout << "epsilon: " << eps << endl;
102 cout << "max_cache_size: " << max_cache_size << endl;
103 cout << "num_samples: " << num_samples << endl;
104 cout << "num_dimensions: " << num_dimensions << endl;
105 cout << "use_sparse_feature_vectors: " << std::boolalpha << use_sparse_feature_vectors << endl;
106 cout << "learns_nonnegative_weights: " << std::boolalpha << learns_nonnegative_weights << endl;
107 cout << endl;
108 }
109
110 svm_struct_prob<psi_type> prob(problem, num_dimensions, num_samples);
111 prob.set_c(C);
112 prob.set_epsilon(eps);
113 prob.set_max_cache_size(max_cache_size);
114 if (be_verbose)
115 prob.be_verbose();
116
117 oca solver;
118 matrix<double,0,1> w;
119 if (learns_nonnegative_weights)
120 solver(prob, w, prob.get_num_dimensions());
121 else
122 solver(prob, w);
123 return w;
124}
125
126// ----------------------------------------------------------------------------------------
127

Callers

nothing calls this directly

Calls 7

hasattrFunction · 0.85
attrMethod · 0.80
set_cMethod · 0.45
set_epsilonMethod · 0.45
set_max_cache_sizeMethod · 0.45
be_verboseMethod · 0.45
get_num_dimensionsMethod · 0.45

Tested by

no test coverage detected