Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional Contextual Bandit #1816

Merged
merged 72 commits into from Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
087eb9a
Add CCB label parsing, label and prediction types (#1754)
jackgerrits Feb 11, 2019
9655add
Merge remote-tracking branch 'upstream/master' into conditional_conte…
jackgerrits Feb 21, 2019
499f663
[CCB] Enable interactions to be overridden by an example (#1770)
jackgerrits Mar 12, 2019
ab5d418
[CCB] Add ccb_explore_adf reduction (#1761)
yannstad Mar 12, 2019
7d5b8ff
Fix ordering to be consistent with existing cb reduction (#1786)
jackgerrits Mar 14, 2019
b9fd188
[CCB] Dsjson and json parsing for CCB (#1767)
jackgerrits Mar 18, 2019
1f382e0
Merge branch 'master' into conditional_contextual_bandit
jackgerrits Mar 19, 2019
de4603b
Merge branch 'master' into conditional_contextual_bandit
jackgerrits Mar 25, 2019
7b79c13
Sample from PDF and swap chosen as part of CCB (#1797)
jackgerrits Mar 26, 2019
efb851b
Extend CCB parser for Dsjson/Json to support implicitly converting CB…
jackgerrits Mar 27, 2019
3fbc5de
Implement finish example and output for CCB (#1795)
jackgerrits Mar 27, 2019
0133821
Shared example decision feature injection and auto crossing (#1796)
jackgerrits Mar 27, 2019
fef3881
Fix learning and stashed pred (#1836)
jackgerrits Apr 11, 2019
b5d7e96
Merge branch 'master' into conditional_contextual_bandit
jackgerrits Apr 11, 2019
444f6e3
trigger ci
jackgerrits Apr 11, 2019
8f350b8
trigger ci
jackgerrits Apr 11, 2019
28a9540
Merge branch 'master' into conditional_contextual_bandit
JohnLangford Apr 15, 2019
06d567e
Merge branch 'master' into conditional_contextual_bandit
jackgerrits May 2, 2019
d3754f0
"remove cb_sample_seed, only can override with tag"
jackgerrits May 3, 2019
c2a4b85
- comment out explicit slot actions
jackgerrits May 3, 2019
1dc9adf
fix spelling error
jackgerrits May 3, 2019
061d065
Use variable names instead of types for sizeof
jackgerrits May 6, 2019
40f76fe
stop using read_object helper
jackgerrits May 6, 2019
294fb51
Rename get_unbiased_cost to get_cost_estimate
jackgerrits May 6, 2019
3f11c0c
Fix test number in runtests
jackgerrits May 7, 2019
3d41ca3
C# test needs an extra empty line to recognize the data file as multi…
jackgerrits May 7, 2019
5218387
Merge branch 'master' into conditional_contextual_bandit
jackgerrits May 7, 2019
05b9a16
change seed handling to match explore
jackgerrits May 8, 2019
e3bd96d
move to asserts
jackgerrits May 8, 2019
eaf556f
remove unused variable
jackgerrits May 8, 2019
36c6cb4
Update overridable interactions implementation (#1866)
jackgerrits May 10, 2019
087c1f3
Implement history rollup and higher order interactions for CCB (#1869)
jackgerrits May 10, 2019
5f7ac49
Fix naming based on spec discussion (#1879)
jackgerrits May 16, 2019
64f44f1
Resolve leaking of label and prediction in CCB (#1882)
jackgerrits May 20, 2019
7bac50a
CCB Learning fixes (#1890)
jackgerrits May 29, 2019
d3dc719
Merge branch 'master' into conditional_contextual_bandit
JohnLangford Jun 3, 2019
1bbcf62
Fix merge conflicts and test number bad merge
jackgerrits Jun 7, 2019
edcd6dc
Fix parser constructors in test
jackgerrits Jun 7, 2019
33e88b7
remove history related changes
jackgerrits Jun 14, 2019
9672ad2
split ccb into two files, remove history
jackgerrits Jun 16, 2019
9b9d539
Automatic quadratic features
jackgerrits Jun 17, 2019
1afd992
Add ccb test
jackgerrits Jun 17, 2019
79f6603
Fix runtests, includes and move to warning
jackgerrits Jun 17, 2019
cba7806
fix runtests file
jackgerrits Jun 17, 2019
be3313e
Fix warning
jackgerrits Jun 17, 2019
af05fb5
Add new line so windows tests work
jackgerrits Jun 18, 2019
2e97eef
move cb_sample beneath shared_merger
jackgerrits Jun 18, 2019
a66a5f1
use seed for sample for consistent behavior
jackgerrits Jun 19, 2019
8c7f4a2
Make sure interactions are set in locations where examples are alloc…
jackgerrits Jun 20, 2019
bec5590
Reuse memory in ccb rather than alloc/dealloc (#1938)
jackgerrits Jun 21, 2019
d833563
Inject slot id and revise automatic interactions to slot id with all …
jackgerrits Jun 21, 2019
1d2a670
Fix namespace duplication and ignore bugs
jackgerrits Jun 25, 2019
52cd75b
Fix interaction object for ccb parser (#1947)
jackgerrits Jun 25, 2019
519fe82
Address comments
jackgerrits Jun 25, 2019
fa00e96
Merge branch 'conditional_contextual_bandit' of https://github.com/Vo…
jackgerrits Jun 25, 2019
350cbec
Fix scope of clear
jackgerrits Jun 25, 2019
d2f34e1
Fix scope of clear
jackgerrits Jun 25, 2019
9e2bd2e
Update tests
jackgerrits Jun 25, 2019
79b9bf1
Address PR comments
jackgerrits Jun 26, 2019
8f08d6f
Merge branch 'master' into conditional_contextual_bandit
yannstad Jun 26, 2019
0200449
Remove json parser
jackgerrits Jun 26, 2019
a9f1852
Merge branch 'conditional_contextual_bandit' of https://github.com/Vo…
jackgerrits Jun 26, 2019
d05eee5
Fix usage of json_parser
jackgerrits Jun 27, 2019
bc3a81a
Merge branch 'master' into conditional_contextual_bandit
jackgerrits Jun 27, 2019
1dc9b24
Fix bad merge of tests
jackgerrits Jun 27, 2019
15ee2c0
revert file change
jackgerrits Jun 27, 2019
9bd8b6f
Remove if conditional
jackgerrits Jun 27, 2019
adabcd0
rename dfstate to slotsstate
jackgerrits Jun 27, 2019
f4d9929
Improve error handling, and improve perf of interactions generation
jackgerrits Jun 27, 2019
ca8d599
Fix brackets
jackgerrits Jun 27, 2019
207ebb5
Merge branch 'master' into conditional_contextual_bandit
jackgerrits Jul 1, 2019
c0741ad
Merge branch 'master' into conditional_contextual_bandit
jackgerrits Jul 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 17 additions & 17 deletions cs/cli/vw_cbutil.cpp
@@ -1,17 +1,17 @@
/*
Copyright (c) by respective owners including Yahoo!, Microsoft, and
individual contributors. All rights reserved. Released under a BSD (revised)
license as described in the file LICENSE.
*/

#include "vw_cbutil.h"
#include "cb_algs.h"

namespace VW
{
float VowpalWabbitContextualBanditUtil::GetUnbiasedCost(uint32_t actionObservered, uint32_t actionTaken, float cost, float probability)
{ CB::cb_class observation = { cost, actionObservered, probability };

return CB_ALGS::get_unbiased_cost(&observation, actionTaken);
}
}
/*
Copyright (c) by respective owners including Yahoo!, Microsoft, and
individual contributors. All rights reserved. Released under a BSD (revised)
license as described in the file LICENSE.
*/
#include "vw_cbutil.h"
#include "cb_algs.h"
namespace VW
{
float VowpalWabbitContextualBanditUtil::GetUnbiasedCost(uint32_t actionObservered, uint32_t actionTaken, float cost, float probability)
{ CB::cb_class observation = { cost, actionObservered, probability };
return CB_ALGS::get_cost_estimate(&observation, actionTaken);
}
}
10 changes: 5 additions & 5 deletions cs/unittest/TestJson.cs

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions explore/explore_internal.h
Expand Up @@ -229,6 +229,8 @@ namespace exploration
return enforce_minimum_probability(minimum_uniform, update_zero_elements, pdf_first, pdf_last, pdf_category());
}

// Warning: `seed` must be sufficiently random for the PRNG to produce uniform random values. Using sequential seeds will result in a very biased distribution.
// If unsure how to update seed between calls, merand48 (in rand48.h) can be used to inplace mutate it.
template<typename It>
int sample_after_normalizing(uint64_t seed, It pdf_first, It pdf_last, uint32_t& chosen_index, std::input_iterator_tag /* pdf_category */)
{
Expand Down Expand Up @@ -277,20 +279,26 @@ namespace exploration
return S_EXPLORATION_OK;
}

// Warning: `seed` must be sufficiently random for the PRNG to produce uniform random values. Using sequential seeds will result in a very biased distribution.
// If unsure how to update seed between calls, merand48 (in rand48.h) can be used to inplace mutate it.
template<typename It>
int sample_after_normalizing(uint64_t seed, It pdf_first, It pdf_last, uint32_t& chosen_index)
{
typedef typename std::iterator_traits<It>::iterator_category pdf_category;
return sample_after_normalizing(seed, pdf_first, pdf_last, chosen_index, pdf_category());
}

// Warning: `seed` must be sufficiently random for the PRNG to produce uniform random values. Using sequential seeds will result in a very biased distribution.
// If unsure how to update seed between calls, merand48 (in rand48.h) can be used to inplace mutate it.
template<typename It>
int sample_after_normalizing(const char* seed, It pdf_first, It pdf_last, uint32_t& chosen_index, std::random_access_iterator_tag pdf_category)
{
uint64_t seed_hash = uniform_hash(seed, strlen(seed), 0);
return sample_after_normalizing(seed_hash, pdf_first, pdf_last, chosen_index, pdf_category);
}

// Warning: `seed` must be sufficiently random for the PRNG to produce uniform random values. Using sequential seeds will result in a very biased distribution.
// If unsure how to update seed between calls, merand48 (in rand48.h) can be used to inplace mutate it.
template<typename It>
int sample_after_normalizing(const char* seed, It pdf_first, It pdf_last, uint32_t& chosen_index)
{
Expand Down
3 changes: 2 additions & 1 deletion java/src/main/c++/jni_spark_vw.cc
Expand Up @@ -194,6 +194,7 @@ JNIEXPORT jlong JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_initiali
try
{
example* ex = VW::alloc_examples(0, 1);
ex->interactions = &all->interactions;

if (isEmpty)
{
Expand Down Expand Up @@ -419,4 +420,4 @@ JNIEXPORT jobject JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_predic
{
rethrow_cpp_exception_as_java_exception(env);
}
}
}
1 change: 1 addition & 0 deletions python/pylibvw.cc
Expand Up @@ -148,6 +148,7 @@ example* my_empty_example0(vw_ptr vw, size_t labelType)
{ label_parser* lp = get_label_parser(&*vw, labelType);
example* ec = VW::alloc_examples(lp->label_size, 1);
lp->default_label(&ec->l);
ec->interactions = &vw->interactions;
if (labelType == lCOST_SENSITIVE)
{ COST_SENSITIVE::wclass zero = { 0., 1, 0., 0. };
ec->l.cs.costs.push_back(zero);
Expand Down
15 changes: 8 additions & 7 deletions test/RunTests
Expand Up @@ -1731,12 +1731,13 @@ printf '3 |f a b c |e x y z\n2 |f a y c |e x\n' | {VW} --oaa 3 -q ef --audit
{VW} -d train-sets/malformed.dat --onethread
train-sets/ref/malformed.stderr

# Test 196: online contextual memory tree
{VW} -d train-sets/rcv1_smaller.dat --memory_tree 10 --learn_at_leaf --max_number_of_labels 2 --dream_at_update 0 --dream_repeats 3 --online --leaf_example_multiplier 10 --alpha 0.1 -l 0.001 -b 15 --passes 1 --loss_function squared --holdout_off
train-sets/ref/cmt_rcv1_smaller_online.stderr

# Test 197: offline contextual memory tree
{VW} -d train-sets/rcv1_smaller.dat --memory_tree 10 --learn_at_leaf --max_number_of_labels 2 --dream_at_update 0 --dream_repeats 3 --leaf_example_multiplier 10 --alpha 0.1 -l 0.001 -b 15 -c --passes 2 --loss_function squared --holdout_off
train-sets/ref/cmt_rcv1_smaller_offline.stderr
# Test 196: test cb_sample
{VW} --cb_sample --cb_explore_adf -d test-sets/cb_sample_seed.data -p cb_sample_seed.predict --random_seed 1234
pred-sets/ref/cb_sample_seed.predict

# Test 197: CCB train then test
{VW} -d train-sets/ccb_test.dat --ccb_explore_adf -p ccb_test.predict
train-sets/ref/ccb_test.stderr
train-sets/ref/ccb_test.predict

# Do not delete this line or the empty line above it
4 changes: 4 additions & 0 deletions test/pred-sets/ref/cb_sample_seed.predict
@@ -0,0 +1,4 @@
1:0.5,0:0.5

0:0.5,1:0.5

7 changes: 7 additions & 0 deletions test/test-sets/cb_sample_seed.data
@@ -0,0 +1,7 @@
shared seed=1234| s_1 s_2
| a:1 b:1 c:1
| a:0.5 b:2 c:1

shared seed=1234| s_1 s_2
0:1.0:0.5 | a:1 b:1 c:1
| a:0.5 b:2 c:1
240 changes: 240 additions & 0 deletions test/train-sets/ccb_test.dat
@@ -0,0 +1,240 @@
ccb shared |User b
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 0:0:0.2 |Slot h
ccb slot 1:0:0.25 |Slot i
ccb slot 2:0:0.333333 |Slot j

ccb shared |User b
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 3:0:0.2 |Slot h
ccb slot 4:0:0.25 |Slot i
ccb slot 0:0:0.333333 |Slot j

ccb shared |User c
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 4:0:0.2 |Slot h
ccb slot 3:0:0.25 |Slot i
ccb slot 2:0:0.333333 |Slot j

ccb shared |User a
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 1:0:0.2 |Slot h
ccb slot 4:-1:0.25 |Slot i
ccb slot 2:0:0.333333 |Slot j

ccb shared |User a
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 4:0:0.84 |Slot h
ccb slot 3:0:0.316667 |Slot i
ccb slot 1:-1:0.466667 |Slot j

ccb shared |User b
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 1:0:0.04 |Slot h
ccb slot 4:-1:0.85 |Slot i
ccb slot 0:0:0.866667 |Slot j

ccb shared |User c
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 4:-1:0.84 |Slot h
ccb slot 1:0:0.85 |Slot i
ccb slot 2:0:0.0666667 |Slot j

ccb shared |User c
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 4:-1:0.84 |Slot h
ccb slot 1:0:0.85 |Slot i
ccb slot 0:0:0.866667 |Slot j

ccb shared |User a
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 4:0:0.84 |Slot h
ccb slot 1:0:0.85 |Slot i
ccb slot 2:0:0.0666667 |Slot j

ccb shared |User c
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 4:0:0.84 |Slot h
ccb slot 1:0:0.85 |Slot i
ccb slot 0:0:0.0666667 |Slot j

ccb shared |User b
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 4:0:0.84 |Slot h
ccb slot 1:0:0.85 |Slot i
ccb slot 3:0:0.866667 |Slot j

ccb shared |User b
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 4:0:0.84 |Slot h
ccb slot 1:0:0.85 |Slot i
ccb slot 2:0:0.0666667 |Slot j

ccb shared |User a
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 4:0:0.84 |Slot h
ccb slot 1:0:0.85 |Slot i
ccb slot 3:0:0.866667 |Slot j

ccb shared |User a
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 4:0:0.84 |Slot h
ccb slot 2:-1:0.05 |Slot i
ccb slot 1:0:0.866667 |Slot j

ccb shared |User b
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot 2:0:0.84 |Slot h
ccb slot 4:0:0.85 |Slot i
ccb slot 1:0:0.866667 |Slot j

ccb shared |User a
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot |Slot h
ccb slot |Slot i
ccb slot |Slot j

ccb shared |User b
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot |Slot h
ccb slot |Slot i
ccb slot |Slot j

ccb shared |User c
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot |Slot h
ccb slot |Slot i
ccb slot |Slot j

ccb shared |User b
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot |Slot h
ccb slot |Slot i
ccb slot |Slot j

ccb shared |User a
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot |Slot h
ccb slot |Slot i
ccb slot |Slot j

ccb shared |User c
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot |Slot h
ccb slot |Slot i
ccb slot |Slot j

ccb shared |User b
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot |Slot h
ccb slot |Slot i
ccb slot |Slot j

ccb shared |User b
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot |Slot h
ccb slot |Slot i
ccb slot |Slot j

ccb shared |User a
ccb action |Action d
ccb action |Action e
ccb action |Action f
ccb action |Action ff
ccb action |Action fff
ccb slot |Slot h
ccb slot |Slot i
ccb slot |Slot j