Skip to content

Commit 2e8bccb

Browse files
committed
Group the tree analysis and results in a simpler layout
1 parent ff3a2ef commit 2e8bccb

13 files changed

Lines changed: 15 additions & 15 deletions

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
- name: Run regression tests
2525
run: python -m unittest discover -s tests -v
2626
- name: Run the documented example
27-
run: python demo.py
27+
run: python -m analysis.demo

.gitignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ For 100 keys, the narrowest feasible range contains **79 root positions**. Roots
1212
| Maximum minimum reward | 1–100 | 0.105679 | +0.028524 | 0 |
1313
| **Smallest range, then maximum mean** | **4–82** | **0.131744** | **+0.000001** | **0** |
1414

15-
![Expected reward for each key and root-selection probabilities for the minimum-range solution](assets/reward-comparison.png)
15+
![Expected reward for each key and root-selection probabilities for the minimum-range solution](reward-comparison.png)
1616

1717
The new solution improves the mean by approximately **24.7%** over the all-root maximin mixture while keeping every key's expected reward positive. It trades some protection for the worst-served key for a higher average reward.
1818

19-
[Root probabilities](assets/root-weights.csv) · [Expected rewards by key](assets/key-rewards.csv) · [Search results](assets/results.json)
19+
[Root probabilities](analysis/results/root-weights.csv) · [Expected rewards by key](analysis/results/key-rewards.csv) · [Search results](analysis/results/results.json)
2020

2121
## How the strategy is found
2222

@@ -48,11 +48,11 @@ This is an expected-reward result for the defined tree family. It does not mean
4848

4949
```bash
5050
python -m pip install -r requirements.txt
51-
python demo.py
51+
python -m analysis.demo
5252
python -m unittest discover -s tests -v
5353
```
5454

55-
The calculation writes the figure, root weights, per-key expectations and search results to `outputs/demo/`. The walkthrough is in [Binary Search Trees.ipynb](Binary%20Search%20Trees.ipynb).
55+
The calculation in `analysis/demo.py` writes the figure, root weights, per-key expectations and search results to `outputs/demo/`. The walkthrough is in [Binary Search Trees.ipynb](analysis/Binary%20Search%20Trees.ipynb).
5656

5757
Tests check the tree construction, probability constraints, small problems with known solutions, the minimum feasible range and strict positivity of every expected reward.
5858

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414
"cell_type": "code",
1515
"metadata": {},
1616
"source": [
17+
"from pathlib import Path\n",
18+
"import sys\n",
19+
"root = Path.cwd()\n",
20+
"if not (root / \"analysis\").is_dir():\n",
21+
" root = root.parent\n",
22+
"sys.path.insert(0, str(root))\n",
1723
"import numpy as np\n",
1824
"import matplotlib.pyplot as plt\n",
19-
"from bst_rewards import reward_matrix, minimum_positive_range\n",
25+
"from analysis.bst_rewards import reward_matrix, minimum_positive_range\n",
2026
"\n",
2127
"rewards = reward_matrix(range(1, 101))\n",
2228
"result = minimum_positive_range(rewards, reward_floor=1e-6)\n",

analysis/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Binary-search-tree reward analysis."""
File renamed without changes.

demo.py renamed to analysis/demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import matplotlib.pyplot as plt
99
import numpy as np
1010

11-
from bst_rewards import reward_matrix, optimise_mixture, minimum_positive_range
11+
from analysis.bst_rewards import reward_matrix, optimise_mixture, minimum_positive_range
1212

1313

1414
def main():

0 commit comments

Comments
 (0)