david-cortes / contextualbandits

Python implementations of contextual bandits algorithms
http://contextual-bandits.readthedocs.io
BSD 2-Clause "Simplified" License
750 stars 148 forks source link

Allowing two armed bandits? #4

Closed maxpv closed 6 years ago

maxpv commented 6 years ago

Hello,

Thanks for this nice package.

Why two armed bandit aren't allowed?

Changing:

def _check_constructor_input(base_algorithm, nchoices, batch_train=False):
    assert nchoices > 2
    assert isinstance(nchoices, int)
    assert ('fit' in dir(base_algorithm)) and ('predict' in dir(base_algorithm))
    if batch_train:
        assert 'partial_fit' in dir(base_algorithm)
    return None

To:

def _check_constructor_input(base_algorithm, nchoices, batch_train=False):
    assert nchoices >= 2
    assert isinstance(nchoices, int)
    assert ('fit' in dir(base_algorithm)) and ('predict' in dir(base_algorithm))
    if batch_train:
        assert 'partial_fit' in dir(base_algorithm)
    return None

Was enough to make it work.

david-cortes commented 6 years ago

If you have a situation in which there are two arms and each observation will always have one label or the other, it wouldn't make sense to use these metaheuristics. If however you have a situation in which there are two arms but observations can have no label or have more than one label, then there shouldn't be any problem - I hadn't really thought of such scenario so I put that check just to avoid the first one, but you can indeed skip it, and I guess I'll better remove it next time.