diff options
author | John Langford <jl@hunch.net> | 2014-01-29 02:28:32 +0400 |
---|---|---|
committer | John Langford <jl@hunch.net> | 2014-01-29 02:28:32 +0400 |
commit | 2fb8eca0a0d2a8ba5e8438145b5639486cc4c933 (patch) | |
tree | 6ebf73e8d06d551776f5235857eb7b5fe48f3609 /vowpalwabbit/cb.h | |
parent | 1a9eae25b5fc861af1f6714b3ad61822bcf4726f (diff) |
baseline bag and cover approaches working
Diffstat (limited to 'vowpalwabbit/cb.h')
-rw-r--r-- | vowpalwabbit/cb.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/vowpalwabbit/cb.h b/vowpalwabbit/cb.h index 38418b6a..066410b1 100644 --- a/vowpalwabbit/cb.h +++ b/vowpalwabbit/cb.h @@ -49,6 +49,34 @@ namespace CB { copy_label, sizeof(label)}; + template <bool is_learn> + float get_cost_pred(vw& all, cb_class* known_cost, example& ec, uint32_t index, uint32_t base) + { + CB::label* ld = (CB::label*)ec.ld; + + label_data simple_temp; + simple_temp.initial = 0.; + if (known_cost != NULL && index == known_cost->action) + { + simple_temp.label = known_cost->cost; + simple_temp.weight = 1.; + } + else + { + simple_temp.label = FLT_MAX; + simple_temp.weight = 0.; + } + + ec.ld = &simple_temp; + + if (is_learn) + all.scorer->learn(ec, index-1+base); + else + all.scorer->predict(ec, index-1+base); + ec.ld = ld; + + return ec.final_prediction; + } } #endif |