Skip to content

Commit 0093535

Browse files
shaharbar1Shahar-Bar
authored andcommitted
Add offline policy evaluation module and update dependencies
### Changes * Introduced `offline_policy_evaluator.py` with classes for propensity score estimation and offline policy evaluation. * Updated `pyproject.toml` to include new dependencies: `bokeh`, `obp` and `optuna`. Further adjusted existing dependencies to compatible versions. * Added class method to PyBanditsBaseModel on base.py to allow seeing default values for arguments that were not passed to the model. * Added test_offline_policy_evaluator.py as a test suite for the OfflinePolicyEvaluator. * Added `visualize_via_bokeh` and `in_jupyter_notebook` utility functions.
1 parent cddda5c commit 0093535

22 files changed

+2642
-1490
lines changed

.github/workflows/continuous_delivery.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
python-version: [ "3.8", "3.9", "3.10" ]
14+
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
1515

1616
steps:
1717
- name: Checkout repository

.github/workflows/continuous_integration.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
python-version: [ "3.8", "3.9", "3.10" ]
23+
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
2424

2525
steps:
2626
- name: Checkout repository
@@ -43,4 +43,8 @@ jobs:
4343
poetry run pre-commit run --all-files
4444
- name: Run tests
4545
run: |
46+
START_TIME=$(date +%s)
4647
poetry run pytest -vv -k 'not time and not update_parallel'
48+
END_TIME=$(date +%s)
49+
DURATION=$((END_TIME - START_TIME))
50+
echo "Tests completed in $DURATION seconds."

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repos:
2525
types_or: [ python, pyi, jupyter ]
2626
require_serial: true
2727

28-
- repo: https://github.com/fastai/nbdev
29-
rev: 2.3.11
28+
- repo: https://github.com/kynan/nbstripout
29+
rev: 0.7.1
3030
hooks:
31-
- id: nbdev_clean
31+
- id: nbstripout

docs/src/tutorials/cmab.ipynb

Lines changed: 11 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
{
3636
"cell_type": "code",
37-
"execution_count": 1,
37+
"execution_count": null,
3838
"metadata": {
3939
"pycharm": {
4040
"is_executing": false
@@ -56,31 +56,13 @@
5656
},
5757
{
5858
"cell_type": "code",
59-
"execution_count": 2,
59+
"execution_count": null,
6060
"metadata": {
6161
"pycharm": {
6262
"is_executing": false
6363
}
6464
},
65-
"outputs": [
66-
{
67-
"name": "stdout",
68-
"output_type": "stream",
69-
"text": [
70-
"X: context matrix of shape (n_samples, n_features)\n",
71-
"[[-0.53211475 -0.40592956 0.05892565 -0.88067628 -0.84061481]\n",
72-
" [-0.95680954 -0.00540581 0.09148556 -0.82021004 -0.63425381]\n",
73-
" [-0.87792928 -0.51881823 -0.51767022 -0.05385187 -0.64499044]\n",
74-
" [-0.10569516 0.30847784 -0.353929 -0.94831998 -0.52175713]\n",
75-
" [-0.05088401 0.17155683 -0.4322128 -0.07509104 -0.78919832]\n",
76-
" [-0.88604157 0.55037109 0.42634479 -0.87179776 -0.69767766]\n",
77-
" [-0.0022063 0.99304089 0.76398198 -0.87343131 -0.12363411]\n",
78-
" [ 0.36371019 0.6660538 0.17177652 -0.08891719 -0.91070485]\n",
79-
" [-0.1056742 -0.72879406 -0.69367421 -0.8684397 0.70903817]\n",
80-
" [-0.15422305 0.31069811 -0.47487951 0.00853137 0.23793364]]\n"
81-
]
82-
}
83-
],
65+
"outputs": [],
8466
"source": [
8567
"# context\n",
8668
"n_samples = 1000\n",
@@ -92,7 +74,7 @@
9274
},
9375
{
9476
"cell_type": "code",
95-
"execution_count": 3,
77+
"execution_count": null,
9678
"metadata": {},
9779
"outputs": [],
9880
"source": [
@@ -109,7 +91,7 @@
10991
},
11092
{
11193
"cell_type": "code",
112-
"execution_count": 4,
94+
"execution_count": null,
11395
"metadata": {},
11496
"outputs": [],
11597
"source": [
@@ -126,18 +108,9 @@
126108
},
127109
{
128110
"cell_type": "code",
129-
"execution_count": 5,
111+
"execution_count": null,
130112
"metadata": {},
131-
"outputs": [
132-
{
133-
"name": "stdout",
134-
"output_type": "stream",
135-
"text": [
136-
"Recommended action: ['action C' 'action C' 'action B' 'action B' 'action C' 'action C'\n",
137-
" 'action B' 'action C' 'action B' 'action C']\n"
138-
]
139-
}
140-
],
113+
"outputs": [],
141114
"source": [
142115
"# predict action\n",
143116
"pred_actions, _ = cmab.predict(X)\n",
@@ -153,17 +126,9 @@
153126
},
154127
{
155128
"cell_type": "code",
156-
"execution_count": 6,
129+
"execution_count": null,
157130
"metadata": {},
158-
"outputs": [
159-
{
160-
"name": "stdout",
161-
"output_type": "stream",
162-
"text": [
163-
"Simulated rewards: [1 0 0 0 0 0 0 0 1 1]\n"
164-
]
165-
}
166-
],
131+
"outputs": [],
167132
"source": [
168133
"# simulate reward from environment\n",
169134
"simulated_rewards = np.random.randint(2, size=n_samples)\n",
@@ -179,31 +144,9 @@
179144
},
180145
{
181146
"cell_type": "code",
182-
"execution_count": 7,
147+
"execution_count": null,
183148
"metadata": {},
184-
"outputs": [
185-
{
186-
"name": "stderr",
187-
"output_type": "stream",
188-
"text": [
189-
"Auto-assigning NUTS sampler...\n",
190-
"Initializing NUTS using adapt_diag...\n",
191-
"Sequential sampling (2 chains in 1 job)\n",
192-
"NUTS: [beta4, beta3, beta2, beta1, beta0, alpha]\n",
193-
"Sampling 2 chains for 500 tune and 1_000 draw iterations (1_000 + 2_000 draws total) took 5 seconds.\n",
194-
"Auto-assigning NUTS sampler...\n",
195-
"Initializing NUTS using adapt_diag...\n",
196-
"Sequential sampling (2 chains in 1 job)\n",
197-
"NUTS: [beta4, beta3, beta2, beta1, beta0, alpha]\n",
198-
"Sampling 2 chains for 500 tune and 1_000 draw iterations (1_000 + 2_000 draws total) took 3 seconds.\n",
199-
"Auto-assigning NUTS sampler...\n",
200-
"Initializing NUTS using adapt_diag...\n",
201-
"Sequential sampling (2 chains in 1 job)\n",
202-
"NUTS: [beta4, beta3, beta2, beta1, beta0, alpha]\n",
203-
"Sampling 2 chains for 500 tune and 1_000 draw iterations (1_000 + 2_000 draws total) took 3 seconds.\n"
204-
]
205-
}
206-
],
149+
"outputs": [],
207150
"source": [
208151
"# update model\n",
209152
"cmab.update(X, actions=pred_actions, rewards=simulated_rewards)"

0 commit comments

Comments
 (0)