Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Mineiro <paul-github@mineiro.com>2013-12-28 23:55:48 +0400
committerPaul Mineiro <paul-github@mineiro.com>2013-12-28 23:55:48 +0400
commit35ebf66814789250b6cfa2afbbbe8feb58464c20 (patch)
tree9700b27b1ce06bd99c0b19fa6d9b3cf338920f59 /vowpalwabbit/parse_args.cc
parent588c309570a55404dcde24404843b24ddfcab944 (diff)
parente1ae678bdfa35b96bc3f474af6cc36f5e5cddd44 (diff)
merge upstream master
Diffstat (limited to 'vowpalwabbit/parse_args.cc')
-rw-r--r--vowpalwabbit/parse_args.cc113
1 files changed, 70 insertions, 43 deletions
diff --git a/vowpalwabbit/parse_args.cc b/vowpalwabbit/parse_args.cc
index 914119ec..0c1f1dda 100644
--- a/vowpalwabbit/parse_args.cc
+++ b/vowpalwabbit/parse_args.cc
@@ -15,6 +15,7 @@ license as described in the file LICENSE.
#include "network.h"
#include "global_data.h"
#include "nn.h"
+#include "cbify.h"
#include "oaa.h"
#include "bs.h"
#include "topk.h"
@@ -27,6 +28,7 @@ license as described in the file LICENSE.
#include "lda_core.h"
#include "noop.h"
#include "gd_mf.h"
+#include "mf.h"
#include "vw.h"
#include "rand48.h"
#include "parse_args.h"
@@ -75,7 +77,7 @@ void parse_affix_argument(vw&all, string str) {
if (q[1] != 0) {
if (valid_ns(q[1]))
ns = (uint16_t)q[1];
- else {
+ else {
cerr << "malformed affix argument (invalid namespace): " << p << endl;
throw exception();
}
@@ -88,17 +90,17 @@ void parse_affix_argument(vw&all, string str) {
uint16_t afx = (len << 1) | (prefix & 0x1);
all.affix_features[ns] <<= 4;
all.affix_features[ns] |= afx;
-
+
p = strtok(NULL, ",");
}
-
+
delete cstr;
}
vw* parse_args(int argc, char *argv[])
{
po::options_description desc("VW options");
-
+
vw* all = new vw();
size_t random_seed = 0;
@@ -135,18 +137,18 @@ vw* parse_args(int argc, char *argv[])
("quiet", "Don't output diagnostics")
("binary", "report loss as binary classification on -1,1")
("min_prediction", po::value<float>(&(all->sd->min_label)), "Smallest prediction to output")
- ("max_prediction", po::value<float>(&(all->sd->max_label)), "Largest prediction to output")
+ ("max_prediction", po::value<float>(&(all->sd->max_label)), "Largest prediction to output")
;
po::options_description update_opt("Update options");
-
+
update_opt.add_options()
("sgd", "use regular stochastic gradient descent update.")
("hessian_on", "use second derivative in line search")
("bfgs", "use bfgs optimization")
("mem", po::value<int>(&(all->m)), "memory in bfgs")
("termination", po::value<float>(&(all->rel_threshold)),"Termination threshold")
- ("adaptive", "use adaptive, individual learning rates.")
+ ("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")
@@ -194,6 +196,7 @@ vw* parse_args(int argc, char *argv[])
("ignore", po::value< vector<unsigned char> >(), "ignore namespaces beginning with character <arg>")
("keep", po::value< vector<unsigned char> >(), "keep namespaces beginning with character <arg>")
("noconstant", "Don't add a constant feature")
+ ("constant,C", po::value<float>(&(all->initial_constant)), "Set initial value of constant")
("sort_features", "turn this on to disregard order in which features have been defined. This will lead to smaller cache sizes")
("ngram", po::value< vector<string> >(), "Generate N grams")
("skips", po::value< vector<string> >(), "Generate skips in N grams. This in conjunction with the ngram tag can be used to generate generalized n-skip-k-gram.")
@@ -238,7 +241,7 @@ vw* parse_args(int argc, char *argv[])
cluster_opt.add_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")
+ ("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")
;
@@ -251,6 +254,7 @@ vw* parse_args(int argc, char *argv[])
("cb", po::value<size_t>(), "Use contextual bandit learning with <k> costs")
("lda", po::value<size_t>(&(all->lda)), "Run lda with <int> topics")
("nn", po::value<size_t>(), "Use sigmoidal feedforward network with <k> hidden units")
+ ("cbify", po::value<size_t>(), "Convert multiclass on <k> classes into a contextual bandit problem and solve")
("searn", po::value<size_t>(), "use searn, argument=maximum action id or 0 for LDF")
;
@@ -292,7 +296,7 @@ vw* parse_args(int argc, char *argv[])
po::store(parsed, vm);
po::notify(vm);
-
+
if(all->numpasses > 1)
all->holdout_set_off = false;
@@ -303,7 +307,7 @@ vw* parse_args(int argc, char *argv[])
{
all->holdout_set_off = true;
cerr<<"Making holdout_set_off=true since output regularizer specified\n";
- }
+ }
all->data_filename = "";
@@ -387,7 +391,7 @@ vw* parse_args(int argc, char *argv[])
all->feature_mask_idx = 1;
}
else if(all->reg.stride == 2){
- all->reg.stride *= 2;//if either normalized or adaptive, stride->4, mask_idx is still 3
+ all->reg.stride *= 2;//if either normalized or adaptive, stride->4, mask_idx is still 3
}
}
}
@@ -395,7 +399,7 @@ vw* parse_args(int argc, char *argv[])
all->l = GD::setup(*all, vm);
all->scorer = all->l;
- if (vm.count("bfgs") || vm.count("conjugate_gradient"))
+ if (vm.count("bfgs") || vm.count("conjugate_gradient"))
all->l = BFGS::setup(*all, to_pass_further, vm, vm_file);
if (vm.count("version") || argc == 1) {
@@ -423,7 +427,7 @@ vw* parse_args(int argc, char *argv[])
cout << "You can not skip unless ngram is > 1" << endl;
throw exception();
}
-
+
all->skip_strings = vm["skips"].as<vector<string> >();
compile_gram(all->skip_strings, all->skips, (char*)"skips", all->quiet);
}
@@ -438,7 +442,7 @@ vw* parse_args(int argc, char *argv[])
if (spelling_ns[id][0] == '_') all->spelling_features[' '] = true;
else all->spelling_features[(size_t)spelling_ns[id][0]] = true;
}
-
+
if (vm.count("bit_precision"))
{
all->default_bits = false;
@@ -449,7 +453,7 @@ vw* parse_args(int argc, char *argv[])
throw exception();
}
}
-
+
if (vm.count("daemon") || vm.count("pid_file") || (vm.count("port") && !all->active) ) {
all->daemon = true;
@@ -459,7 +463,7 @@ vw* parse_args(int argc, char *argv[])
if (vm.count("compressed"))
set_compressed(all->p);
-
+
if (vm.count("data")) {
all->data_filename = vm["data"].as<string>();
if (ends_with(all->data_filename, ".gz"))
@@ -475,14 +479,14 @@ vw* parse_args(int argc, char *argv[])
{
all->pairs = vm["quadratic"].as< vector<string> >();
vector<string> newpairs;
- //string tmp;
+ //string tmp;
char printable_start = '!';
char printable_end = '~';
int valid_ns_size = printable_end - printable_start - 1; //will skip two characters
if(!all->quiet)
- cerr<<"creating quadratic features for pairs: ";
-
+ cerr<<"creating quadratic features for pairs: ";
+
for (vector<string>::iterator i = all->pairs.begin(); i != all->pairs.end();i++){
if(!all->quiet){
cerr << *i << " ";
@@ -523,7 +527,7 @@ vw* parse_args(int argc, char *argv[])
}
else{
newpairs.push_back(string(*i));
- }
+ }
}
newpairs.swap(all->pairs);
if(!all->quiet)
@@ -649,21 +653,21 @@ vw* parse_args(int argc, char *argv[])
//if (vm.count("nonormalize"))
// all->nonormalize = true;
- if (vm.count("lda"))
+ if (vm.count("lda"))
all->l = LDA::setup(*all, to_pass_further, vm);
- if (!vm.count("lda") && !all->adaptive && !all->normalized_updates)
+ if (!vm.count("lda") && !all->adaptive && !all->normalized_updates)
all->eta *= powf((float)(all->sd->t), all->power_t);
-
+
if (vm.count("readable_model"))
all->text_regressor_name = vm["readable_model"].as<string>();
if (vm.count("invert_hash")){
all->inv_hash_regressor_name = vm["invert_hash"].as<string>();
- all->hash_inv = true;
+ all->hash_inv = true;
}
-
+
if (vm.count("save_per_pass"))
all->save_per_pass = true;
@@ -686,10 +690,10 @@ vw* parse_args(int argc, char *argv[])
if(vm.count("quantile_tau"))
loss_parameter = vm["quantile_tau"].as<float>();
- if (vm.count("noop"))
+ if (vm.count("noop"))
all->l = NOOP::setup(*all);
-
- if (all->rank != 0)
+
+ if (all->rank != 0)
all->l = GDMF::setup(*all);
all->loss = getLossFunction(all, loss_function, (float)loss_parameter);
@@ -802,15 +806,18 @@ vw* parse_args(int argc, char *argv[])
bool got_cs = false;
bool got_cb = false;
- if(vm.count("nn") || vm_file.count("nn") )
+ if(vm.count("nn") || vm_file.count("nn") )
all->l = NN::setup(*all, to_pass_further, vm, vm_file);
- if(vm.count("autolink") || vm_file.count("autolink") )
+ // if (all->rank != 0)
+ // all->l = MF::setup(*all);
+
+ if(vm.count("autolink") || vm_file.count("autolink") )
all->l = ALINK::setup(*all, to_pass_further, vm, vm_file);
- if(vm.count("top") || vm_file.count("top") )
+ if(vm.count("top") || vm_file.count("top") )
all->l = TOPK::setup(*all, to_pass_further, vm, vm_file);
-
+
if (vm.count("binary") || vm_file.count("binary"))
all->l = BINARY::setup(*all, to_pass_further, vm, vm_file);
@@ -823,7 +830,7 @@ vw* parse_args(int argc, char *argv[])
all->l = OAA::setup(*all, to_pass_further, vm, vm_file);
got_mc = true;
}
-
+
if (vm.count("ect") || vm_file.count("ect") ) {
if (got_mc) { cerr << "error: cannot specify multiple MC learners" << endl; throw exception(); }
@@ -833,14 +840,14 @@ vw* parse_args(int argc, char *argv[])
if(vm.count("csoaa") || vm_file.count("csoaa") ) {
if (got_cs) { cerr << "error: cannot specify multiple CS learners" << endl; throw exception(); }
-
+
all->l = CSOAA::setup(*all, to_pass_further, vm, vm_file);
got_cs = true;
}
if(vm.count("wap") || vm_file.count("wap") ) {
if (got_cs) { cerr << "error: cannot specify multiple CS learners" << endl; throw exception(); }
-
+
all->l = WAP::setup(*all, to_pass_further, vm, vm_file);
got_cs = true;
}
@@ -873,12 +880,32 @@ vw* parse_args(int argc, char *argv[])
got_cb = true;
}
+ if (vm.count("cbify") || vm_file.count("cbify"))
+ {
+ if(!got_cs) {
+ if( vm_file.count("cbify") ) vm.insert(pair<string,po::variable_value>(string("csoaa"),vm_file["cbify"]));
+ else vm.insert(pair<string,po::variable_value>(string("csoaa"),vm["cbify"]));
+
+ all->l = CSOAA::setup(*all, to_pass_further, vm, vm_file); // default to CSOAA unless wap is specified
+ got_cs = true;
+ }
+
+ if (!got_cb) {
+ if( vm_file.count("cbify") ) vm.insert(pair<string,po::variable_value>(string("cb"),vm_file["cbify"]));
+ else vm.insert(pair<string,po::variable_value>(string("cb"),vm["cbify"]));
+ all->l = CB::setup(*all, to_pass_further, vm, vm_file);
+ got_cb = true;
+ }
+
+ all->l = CBIFY::setup(*all, to_pass_further, vm, vm_file);
+ }
+
all->searnstr = NULL;
- if (vm.count("searn") || vm_file.count("searn") ) {
+ if (vm.count("searn") || vm_file.count("searn") ) {
if (!got_cs && !got_cb) {
if( vm_file.count("searn") ) vm.insert(pair<string,po::variable_value>(string("csoaa"),vm_file["searn"]));
else vm.insert(pair<string,po::variable_value>(string("csoaa"),vm["searn"]));
-
+
all->l = CSOAA::setup(*all, to_pass_further, vm, vm_file); // default to CSOAA unless others have been specified
got_cs = true;
}
@@ -891,7 +918,7 @@ vw* parse_args(int argc, char *argv[])
throw exception();
}
- if(vm.count("bs") || vm_file.count("bs") )
+ if(vm.count("bs") || vm_file.count("bs") )
all->l = BS::setup(*all, to_pass_further, vm, vm_file);
if (to_pass_further.size() > 0) {
@@ -950,7 +977,7 @@ namespace VW {
}
else {
//flag is present, need to replace old value with new value
-
+
//compute position after flag_to_replace
pos += flag_to_replace.size();
@@ -978,7 +1005,7 @@ namespace VW {
v_array<substring> foo;
foo.end_array = foo.begin = foo.end = NULL;
tokenize(' ', ss, foo);
-
+
char** argv = (char**)calloc(foo.size(), sizeof(char*));
for (size_t i = 0; i < foo.size(); i++)
{
@@ -992,15 +1019,15 @@ namespace VW {
foo.delete_v();
return argv;
}
-
+
vw* initialize(string s)
{
int argc = 0;
s += " --no_stdin";
char** argv = get_argv_from_string(s,argc);
-
+
vw* all = parse_args(argc, argv);
-
+
initialize_examples(*all);
for(int i = 0; i < argc; i++)