diff options
author | John Langford <jl@hunch.net> | 2015-01-02 22:44:31 +0300 |
---|---|---|
committer | John Langford <jl@hunch.net> | 2015-01-02 22:44:31 +0300 |
commit | 6688da8c2179afcfe520f18149449b812bb1fabc (patch) | |
tree | 4987a55e39d818d2971ee5c7d8c97be6bae7ee1b | |
parent | ffa9e4f8c1d5a46cadc89a082c5860375d433162 (diff) |
required and optional options
29 files changed, 173 insertions, 254 deletions
diff --git a/vowpalwabbit/active.cc b/vowpalwabbit/active.cc index 774b4696..54094331 100644 --- a/vowpalwabbit/active.cc +++ b/vowpalwabbit/active.cc @@ -153,14 +153,13 @@ namespace ACTIVE { base_learner* setup(vw& all) {//parse and set arguments - po::options_description opts("Active Learning options"); - opts.add_options() - ("active", "enable active learning") + new_options(all, "Active Learning options") + ("active", "enable active learning"); + if (missing_required(all)) return NULL; + new_options(all) ("simulation", "active learning simulation mode") ("mellowness", po::value<float>(), "active learning mellowness parameter c_0. Default 8"); - add_options(all, opts); - if(!all.vm.count("active")) - return NULL; + add_options(all); active& data = calloc_or_die<active>(); data.active_c0 = 8; diff --git a/vowpalwabbit/autolink.cc b/vowpalwabbit/autolink.cc index d78662c0..707b38a6 100644 --- a/vowpalwabbit/autolink.cc +++ b/vowpalwabbit/autolink.cc @@ -39,12 +39,9 @@ namespace ALINK { LEARNER::base_learner* setup(vw& all) { - po::options_description opts("Autolink options"); - opts.add_options() + new_options(all,"Autolink options") ("autolink", po::value<size_t>(), "create link function with polynomial d"); - add_options(all,opts); - if(!all.vm.count("autolink")) - return NULL; + if(missing_required(all)) return NULL; autolink& data = calloc_or_die<autolink>(); data.d = (uint32_t)all.vm["autolink"].as<size_t>(); diff --git a/vowpalwabbit/bfgs.cc b/vowpalwabbit/bfgs.cc index 47be2d70..a14d085c 100644 --- a/vowpalwabbit/bfgs.cc +++ b/vowpalwabbit/bfgs.cc @@ -970,18 +970,17 @@ void save_load(bfgs& b, io_buf& model_file, bool read, bool text) base_learner* setup(vw& all) { - po::options_description opts("LBFGS options"); - opts.add_options() + new_options(all, "LBFGS options") ("bfgs", "use bfgs optimization") - ("conjugate_gradient", "use conjugate gradient based optimization") + ("conjugate_gradient", "use conjugate gradient based optimization"); + if (missing_required(all)) return NULL; + new_options(all) ("hessian_on", "use second derivative in line search") ("mem", po::value<uint32_t>()->default_value(15), "memory in bfgs") ("termination", po::value<float>()->default_value(0.001f),"Termination threshold"); - add_options(all, opts); + add_options(all); + po::variables_map& vm = all.vm; - if(!vm.count("bfgs") && !vm.count("conjugate_gradient")) - return NULL; - bfgs& b = calloc_or_die<bfgs>(); b.all = &all; b.m = vm["mem"].as<uint32_t>(); diff --git a/vowpalwabbit/binary.cc b/vowpalwabbit/binary.cc index 2f0765db..d9afc63b 100644 --- a/vowpalwabbit/binary.cc +++ b/vowpalwabbit/binary.cc @@ -30,12 +30,9 @@ namespace BINARY { LEARNER::base_learner* setup(vw& all) {//parse and set arguments - po::options_description opts("Binary options"); - opts.add_options() + new_options(all,"Binary options") ("binary", "report loss as binary classification on -1,1"); - add_options(all,opts); - if(!all.vm.count("binary")) - return NULL; + if(missing_required(all)) return NULL; //Create new learner LEARNER::learner<char>& ret = diff --git a/vowpalwabbit/bs.cc b/vowpalwabbit/bs.cc index 1b35d972..f66403dd 100644 --- a/vowpalwabbit/bs.cc +++ b/vowpalwabbit/bs.cc @@ -241,15 +241,11 @@ namespace BS { base_learner* setup(vw& all) { - po::options_description opts("Bootstrap options"); - opts.add_options() - ("bootstrap,B", po::value<size_t>(), "bootstrap mode with k rounds by online importance resampling") - ("bs_type", po::value<string>(), "prediction type {mean,vote}"); - - add_options(all, opts); - if (!all.vm.count("bootstrap")) - return NULL; - + new_options(all, "Bootstrap options") + ("bootstrap,B", po::value<size_t>(), "bootstrap mode with k rounds by online importance resampling"); + if (missing_required(all)) return NULL; + new_options(all)("bs_type", po::value<string>(), "prediction type {mean,vote}"); + add_options(all); bs& data = calloc_or_die<bs>(); data.ub = FLT_MAX; diff --git a/vowpalwabbit/cb_algs.cc b/vowpalwabbit/cb_algs.cc index cf377a55..b14328d3 100644 --- a/vowpalwabbit/cb_algs.cc +++ b/vowpalwabbit/cb_algs.cc @@ -438,35 +438,33 @@ namespace CB_ALGS base_learner* setup(vw& all) { - po::options_description opts("CB options"); - opts.add_options() - ("cb", po::value<size_t>(), "Use contextual bandit learning with <k> costs") + new_options(all, "CB options") + ("cb", po::value<size_t>(), "Use contextual bandit learning with <k> costs"); + if (missing_required(all)) return NULL; + new_options(all) ("cb_type", po::value<string>(), "contextual bandit method to use in {ips,dm,dr}") ("eval", "Evaluate a policy rather than optimizing."); - add_options(all, opts); - po::variables_map& vm = all.vm; - if (!vm.count("cb")) - return NULL; + add_options(all); cb& c = calloc_or_die<cb>(); c.all = &all; - uint32_t nb_actions = (uint32_t)vm["cb"].as<size_t>(); + uint32_t nb_actions = (uint32_t)all.vm["cb"].as<size_t>(); *all.file_options << " --cb " << nb_actions; all.sd->k = nb_actions; bool eval = false; - if (vm.count("eval")) + if (all.vm.count("eval")) eval = true; size_t problem_multiplier = 2;//default for DR - if (vm.count("cb_type")) + if (all.vm.count("cb_type")) { std::string type_string; - type_string = vm["cb_type"].as<std::string>(); + type_string = all.vm["cb_type"].as<std::string>(); *all.file_options << " --cb_type " << type_string; if (type_string.compare("dr") == 0) @@ -501,7 +499,7 @@ namespace CB_ALGS { all.args.push_back("--csoaa"); stringstream ss; - ss << vm["cb"].as<size_t>(); + ss << all.vm["cb"].as<size_t>(); all.args.push_back(ss.str()); } diff --git a/vowpalwabbit/cbify.cc b/vowpalwabbit/cbify.cc index 02e7f748..d72011a2 100644 --- a/vowpalwabbit/cbify.cc +++ b/vowpalwabbit/cbify.cc @@ -373,20 +373,18 @@ namespace CBIFY { base_learner* setup(vw& all) {//parse and set arguments - po::options_description opts("CBIFY options"); - opts.add_options() - ("cbify", po::value<size_t>(), "Convert multiclass on <k> classes into a contextual bandit problem and solve") + new_options(all, "CBIFY options") + ("cbify", po::value<size_t>(), "Convert multiclass on <k> classes into a contextual bandit problem and solve"); + if (missing_required(all)) return NULL; + new_options(all) ("first", po::value<size_t>(), "tau-first exploration") ("epsilon",po::value<float>() ,"epsilon-greedy exploration") ("bag",po::value<size_t>() ,"bagging-based exploration") ("cover",po::value<size_t>() ,"bagging-based exploration"); - add_options(all, opts); - po::variables_map& vm = all.vm; - if (!vm.count("cbify")) - return NULL; + add_options(all); + po::variables_map& vm = all.vm; cbify& data = calloc_or_die<cbify>(); - data.all = &all; data.k = (uint32_t)vm["cbify"].as<size_t>(); *all.file_options << " --cbify " << data.k; diff --git a/vowpalwabbit/csoaa.cc b/vowpalwabbit/csoaa.cc index 1f2a1ce4..908369b7 100644 --- a/vowpalwabbit/csoaa.cc +++ b/vowpalwabbit/csoaa.cc @@ -68,12 +68,10 @@ namespace CSOAA { base_learner* setup(vw& all) { - po::options_description opts("CSOAA options"); - opts.add_options() + new_options(all, "CSOAA options") ("csoaa", po::value<size_t>(), "Use one-against-all multiclass learning with <k> costs"); - add_options(all, opts); - if(!all.vm.count("csoaa")) - return NULL; + if(missing_required(all)) return NULL; + csoaa& c = calloc_or_die<csoaa>(); c.all = &all; //first parse for number of actions @@ -651,16 +649,15 @@ namespace LabelDict { base_learner* setup(vw& all) { - po::options_description opts("LDF Options"); - opts.add_options() + new_options(all, "LDF Options") ("csoaa_ldf", po::value<string>(), "Use one-against-all multiclass learning with label dependent features. Specify singleline or multiline.") - ("wap_ldf", po::value<string>(), "Use weighted all-pairs multiclass learning with label dependent features. Specify singleline or multiline.") + ("wap_ldf", po::value<string>(), "Use weighted all-pairs multiclass learning with label dependent features. Specify singleline or multiline."); + if (missing_required(all)) return NULL; + new_options(all) ("ldf_override", po::value<string>(), "Override singleline or multiline from csoaa_ldf or wap_ldf, eg if stored in file"); - add_options(all, opts); + add_options(all); + po::variables_map& vm = all.vm; - if(!vm.count("csoaa_ldf") && !vm.count("wap_ldf")) - return NULL; - ldf& ld = calloc_or_die<ldf>(); ld.all = &all; diff --git a/vowpalwabbit/ect.cc b/vowpalwabbit/ect.cc index 7bff8892..dde893d2 100644 --- a/vowpalwabbit/ect.cc +++ b/vowpalwabbit/ect.cc @@ -364,13 +364,11 @@ namespace ECT base_learner* setup(vw& all) { - po::options_description opts("ECT options"); - opts.add_options() - ("ect", po::value<size_t>(), "Use error correcting tournament with <k> labels") - ("error", po::value<size_t>()->default_value(0), "error in ECT"); - add_options(all, opts); - if (!all.vm.count("ect")) - return NULL; + new_options(all, "ECT options") + ("ect", po::value<size_t>(), "Use error correcting tournament with <k> labels"); + if (missing_required(all)) return NULL; + new_options(all)("error", po::value<size_t>()->default_value(0), "error in ECT"); + add_options(all); ect& data = calloc_or_die<ect>(); data.k = (int)all.vm["ect"].as<size_t>(); diff --git a/vowpalwabbit/ftrl_proximal.cc b/vowpalwabbit/ftrl_proximal.cc index f1b8918e..f912267d 100644 --- a/vowpalwabbit/ftrl_proximal.cc +++ b/vowpalwabbit/ftrl_proximal.cc @@ -179,16 +179,14 @@ namespace FTRL { base_learner* setup(vw& all) { - po::options_description opts("FTRL options"); - opts.add_options() - ("ftrl", "Follow the Regularized Leader") + new_options(all, "FTRL options") + ("ftrl", "Follow the Regularized Leader"); + if (missing_required(all)) return NULL; + new_options(all) ("ftrl_alpha", po::value<float>()->default_value(0.0), "Learning rate for FTRL-proximal optimization") ("ftrl_beta", po::value<float>()->default_value(0.1), "FTRL beta") ("progressive_validation", po::value<string>()->default_value("ftrl.evl"), "File to record progressive validation for ftrl-proximal"); - add_options(all, opts); - - if (!all.vm.count("ftrl")) - return NULL; + add_options(all); ftrl& b = calloc_or_die<ftrl>(); b.all = &all; diff --git a/vowpalwabbit/gd.cc b/vowpalwabbit/gd.cc index b09333e9..8460bab8 100644 --- a/vowpalwabbit/gd.cc +++ b/vowpalwabbit/gd.cc @@ -846,14 +846,13 @@ uint32_t ceil_log_2(uint32_t v) base_learner* setup(vw& all) { - po::options_description opts("Gradient Descent options"); - opts.add_options() + new_options(all, "Gradient Descent options") ("sgd", "use regular stochastic gradient descent update.") ("adaptive", "use adaptive, individual learning rates.") ("invariant", "use safe/importance aware updates.") ("normalized", "use per feature normalized updates") ("exact_adaptive_norm", "use current default invariant normalized adaptive update rule"); - add_options(all, opts); + add_options(all); po::variables_map& vm = all.vm; gd& g = calloc_or_die<gd>(); g.all = &all; diff --git a/vowpalwabbit/gd_mf.cc b/vowpalwabbit/gd_mf.cc index 8cf5ff41..8c51b0ce 100644 --- a/vowpalwabbit/gd_mf.cc +++ b/vowpalwabbit/gd_mf.cc @@ -295,17 +295,13 @@ void sd_offset_update(weight* weights, size_t mask, feature* begin, feature* end base_learner* setup(vw& all) { - po::options_description opts("Gdmf options"); - opts.add_options() + new_options(all, "Gdmf options") ("rank", po::value<uint32_t>(), "rank for matrix factorization."); - add_options(all, opts); - po::variables_map& vm=all.vm; - if(!vm.count("rank")) - return NULL; + if(missing_required(all)) return NULL; gdmf& data = calloc_or_die<gdmf>(); data.all = &all; - data.rank = vm["rank"].as<uint32_t>(); + data.rank = all.vm["rank"].as<uint32_t>(); *all.file_options << " --rank " << data.rank; // store linear + 2*rank weights per index, round up to power of two @@ -313,32 +309,32 @@ void sd_offset_update(weight* weights, size_t mask, feature* begin, feature* end all.reg.stride_shift = (size_t) temp; all.random_weights = true; - if ( vm.count("adaptive") ) + if ( all.vm.count("adaptive") ) { cerr << "adaptive is not implemented for matrix factorization" << endl; throw exception(); } - if ( vm.count("normalized") ) + if ( all.vm.count("normalized") ) { cerr << "normalized is not implemented for matrix factorization" << endl; throw exception(); } - if ( vm.count("exact_adaptive_norm") ) + if ( all.vm.count("exact_adaptive_norm") ) { cerr << "normalized adaptive updates is not implemented for matrix factorization" << endl; throw exception(); } - if (vm.count("bfgs") || vm.count("conjugate_gradient")) + if (all.vm.count("bfgs") || all.vm.count("conjugate_gradient")) { cerr << "bfgs is not implemented for matrix factorization" << endl; throw exception(); } - if(!vm.count("learning_rate") && !vm.count("l")) + if(!all.vm.count("learning_rate") && !all.vm.count("l")) all.eta = 10; //default learning rate to 10 for non default update rule //default initial_t to 1 instead of 0 - if(!vm.count("initial_t")) { + if(!all.vm.count("initial_t")) { all.sd->t = 1.f; all.sd->weighted_unlabeled_examples = 1.f; all.initial_t = 1.f; diff --git a/vowpalwabbit/global_data.cc b/vowpalwabbit/global_data.cc index 4b8472ff..cd288b52 100644 --- a/vowpalwabbit/global_data.cc +++ b/vowpalwabbit/global_data.cc @@ -225,29 +225,31 @@ void add_options(vw& all, po::options_description& opts) po::store(parsed, new_vm); po::notify(new_vm); - //parse all opts for a complete variable map. - parsed = po::command_line_parser(all.args). - style(po::command_line_style::default_style ^ po::command_line_style::allow_guessing). - options(all.opts).allow_unregistered().run(); - po::store(parsed, new_vm); - all.vm = new_vm; + for (po::variables_map::iterator it=new_vm.begin(); it!=new_vm.end(); ++it) + all.vm.insert(*it); } -bool missing_required(vw& all, po::variables_map& vm) +void add_options(vw& all) +{ + add_options(all, *all.new_opts); + delete all.new_opts; +} + +bool missing_required(vw& all) { - all.opts.add(*all.new_opts);//record required. - po::variables_map new_vm; //parse local opts once for notifications. po::parsed_options parsed = po::command_line_parser(all.args). style(po::command_line_style::default_style ^ po::command_line_style::allow_guessing). options(*all.new_opts).allow_unregistered().run(); + po::variables_map new_vm; po::store(parsed, new_vm); - + all.opts.add(*all.new_opts); + delete all.new_opts; + for (po::variables_map::iterator it=new_vm.begin(); it!=new_vm.end(); ++it) + all.vm.insert(*it); + if (new_vm.size() == 0) // required are missing; - { - delete all.new_opts; - return true; - } + return true; else return false; } diff --git a/vowpalwabbit/global_data.h b/vowpalwabbit/global_data.h index c3bb6b7f..7e6ec74b 100644 --- a/vowpalwabbit/global_data.h +++ b/vowpalwabbit/global_data.h @@ -314,8 +314,10 @@ void compile_gram(vector<string> grams, uint32_t* dest, char* descriptor, bool q void compile_limits(vector<string> limits, uint32_t* dest, bool quiet); int print_tag(std::stringstream& ss, v_array<char> tag); void add_options(vw& all, po::options_description& opts); -inline po::options_description_easy_init new_options(vw& all, const char* name) +inline po::options_description_easy_init new_options(vw& all, std::string name = "\0") { all.new_opts = new po::options_description(name); return all.new_opts->add_options(); } +bool missing_required(vw& all); +void add_options(vw& all); diff --git a/vowpalwabbit/kernel_svm.cc b/vowpalwabbit/kernel_svm.cc index 34ebf23f..5c955f18 100644 --- a/vowpalwabbit/kernel_svm.cc +++ b/vowpalwabbit/kernel_svm.cc @@ -791,9 +791,10 @@ namespace KSVM } LEARNER::base_learner* setup(vw &all) { - po::options_description opts("KSVM options"); - opts.add_options() - ("ksvm", "kernel svm") + new_options(all, "KSVM options") + ("ksvm", "kernel svm"); + if (missing_required(all)) return NULL; + new_options(all) ("reprocess", po::value<size_t>(), "number of reprocess steps for LASVM") // ("active", "do active learning") //("active_c", po::value<double>(), "parameter for query prob") @@ -805,11 +806,9 @@ namespace KSVM ("bandwidth", po::value<float>(), "bandwidth of rbf kernel") ("degree", po::value<int>(), "degree of poly kernel") ("lambda", po::value<double>(), "saving regularization for test time"); + add_options(all); - add_options(all, opts); po::variables_map& vm = all.vm; - if (!vm.count("ksvm")) - return NULL; string loss_function = "hinge"; float loss_parameter = 0.0; delete all.loss; diff --git a/vowpalwabbit/lda_core.cc b/vowpalwabbit/lda_core.cc index ba7cbbc7..3f9932e0 100644 --- a/vowpalwabbit/lda_core.cc +++ b/vowpalwabbit/lda_core.cc @@ -756,15 +756,14 @@ void end_examples(lda& l) base_learner* setup(vw&all)
{
- po::options_description opts("Lda options");
- opts.add_options()
+ new_options(all, "Lda options") ("lda", po::value<uint32_t>(), "Run lda with <int> topics")
("lda_alpha", po::value<float>()->default_value(0.1f), "Prior on sparsity of per-document topic weights")
("lda_rho", po::value<float>()->default_value(0.1f), "Prior on sparsity of topic distributions")
("lda_D", po::value<float>()->default_value(10000.), "Number of documents")
("lda_epsilon", po::value<float>()->default_value(0.001f), "Loop convergence threshold")
("minibatch", po::value<size_t>()->default_value(1), "Minibatch size, for LDA");
- add_options(all, opts);
+ add_options(all);
po::variables_map& vm= all.vm; if(!vm.count("lda"))
return NULL;
diff --git a/vowpalwabbit/log_multi.cc b/vowpalwabbit/log_multi.cc index a13f751e..65390ccc 100644 --- a/vowpalwabbit/log_multi.cc +++ b/vowpalwabbit/log_multi.cc @@ -500,15 +500,15 @@ namespace LOG_MULTI base_learner* setup(vw& all) //learner setup
{
- po::options_description opts("Log Multi options");
- opts.add_options()
- ("log_multi", po::value<size_t>(), "Use online tree for multiclass")
+ new_options(all, "Log Multi options") + ("log_multi", po::value<size_t>(), "Use online tree for multiclass"); + if (missing_required(all)) return NULL; + new_options(all) ("no_progress", "disable progressive validation")
- ("swap_resistance", po::value<uint32_t>(), "higher = more resistance to swap, default=4");
- add_options(all, opts);
+ ("swap_resistance", po::value<uint32_t>(), "higher = more resistance to swap, default=4"); + add_options(all);
+ po::variables_map& vm = all.vm; - if(!vm.count("log_multi"))
- return NULL;
log_multi& data = calloc_or_die<log_multi>(); data.k = (uint32_t)vm["log_multi"].as<size_t>();
diff --git a/vowpalwabbit/lrq.cc b/vowpalwabbit/lrq.cc index 8b72f7dc..8bdd8551 100644 --- a/vowpalwabbit/lrq.cc +++ b/vowpalwabbit/lrq.cc @@ -189,13 +189,14 @@ namespace LRQ { base_learner* setup(vw& all) {//parse and set arguments - po::options_description opts("Lrq options"); - opts.add_options() - ("lrq", po::value<vector<string> > (), "use low rank quadratic features") + new_options(all, "Lrq options") + ("lrq", po::value<vector<string> > (), "use low rank quadratic features"); + if (missing_required(all)) return NULL; + new_options(all) ("lrqdropout", "use dropout training for low rank quadratic features"); - add_options(all, opts); - po::variables_map& vm = all.vm; - if(!vm.count("lrq")) + add_options(all); + + if(!all.vm.count("lrq")) return NULL; LRQstate& lrq = calloc_or_die<LRQstate>(); @@ -203,17 +204,17 @@ namespace LRQ { lrq.all = &all; size_t random_seed = 0; - if (vm.count("random_seed")) random_seed = vm["random_seed"].as<size_t> (); + if (all.vm.count("random_seed")) random_seed = all.vm["random_seed"].as<size_t> (); lrq.initial_seed = lrq.seed = random_seed | 8675309; - if (vm.count("lrqdropout")) + if (all.vm.count("lrqdropout")) lrq.dropout = true; else lrq.dropout = false; *all.file_options << " --lrqdropout "; - lrq.lrpairs = vm["lrq"].as<vector<string> > (); + lrq.lrpairs = all.vm["lrq"].as<vector<string> > (); for (vector<string>::iterator i = lrq.lrpairs.begin (); i != lrq.lrpairs.end (); diff --git a/vowpalwabbit/mf.cc b/vowpalwabbit/mf.cc index 52e5e53d..c2e7575a 100644 --- a/vowpalwabbit/mf.cc +++ b/vowpalwabbit/mf.cc @@ -189,16 +189,11 @@ void finish(mf& o) { } base_learner* setup(vw& all) { - po::options_description opts("MF options"); - opts.add_options() + new_options(all, "MF options") ("new_mf", po::value<size_t>(), "rank for reduction-based matrix factorization"); - add_options(all, opts); - if(!all.vm.count("new_mf")) - return NULL; + if(missing_required(all)) return NULL; mf& data = calloc_or_die<mf>(); - - // copy global data locally data.all = &all; data.rank = (uint32_t)all.vm["new_mf"].as<size_t>(); diff --git a/vowpalwabbit/nn.cc b/vowpalwabbit/nn.cc index c5107fa9..e9697b1b 100644 --- a/vowpalwabbit/nn.cc +++ b/vowpalwabbit/nn.cc @@ -310,17 +310,16 @@ CONVERSE: // That's right, I'm using goto. So sue me. base_learner* setup(vw& all) { - po::options_description opts("NN options"); - opts.add_options() - ("nn", po::value<size_t>(), "Use sigmoidal feedforward network with <k> hidden units") + new_options(all, "NN options") + ("nn", po::value<size_t>(), "Use sigmoidal feedforward network with <k> hidden units"); + if(missing_required(all)) return NULL; + new_options(all) ("inpass", "Train or test sigmoidal feedforward network with input passthrough.") ("dropout", "Train or test sigmoidal feedforward network using dropout.") ("meanfield", "Train or test sigmoidal feedforward network using mean field."); - add_options(all, opts); + add_options(all); + po::variables_map& vm = all.vm; - if(!vm.count("nn")) - return NULL; - nn& n = calloc_or_die<nn>(); n.all = &all; //first parse for number of hidden units diff --git a/vowpalwabbit/noop.cc b/vowpalwabbit/noop.cc index e6d659d2..892480ff 100644 --- a/vowpalwabbit/noop.cc +++ b/vowpalwabbit/noop.cc @@ -12,12 +12,8 @@ namespace NOOP { LEARNER::base_learner* setup(vw& all) { - po::options_description opts("Noop options"); - opts.add_options() - ("noop","do no learning"); - add_options(all, opts); - if(!all.vm.count("noop")) - return NULL; + new_options(all, "Noop options") ("noop","do no learning"); + if(missing_required(all)) return NULL; return &LEARNER::init_learner<char>(NULL, learn, 1); } } diff --git a/vowpalwabbit/oaa.cc b/vowpalwabbit/oaa.cc index f29cbcb4..6063ed47 100644 --- a/vowpalwabbit/oaa.cc +++ b/vowpalwabbit/oaa.cc @@ -62,8 +62,7 @@ namespace OAA { void finish_example(vw& all, oaa&, example& ec) { MULTICLASS::finish_example(all, ec); } - /* -{ + /*{ new_options(all, "One-against-all options") ("oaa", po::value<size_t>(), "Use one-against-all multiclass learning with <k> labels"); if (missing_required(all,vm)) return NULL; @@ -74,12 +73,9 @@ namespace OAA { LEARNER::base_learner* setup(vw& all) { - po::options_description opts("One-against-all options"); - opts.add_options() + new_options(all, "One-against-all options") ("oaa", po::value<size_t>(), "Use one-against-all multiclass learning with <k> labels"); - add_options(all, opts); - if(!all.vm.count("oaa")) - return NULL; + if(missing_required(all)) return NULL; oaa& data = calloc_or_die<oaa>(); data.k = all.vm["oaa"].as<size_t>(); diff --git a/vowpalwabbit/parse_args.cc b/vowpalwabbit/parse_args.cc index bc55cccb..69bb794c 100644 --- a/vowpalwabbit/parse_args.cc +++ b/vowpalwabbit/parse_args.cc @@ -180,16 +180,13 @@ void parse_affix_argument(vw&all, string str) { void parse_diagnostics(vw& all, int argc) { - po::options_description diag_opt("Diagnostic options"); - - diag_opt.add_options() + new_options(all, "Diagnostic options") ("version","Version information") ("audit,a", "print weights of features") ("progress,P", po::value< string >(), "Progress update frequency. int: additive, float: multiplicative") ("quiet", "Don't output disgnostics and progress updates") ("help,h","Look here: http://hunch.net/~vw/ and click on Tutorial."); - - add_options(all, diag_opt); + add_options(all); po::variables_map& vm = all.vm; @@ -250,9 +247,7 @@ void parse_diagnostics(vw& all, int argc) void parse_source(vw& all) { - po::options_description in_opt("Input options"); - - in_opt.add_options() + new_options(all, "Input options") ("data,d", po::value< string >(), "Example Set") ("daemon", "persistent daemon mode on port 26542") ("port", po::value<size_t>(),"port to listen on; use 0 to pick unused port") @@ -264,8 +259,7 @@ void parse_source(vw& all) ("kill_cache,k", "do not reuse existing cache: create a new one always") ("compressed", "use gzip format whenever possible. If a cache file is being created, this option creates a compressed cache file. A mixture of raw-text & compressed inputs are supported with autodetection.") ("no_stdin", "do not default to reading from stdin"); - - add_options(all, in_opt); + add_options(all); // Be friendly: if -d was left out, treat positional param as data file po::positional_options_description p; @@ -320,8 +314,7 @@ void parse_source(vw& all) void parse_feature_tweaks(vw& all) { - po::options_description feature_opt("Feature options"); - feature_opt.add_options() + new_options(all, "Feature options") ("hash", po::value< string > (), "how to hash the features. Available options: strings, all") ("ignore", po::value< vector<unsigned char> >(), "ignore namespaces beginning with character <arg>") ("keep", po::value< vector<unsigned char> >(), "keep namespaces beginning with character <arg>") @@ -338,8 +331,8 @@ void parse_feature_tweaks(vw& all) ("q:", po::value< string >(), ": corresponds to a wildcard for all printable characters") ("cubic", po::value< vector<string> > (), "Create and use cubic features"); + add_options(all); - add_options(all, feature_opt); po::variables_map& vm = all.vm; //feature manipulation @@ -551,9 +544,7 @@ void parse_feature_tweaks(vw& all) void parse_example_tweaks(vw& all) { - po::options_description opts("Example options"); - - opts.add_options() + new_options(all, "Example options") ("testonly,t", "Ignore label information and just test") ("holdout_off", "no holdout data in multiple passes") ("holdout_period", po::value<uint32_t>(&(all.holdout_period)), "holdout period for test only, default 10") @@ -569,10 +560,9 @@ void parse_example_tweaks(vw& all) ("quantile_tau", po::value<float>()->default_value(0.5), "Parameter \\tau associated with Quantile loss. Defaults to 0.5") ("l1", po::value<float>(&(all.l1_lambda)), "l_1 lambda") ("l2", po::value<float>(&(all.l2_lambda)), "l_2 lambda"); + add_options(all); - add_options(all, opts); po::variables_map& vm = all.vm; - if (vm.count("testonly") || all.eta == 0.) { if (!all.quiet) @@ -628,16 +618,12 @@ void parse_example_tweaks(vw& all) void parse_output_preds(vw& all) { - po::options_description out_opt("Output options"); - - out_opt.add_options() + new_options(all, "Output options") ("predictions,p", po::value< string >(), "File to output predictions to") - ("raw_predictions,r", po::value< string >(), "File to output unnormalized predictions to") - ; + ("raw_predictions,r", po::value< string >(), "File to output unnormalized predictions to"); + add_options(all); - add_options(all, out_opt); po::variables_map& vm = all.vm; - if (vm.count("predictions")) { if (!all.quiet) cerr << "predictions = " << vm["predictions"].as< string >() << endl; @@ -684,20 +670,17 @@ void parse_output_preds(vw& all) void parse_output_model(vw& all) { - po::options_description output_model("Output model"); - - output_model.add_options() + new_options(all, "Output model") ("final_regressor,f", po::value< string >(), "Final regressor") ("readable_model", po::value< string >(), "Output human-readable final regressor with numeric features") ("invert_hash", po::value< string >(), "Output human-readable final regressor with feature names. Computationally expensive.") ("save_resume", "save extra state so learning can be resumed later with new data") ("save_per_pass", "Save the model after every pass over data") ("output_feature_regularizer_binary", po::value< string >(&(all.per_feature_regularizer_output)), "Per feature regularization output file") - ("output_feature_regularizer_text", po::value< string >(&(all.per_feature_regularizer_text)), "Per feature regularization output file, in text"); - - add_options(all, output_model); - po::variables_map& vm = all.vm; + ("output_feature_regularizer_text", po::value< string >(&(all.per_feature_regularizer_text)), "Per feature regularization output file, in text"); + add_options(all); + po::variables_map& vm = all.vm; if (vm.count("final_regressor")) { all.final_regressor_name = vm["final_regressor"].as<string>(); if (!all.quiet) @@ -806,49 +789,36 @@ vw* parse_args(int argc, char *argv[]) size_t random_seed = 0; all->program_name = argv[0]; - po::options_description desc("VW options"); - - desc.add_options() + new_options(*all, "VW options") ("random_seed", po::value<size_t>(&random_seed), "seed random number generator") ("ring_size", po::value<size_t>(&(all->p->ring_size)), "size of example ring"); + add_options(*all); - po::options_description update_opt("Update options"); - - update_opt.add_options() + new_options(*all, "Update options") ("learning_rate,l", po::value<float>(&(all->eta)), "Set learning rate") ("power_t", po::value<float>(&(all->power_t)), "t power value") ("decay_learning_rate", po::value<float>(&(all->eta_decay_rate)), "Set Decay factor for learning_rate between passes") ("initial_t", po::value<double>(&((all->sd->t))), "initial t value") - ("feature_mask", po::value< string >(), "Use existing regressor to determine which parameters may be updated. If no initial_regressor given, also used for initial weights.") - ; + ("feature_mask", po::value< string >(), "Use existing regressor to determine which parameters may be updated. If no initial_regressor given, also used for initial weights."); + add_options(*all); - po::options_description weight_opt("Weight options"); - - weight_opt.add_options() + new_options(*all, "Weight options") ("initial_regressor,i", po::value< vector<string> >(), "Initial regressor(s)") ("initial_weight", po::value<float>(&(all->initial_weight)), "Set all weights to an initial value of 1.") ("random_weights", po::value<bool>(&(all->random_weights)), "make initial weights random") - ("input_feature_regularizer", po::value< string >(&(all->per_feature_regularizer_input)), "Per feature regularization input file") - ; + ("input_feature_regularizer", po::value< string >(&(all->per_feature_regularizer_input)), "Per feature regularization input file"); + add_options(*all); - po::options_description cluster_opt("Parallelization options"); - cluster_opt.add_options() + new_options(*all, "Parallelization options") ("span_server", po::value<string>(&(all->span_server)), "Location of server for setting up spanning tree") ("unique_id", po::value<size_t>(&(all->unique_id)),"unique id used for cluster parallel jobs") ("total", po::value<size_t>(&(all->total)),"total number of nodes used in cluster parallel job") - ("node", po::value<size_t>(&(all->node)),"node number in cluster parallel job") - ; - - desc.add(update_opt) - .add(weight_opt) - .add(cluster_opt); + ("node", po::value<size_t>(&(all->node)),"node number in cluster parallel job"); + add_options(*all); - add_options(*all, desc); po::variables_map& vm = all->vm; - msrand48(random_seed); - parse_diagnostics(*all, argc); all->sd->weighted_unlabeled_examples = all->sd->t; diff --git a/vowpalwabbit/print.cc b/vowpalwabbit/print.cc index dd8cac99..321a8710 100644 --- a/vowpalwabbit/print.cc +++ b/vowpalwabbit/print.cc @@ -43,12 +43,8 @@ namespace PRINT LEARNER::base_learner* setup(vw& all) { - po::options_description opts("Print options"); - opts.add_options() - ("print","print examples"); - add_options(all, opts); - if(!all.vm.count("print")) - return NULL; + new_options(all, "Print options") ("print","print examples"); + if(missing_required(all)) return NULL; print& p = calloc_or_die<print>(); p.all = &all; diff --git a/vowpalwabbit/scorer.cc b/vowpalwabbit/scorer.cc index fa9ea417..826f8e3b 100644 --- a/vowpalwabbit/scorer.cc +++ b/vowpalwabbit/scorer.cc @@ -33,10 +33,9 @@ namespace Scorer { LEARNER::base_learner* setup(vw& all) { - po::options_description opts("Link options"); - opts.add_options() + new_options(all, "Link options") ("link", po::value<string>()->default_value("identity"), "Specify the link function: identity, logistic or glf1"); - add_options(all, opts); + add_options(all); po::variables_map& vm = all.vm; scorer& s = calloc_or_die<scorer>(); s.all = &all; diff --git a/vowpalwabbit/search.cc b/vowpalwabbit/search.cc index 1275cdfa..74444206 100644 --- a/vowpalwabbit/search.cc +++ b/vowpalwabbit/search.cc @@ -1669,13 +1669,12 @@ namespace Search { } void handle_condition_options(vw& vw, auto_condition_settings& acset) { - po::options_description condition_options("Search Auto-conditioning Options"); - condition_options.add_options() - ("search_max_bias_ngram_length", po::value<size_t>(), "add a \"bias\" feature for each ngram up to and including this length. eg., if it's 1 (default), then you get a single feature for each conditional") - ("search_max_quad_ngram_length", po::value<size_t>(), "add bias *times* input features for each ngram up to and including this length (def: 0)") - ("search_condition_feature_value", po::value<float> (), "how much weight should the conditional features get? (def: 1.)"); + new_options(vw, "Search Auto-conditioning Options") + ("search_max_bias_ngram_length", po::value<size_t>(), "add a \"bias\" feature for each ngram up to and including this length. eg., if it's 1 (default), then you get a single feature for each conditional") + ("search_max_quad_ngram_length", po::value<size_t>(), "add bias *times* input features for each ngram up to and including this length (def: 0)") + ("search_condition_feature_value", po::value<float> (), "how much weight should the conditional features get? (def: 1.)"); + add_options(vw); - add_options(vw, condition_options); po::variables_map& vm = vw.vm; check_option<size_t>(acset.max_bias_ngram_length, vw, vm, "search_max_bias_ngram_length", false, size_equal, @@ -1765,9 +1764,10 @@ namespace Search { } base_learner* setup(vw&all) { - po::options_description opts("Search Options"); - opts.add_options() - ("search", po::value<size_t>(), "use search-based structured prediction, argument=maximum action id or 0 for LDF") + new_options(all,"Search Options") + ("search", po::value<size_t>(), "use search-based structured prediction, argument=maximum action id or 0 for LDF"); + if (missing_required(all)) return NULL; + new_options(all) ("search_task", po::value<string>(), "the search task (use \"--search_task list\" to get a list of available tasks)") ("search_interpolation", po::value<string>(), "at what level should interpolation happen? [*data|policy]") ("search_rollout", po::value<string>(), "how should rollouts be executed? [policy|oracle|*mix_per_state|mix_per_roll|none]") @@ -1792,7 +1792,7 @@ namespace Search { ("search_beam", po::value<size_t>(), "use beam search (arg = beam size, default 0 = no beam)") ("search_kbest", po::value<size_t>(), "size of k-best list to produce (must be <= beam size)") ; - add_options(all, opts); + add_options(all); po::variables_map& vm = all.vm; if (!vm.count("search")) return NULL; diff --git a/vowpalwabbit/sender.cc b/vowpalwabbit/sender.cc index 0fe64fa0..ae73cee9 100644 --- a/vowpalwabbit/sender.cc +++ b/vowpalwabbit/sender.cc @@ -98,12 +98,9 @@ void end_examples(sender& s) LEARNER::base_learner* setup(vw& all) { - po::options_description opts("Sender options"); - opts.add_options() + new_options(all, "Sender options") ("sendto", po::value< vector<string> >(), "send examples to <host>"); - add_options(all, opts); - if(!all.vm.count("sendto")) - return NULL; + if(missing_required(all)) return NULL; sender& s = calloc_or_die<sender>(); s.sd = -1; diff --git a/vowpalwabbit/stagewise_poly.cc b/vowpalwabbit/stagewise_poly.cc index e5a46b24..68065e0c 100644 --- a/vowpalwabbit/stagewise_poly.cc +++ b/vowpalwabbit/stagewise_poly.cc @@ -658,9 +658,11 @@ namespace StagewisePoly base_learner *setup(vw &all) { - po::options_description opts("Stagewise poly options"); - opts.add_options() - ("stage_poly", "use stagewise polynomial feature learning") + new_options(all, "Stagewise poly options") + ("stage_poly", "use stagewise polynomial feature learning"); + if (missing_required(all)) return NULL; + + new_options(all) ("sched_exponent", po::value<float>(), "exponent controlling quantity of included features") ("batch_sz", po::value<uint32_t>(), "multiplier on batch size before including more features") ("batch_sz_no_doubling", "batch_sz does not double") @@ -668,12 +670,9 @@ namespace StagewisePoly ("magic_argument", po::value<float>(), "magical feature flag") #endif //MAGIC_ARGUMENT ; - add_options(all, opts); - po::variables_map &vm = all.vm; - - if (!vm.count("stage_poly")) - return NULL; + add_options(all); + po::variables_map &vm = all.vm; stagewise_poly& poly = calloc_or_die<stagewise_poly>(); poly.all = &all; depthsbits_create(poly); diff --git a/vowpalwabbit/topk.cc b/vowpalwabbit/topk.cc index 118b1d74..d3414bcd 100644 --- a/vowpalwabbit/topk.cc +++ b/vowpalwabbit/topk.cc @@ -102,12 +102,9 @@ namespace TOPK { LEARNER::base_learner* setup(vw& all) { - po::options_description opts("TOP K options"); - opts.add_options() + new_options(all, "TOP K options") ("top", po::value<size_t>(), "top k recommendation"); - add_options(all,opts); - if(!all.vm.count("top")) - return NULL; + if(missing_required(all)) return NULL; topk& data = calloc_or_die<topk>(); data.B = (uint32_t)all.vm["top"].as<size_t>(); |