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:
authorJohn Langford <jl@hunch.net>2014-12-31 17:59:28 +0300
committerJohn Langford <jl@hunch.net>2014-12-31 17:59:28 +0300
commitca852d8cfeef77ca60aa426c9070f1568ecf644e (patch)
tree10eafd40fa54aede5aa9e22b4649982b8b0117b4
parent5669a17da5d03265ef700b495eec6477e016340d (diff)
bugfixes in cb and search
-rw-r--r--vowpalwabbit/cb_algs.cc65
-rw-r--r--vowpalwabbit/search.cc2
2 files changed, 2 insertions, 65 deletions
diff --git a/vowpalwabbit/cb_algs.cc b/vowpalwabbit/cb_algs.cc
index c7fc2021..bf9a6e5b 100644
--- a/vowpalwabbit/cb_algs.cc
+++ b/vowpalwabbit/cb_algs.cc
@@ -30,9 +30,6 @@ namespace CB_ALGS
float last_pred_reg;
float last_correct_cost;
- float min_cost;
- float max_cost;
-
cb_class* known_cost;
vw* all;
};
@@ -245,70 +242,12 @@ namespace CB_ALGS
gen_cs_label<is_learn>(all, c, ec, cs_ld, cl->action);
}
- void cb_test_to_cs_test_label(vw& all, example& ec, COST_SENSITIVE::label& cs_ld)
- {
- CB::label ld = ec.l.cb;
-
- cs_ld.costs.erase();
- if(ld.costs.size() > 0)
- {
- //if this is a test example and we specified actions, this means we are only allowed to perform these actions, so copy all actions with their specified costs
- for( cb_class* cl = ld.costs.begin; cl != ld.costs.end; cl++)
- {
- COST_SENSITIVE::wclass wc;
- wc.wap_value = 0.;
-
- wc.x = cl->cost;
- wc.class_index = cl->action;
- wc.partial_prediction = 0.;
- wc.wap_value = 0.;
-
- cs_ld.costs.push_back(wc);
- }
- }
- else
- {
- for (uint32_t i = 0; i < all.sd->k; i++)
- {
- COST_SENSITIVE::wclass wc;
- wc.wap_value = 0.;
-
- wc.x = FLT_MAX;
- wc.class_index = i+1;
- wc.partial_prediction = 0.;
- wc.wap_value = 0.;
-
- cs_ld.costs.push_back(wc);
- }
- }
- }
-
template <bool is_learn>
void predict_or_learn(cb& c, base_learner& base, example& ec) {
vw* all = c.all;
CB::label ld = ec.l.cb;
- //check if this is a test example where we just want a prediction
- if( !is_learn )
- {
- //if so just query base cost-sensitive learner
- cb_test_to_cs_test_label(*all,ec,c.cb_cs_ld);
-
- ec.l.cs = c.cb_cs_ld;
- base.predict(ec);
- for (size_t i=0; i<ld.costs.size(); i++)
- ld.costs[i].partial_prediction = c.cb_cs_ld.costs[i].partial_prediction;
-
- ec.l.cb = ld;
-
- return;
- }
-
- //now this is a training example
- c.known_cost = get_observed_cost(ld);
- c.min_cost = min (c.min_cost, c.known_cost->cost);
- c.max_cost = max (c.max_cost, c.known_cost->cost);
-
+ c.known_cost = get_observed_cost(ld);
//generate a cost-sensitive example to update classifiers
switch(c.cb_type)
{
@@ -501,8 +440,6 @@ namespace CB_ALGS
{
cb& c = calloc_or_die<cb>();
c.all = &all;
- c.min_cost = 0.;
- c.max_cost = 1.;
uint32_t nb_actions = (uint32_t)vm["cb"].as<size_t>();
//append cb with nb_actions to file_options so it is saved to regressor later
diff --git a/vowpalwabbit/search.cc b/vowpalwabbit/search.cc
index 762ef1e9..fb14e65c 100644
--- a/vowpalwabbit/search.cc
+++ b/vowpalwabbit/search.cc
@@ -855,7 +855,7 @@ namespace Search {
size_t sz = sizeof(size_t) + sizeof(ptag) + sizeof(int) + sizeof(size_t) + sizeof(size_t) + condition_on_cnt * (sizeof(ptag) + sizeof(action) + sizeof(char));
if (sz % 4 != 0) sz = 4 * (sz / 4 + 1); // make sure sz aligns to 4 so that uniform_hash does the right thing
- unsigned char* item = &calloc_or_die<unsigned char>();
+ unsigned char* item = calloc_or_die<unsigned char>(sz);
unsigned char* here = item;
*here = (unsigned char)sz; here += sizeof(size_t);
*here = mytag; here += sizeof(ptag);