Skip to content

Commit

Permalink
unifying file and commandline options
Browse files Browse the repository at this point in the history
  • Loading branch information
John Langford committed May 2, 2014
1 parent ec0f30f commit 4b431bf
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 161 deletions.
11 changes: 4 additions & 7 deletions vowpalwabbit/autolink.cc
Expand Up @@ -42,18 +42,15 @@ namespace ALINK {
ec.total_sum_feat_sq -= sum_sq;
}

learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm, po::variables_map& vm_file)
learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm)
{
autolink* data = (autolink*)calloc_or_die(1,sizeof(autolink));
data->d = (uint32_t)vm["autolink"].as<size_t>();
data->stride_shift = all.reg.stride_shift;

if (!vm_file.count("autolink"))
{
std::stringstream ss;
ss << " --autolink " << data->d << " ";
all.options_from_file.append(ss.str());
}
std::stringstream ss;
ss << " --autolink " << data->d << " ";
all.options_from_file.append(ss.str());

learner* ret = new learner(data, all.l);
ret->set_learn<autolink, predict_or_learn<true> >();
Expand Down
2 changes: 1 addition & 1 deletion vowpalwabbit/autolink.h
Expand Up @@ -2,6 +2,6 @@
#ifndef AUTOLINK_H
#define AUTOLINK_H
namespace ALINK {
LEARNER::learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm, po::variables_map& vm_file);
LEARNER::learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm);
}
#endif
42 changes: 11 additions & 31 deletions vowpalwabbit/bs.cc
Expand Up @@ -192,7 +192,7 @@ namespace BS {
d.pred_vec.~vector();
}

learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm, po::variables_map& vm_file)
learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm)
{
bs* data = (bs*)calloc_or_die(1, sizeof(bs));
data->ub = FLT_MAX;
Expand All @@ -209,41 +209,21 @@ namespace BS {
po::store(parsed, vm);
po::notify(vm);

po::parsed_options parsed_file = po::command_line_parser(all.options_from_file_argc,all.options_from_file_argv).
style(po::command_line_style::default_style ^ po::command_line_style::allow_guessing).
options(desc).allow_unregistered().run();
po::store(parsed_file, vm_file);
po::notify(vm_file);
data->B = (uint32_t)vm["bs"].as<size_t>();

if( vm_file.count("bs") ) {
data->B = (uint32_t)vm_file["bs"].as<size_t>();
if( vm.count("bs") && (uint32_t)vm["bs"].as<size_t>() != data->B )
std::cerr << "warning: you specified a different number of samples through --bs than the one loaded from predictor. Pursuing with loaded value of: " << data->B << endl;
}
else {
data->B = (uint32_t)vm["bs"].as<size_t>();
//append bs with number of samples to options_from_file so it is saved to regressor later
std::stringstream ss;
ss << " --bs " << data->B;
all.options_from_file.append(ss.str());

//append bs with number of samples to options_from_file so it is saved to regressor later
std::stringstream ss;
ss << " --bs " << data->B;
all.options_from_file.append(ss.str());
}

if (vm.count("bs_type") || vm_file.count("bs_type"))
if (vm.count("bs_type"))
{
std::string type_string;

if(vm_file.count("bs_type")) {
type_string = vm_file["bs_type"].as<std::string>();
if( vm.count("bs_type") && type_string.compare(vm["bs_type"].as<string>()) != 0)
cerr << "You specified a different --bs_type than the one loaded from regressor file. Pursuing with loaded value of: " << type_string << endl;
}
else {
type_string = vm["bs_type"].as<std::string>();

all.options_from_file.append(" --bs_type ");
all.options_from_file.append(type_string);
}
type_string = vm["bs_type"].as<std::string>();

all.options_from_file.append(" --bs_type ");
all.options_from_file.append(type_string);

if (type_string.compare("mean") == 0) {
data->bs_type = BS_TYPE_MEAN;
Expand Down
2 changes: 1 addition & 1 deletion vowpalwabbit/bs.h
Expand Up @@ -13,7 +13,7 @@ license as described in the file LICENSE.

namespace BS
{
LEARNER::learner* setup(vw& all, std::vector<std::string>&, po::variables_map& vm, po::variables_map& vm_file);
LEARNER::learner* setup(vw& all, std::vector<std::string>&, po::variables_map& vm);
void print_result(int f, float res, float weight, v_array<char> tag, float lb, float ub);

void output_example(vw& all, example* ec, float lb, float ub);
Expand Down
39 changes: 14 additions & 25 deletions vowpalwabbit/lrq.cc
Expand Up @@ -178,41 +178,30 @@ namespace LRQ {
}
}

learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm, po::variables_map& vm_file)
learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm)
{//parse and set arguments
LRQstate* lrq = (LRQstate*) calloc (1, sizeof (LRQstate));
unsigned int maxk = 0;
lrq->all = &all;

size_t random_seed = 0;
if (vm.count("random_seed")) random_seed = vm["random_seed"].as<size_t> ();
if (vm_file.count("random_seed")) random_seed = vm_file["random_seed"].as<size_t> ();

lrq->initial_seed = lrq->seed = random_seed | 8675309;
lrq->dropout = vm.count("lrqdropout") || vm_file.count("lrqdropout");

if (lrq->dropout && !vm_file.count("lrqdropout"))
all.options_from_file.append(" --lrqdropout");

if (!vm_file.count("lrq"))
{
lrq->lrpairs = vm["lrq"].as<vector<string> > ();

// TODO: doesn't work for non-printable stuff

stringstream ss;
for (vector<string>::iterator i = lrq->lrpairs.begin ();
i != lrq->lrpairs.end ();
++i)
{
ss << " --lrq " << *i;
}

all.options_from_file.append(ss.str());
}
else
lrq->lrpairs = vm_file["lrq"].as<vector<string> > ();
lrq->dropout = vm.count("lrqdropout");

all.options_from_file.append(" --lrqdropout");

lrq->lrpairs = vm["lrq"].as<vector<string> > ();

stringstream ss;
for (vector<string>::iterator i = lrq->lrpairs.begin ();
i != lrq->lrpairs.end ();
++i)
ss << " --lrq " << *i;

all.options_from_file.append(ss.str());

if (! all.quiet)
{
cerr << "creating low rank quadratic features for pairs: ";
Expand Down
2 changes: 1 addition & 1 deletion vowpalwabbit/lrq.h
Expand Up @@ -2,6 +2,6 @@
#ifndef LRQ_HEADER
#define LRQ_HEADER
namespace LRQ {
LEARNER::learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm, po::variables_map& vm_file);
LEARNER::learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm);
}
#endif
41 changes: 10 additions & 31 deletions vowpalwabbit/nn.cc
Expand Up @@ -304,7 +304,7 @@ namespace NN {
free (n.output_layer.atomics[nn_output_namespace].begin);
}

learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm, po::variables_map& vm_file)
learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm)
{
nn* n = (nn*)calloc_or_die(1,sizeof(nn));
n->all = &all;
Expand All @@ -322,41 +322,23 @@ namespace NN {
po::store(parsed, vm);
po::notify(vm);

po::parsed_options parsed_file = po::command_line_parser(all.options_from_file_argc,all.options_from_file_argv).
style(po::command_line_style::default_style ^ po::command_line_style::allow_guessing).
options(desc).allow_unregistered().run();
po::store(parsed_file, vm_file);
po::notify(vm_file);

//first parse for number of hidden units
n->k = 0;
if( vm_file.count("nn") ) {
n->k = (uint32_t)vm_file["nn"].as<size_t>();
if( vm.count("nn") && (uint32_t)vm["nn"].as<size_t>() != n->k )
std::cerr << "warning: you specified a different number of hidden units through --nn than the one loaded from predictor. Pursuing with loaded value of: " << n->k << endl;
}
else {
n->k = (uint32_t)vm["nn"].as<size_t>();

std::stringstream ss;
ss << " --nn " << n->k;
all.options_from_file.append(ss.str());
}

if( vm_file.count("dropout") ) {
n->dropout = all.training || vm.count("dropout");
n->k = (uint32_t)vm["nn"].as<size_t>();

std::stringstream ss;
ss << " --nn " << n->k;
all.options_from_file.append(ss.str());

if (! n->dropout && ! vm.count("meanfield") && ! all.quiet)
std::cerr << "using mean field for testing, specify --dropout explicitly to override" << std::endl;
}
else if ( vm.count("dropout") ) {
if ( vm.count("dropout") ) {
n->dropout = true;

std::stringstream ss;
ss << " --dropout ";
all.options_from_file.append(ss.str());
}

if ( vm.count("meanfield") ) {
n->dropout = false;
if (! all.quiet)
Expand All @@ -371,10 +353,7 @@ namespace NN {
<< (all.training ? "training" : "testing")
<< std::endl;

if( vm_file.count("inpass") ) {
n->inpass = true;
}
else if (vm.count ("inpass")) {
if (vm.count ("inpass")) {
n->inpass = true;

std::stringstream ss;
Expand Down
2 changes: 1 addition & 1 deletion vowpalwabbit/nn.h
Expand Up @@ -11,7 +11,7 @@ license as described in the file LICENSE.

namespace NN
{
LEARNER::learner* setup(vw& all, std::vector<std::string>&, po::variables_map& vm, po::variables_map& vm_file);
LEARNER::learner* setup(vw& all, std::vector<std::string>&opts, po::variables_map& vm);
}

#endif

0 comments on commit 4b431bf

Please sign in to comment.