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

Added interface and module for ccb #37

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added estimators/ccb/__init__.py
Empty file.
51 changes: 51 additions & 0 deletions estimators/ccb/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
""" Interface for implementation of conditional contextual bandits estimators """

from abc import ABC, abstractmethod
from typing import List

class Estimator(ABC):
""" Interface for implementation of conditional contextual bandits estimators """

@abstractmethod
def add_example(self, p_log: List, r: List, p_pred: List, count: float) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to rename count since it's a float?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should do it, but probably not in this PR: all other estimators still have it as count, so it is probably better to be consistent at this point.

"""
Args:
p_log: List of probability of the logging policy
r: List of reward for choosing an action in the given context
p_pred: List of predicted probability of making decision
count: weight
"""
...

@abstractmethod
def get(self) -> float:
""" Calculates the selected estimator

Returns:
The estimator value
"""
...

class Interval(ABC):
""" Interface for implementation of conditional contextual bandits estimators interval """

@abstractmethod
def add_example(self, p_log: List, r: List, p_pred: List, count: float) -> None:
"""
Args:
p_log: List of probability of the logging policy
r: List of reward for choosing an action in the given context
p_pred: List of predicted probability of making decision
count: weight
"""
...

@abstractmethod
def get(self, alpha: float) -> List:
""" Calculates the CI
Args:
alpha: alpha value
Returns:
Returns the confidence interval as list[float]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will return [min_bound, max_bound] only for the first slot? description is a bit general here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine to be generic here since this is an interface.

"""
...
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering"
],
packages=["estimators", "estimators.bandits", "estimators.slates", "estimators.utils"],
packages=["estimators", "estimators.bandits", "estimators.ccb", "estimators.slates", "estimators.utils"],
install_requires= ['scipy>=0.9'],
tests_require=['pytest'],
python_requires=">=3.6",
Expand Down