diff --git a/tools/python/src/svm_c_trainer.cpp b/tools/python/src/svm_c_trainer.cpp index 19fe79263..5dfaca5d3 100644 --- a/tools/python/src/svm_c_trainer.cpp +++ b/tools/python/src/svm_c_trainer.cpp @@ -83,7 +83,16 @@ class_ setup_trainer ( .def("set_c", set_c) .add_property("c_class1", get_c_class1, set_c_class1) .add_property("c_class2", get_c_class2, set_c_class2) - .add_property("epsilon", get_epsilon, set_epsilon) + .add_property("epsilon", get_epsilon, set_epsilon); +} + +template +class_ setup_trainer2 ( + const std::string& name +) +{ + + return setup_trainer(name) .add_property("cache_size", get_cache_size, set_cache_size); } @@ -157,23 +166,61 @@ const binary_test _cross_validate_trainer_t ( void bind_svm_c_trainer() { - setup_trainer > >("svm_c_trainer_radial_basis") - .add_property("gamma", get_gamma, set_gamma); - def("cross_validate_trainer", _cross_validate_trainer > >); - def("cross_validate_trainer_threaded", _cross_validate_trainer_t > >); + { + typedef svm_c_trainer > T; + setup_trainer2("svm_c_trainer_radial_basis") + .add_property("gamma", get_gamma, set_gamma); + def("cross_validate_trainer", _cross_validate_trainer); + def("cross_validate_trainer_threaded", _cross_validate_trainer_t); + } - setup_trainer > >("svm_c_trainer_sparse_radial_basis") - .add_property("gamma", get_gamma, set_gamma); - def("cross_validate_trainer", _cross_validate_trainer > >); - def("cross_validate_trainer_threaded", _cross_validate_trainer_t > >); + { + typedef svm_c_trainer > T; + setup_trainer2("svm_c_trainer_sparse_radial_basis") + .add_property("gamma", get_gamma, set_gamma); + def("cross_validate_trainer", _cross_validate_trainer); + def("cross_validate_trainer_threaded", _cross_validate_trainer_t); + } - setup_trainer > >("svm_c_trainer_histogram_intersection"); - def("cross_validate_trainer", _cross_validate_trainer > >); - def("cross_validate_trainer_threaded", _cross_validate_trainer_t > >); + { + typedef svm_c_trainer > T; + setup_trainer2("svm_c_trainer_histogram_intersection"); + def("cross_validate_trainer", _cross_validate_trainer); + def("cross_validate_trainer_threaded", _cross_validate_trainer_t); + } - setup_trainer > >("svm_c_trainer_sparse_histogram_intersection"); - def("cross_validate_trainer", _cross_validate_trainer > >); - def("cross_validate_trainer_threaded", _cross_validate_trainer_t > >); + { + typedef svm_c_trainer > T; + setup_trainer2("svm_c_trainer_sparse_histogram_intersection"); + def("cross_validate_trainer", _cross_validate_trainer); + def("cross_validate_trainer_threaded", _cross_validate_trainer_t); + } + + { + typedef svm_c_linear_trainer > T; + setup_trainer("svm_c_trainer_linear") + .add_property("max_iterations", &T::get_max_iterations, &T::set_max_iterations) + .add_property("force_last_weight_to_1", &T::forces_last_weight_to_1, &T::force_last_weight_to_1) + .add_property("learns_nonnegative_weights", &T::learns_nonnegative_weights, &T::set_learns_nonnegative_weights) + .def("be_verbose", &T::be_verbose) + .def("be_quiet", &T::be_quiet); + + def("cross_validate_trainer", _cross_validate_trainer); + def("cross_validate_trainer_threaded", _cross_validate_trainer_t); + } + + { + typedef svm_c_linear_trainer > T; + setup_trainer("svm_c_trainer_sparse_linear") + .add_property("max_iterations", &T::get_max_iterations, &T::set_max_iterations) + .add_property("force_last_weight_to_1", &T::forces_last_weight_to_1, &T::force_last_weight_to_1) + .add_property("learns_nonnegative_weights", &T::learns_nonnegative_weights, &T::set_learns_nonnegative_weights) + .def("be_verbose", &T::be_verbose) + .def("be_quiet", &T::be_quiet); + + def("cross_validate_trainer", _cross_validate_trainer); + def("cross_validate_trainer_threaded", _cross_validate_trainer_t); + } }