Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/continuous_delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
${{ runner.os }}-poetry-${{ matrix.python-version }}-${{ matrix.pydantic-version }}-
- name: Install project dependencies with Poetry
run: |
poetry install
poetry install --all-extras
- name: Restore pyproject.toml
run: |
mv pyproject.toml.bak pyproject.toml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/continuous_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
export PATH="$HOME/.poetry/bin:$PATH"
- name: Install project dependencies with Poetry
run: |
poetry install
poetry install --all-extras
- name: Install Pandoc
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Install project dependencies with Poetry
run: |
poetry add pydantic@${{ matrix.pydantic-version }}
poetry install
poetry install --all-extras
- name: Style check
run: |
# run pre-commit hooks
Expand Down
1 change: 1 addition & 0 deletions docs/src/authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Dario d'Andrea, <dariod@playtika.com>
- Shahar Bar, <shaharbar1@gmail.com>
- Jerome Carayol, <jeromec@playtika.com>
- Anastasiia Kabeshova, <anastasiia.kabeshova@gmail.com>
- Stefano Piazza, <stefanop@playtika.com>
- Ron Shiff, <ron.shiff1@gmail.com>
- Raphael Steinmann, <raphaels@playtika.com>
Expand Down
6 changes: 3 additions & 3 deletions pybandits/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _numpy_gelu(x: np.ndarray) -> np.ndarray:
return 0.5 * x * (1 + erf(x / np.sqrt(2.0)))


def _stable_sigmoid(x):
def _numpy_sigmoid(x):
"""Stable sigmoid activation function for NumPy."""
return np.where(x >= 0, 1 / (1 + np.exp(-x)), np.exp(x) / (1 + np.exp(x)))

Expand Down Expand Up @@ -850,7 +850,7 @@ class BaseBayesianNeuralNetwork(Model, ABC):
_numpy_activations: ClassVar[dict] = {
"tanh": np.tanh,
"relu": _numpy_relu,
"sigmoid": _stable_sigmoid,
"sigmoid": _numpy_sigmoid,
"gelu": _numpy_gelu,
}

Expand Down Expand Up @@ -1208,7 +1208,7 @@ def sample_proba(self, context: np.ndarray) -> List[ProbabilityWeight]:
else:
# Output layer - apply sigmoid
weighted_sum = linear_transform.squeeze(-1)
prob = _stable_sigmoid(weighted_sum)
prob = _numpy_sigmoid(weighted_sum)

return list(zip(prob, weighted_sum))

Expand Down
13 changes: 10 additions & 3 deletions pybandits/offline_policy_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,18 @@ def _check_array(
raise ValueError(f"{name} must be a {ndim}D array.")
if array.shape[0] != n_samples:
raise ValueError(f"action and {name} must have the same length.")
if array.dtype != dtype:
# Check dtype compatibility: use issubdtype for numpy dtypes
if dtype is float:
if not np.issubdtype(array.dtype, np.floating):
raise ValueError(f"{name} must be a {dtype} array")
elif dtype is int:
if not np.issubdtype(array.dtype, np.integer):
raise ValueError(f"{name} must be a {dtype} array")
elif array.dtype is not dtype:
raise ValueError(f"{name} must be a {dtype} array")
if ndim > 1:
if array.shape[1] != n_actions:
raise ValueError(f"{name} must have the same number of actions as the action array.")
if array.shape[1] < n_actions:
raise ValueError(f"{name} must have at least number of actions as the action array.")

@classmethod
def _check_sum(cls, name: str, data: Dict[str, np.ndarray]):
Expand Down
Loading