bidlab 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bidlab-0.1.0/LICENSE +21 -0
- bidlab-0.1.0/PKG-INFO +144 -0
- bidlab-0.1.0/README.md +116 -0
- bidlab-0.1.0/pyproject.toml +90 -0
- bidlab-0.1.0/pyproject.toml.orig +86 -0
- bidlab-0.1.0/src/bidlab/__init__.py +74 -0
- bidlab-0.1.0/src/bidlab/auctions.py +186 -0
- bidlab-0.1.0/src/bidlab/bidders/__init__.py +27 -0
- bidlab-0.1.0/src/bidlab/bidders/bandits.py +110 -0
- bidlab-0.1.0/src/bidlab/bidders/base.py +543 -0
- bidlab-0.1.0/src/bidlab/bidders/baselines.py +118 -0
- bidlab-0.1.0/src/bidlab/bidders/pacing.py +120 -0
- bidlab-0.1.0/src/bidlab/bidders/stack.py +63 -0
- bidlab-0.1.0/src/bidlab/callbacks.py +103 -0
- bidlab-0.1.0/src/bidlab/config.py +279 -0
- bidlab-0.1.0/src/bidlab/logs.py +122 -0
- bidlab-0.1.0/src/bidlab/markets.py +763 -0
- bidlab-0.1.0/src/bidlab/metrics.py +385 -0
- bidlab-0.1.0/src/bidlab/py.typed +0 -0
- bidlab-0.1.0/src/bidlab/results.py +187 -0
- bidlab-0.1.0/src/bidlab/runner.py +224 -0
- bidlab-0.1.0/src/bidlab/simulator.py +512 -0
- bidlab-0.1.0/src/bidlab/types.py +182 -0
bidlab-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NovelioPI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
bidlab-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bidlab
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Bidder-side ad auction simulator for research on bidding methods
|
|
5
|
+
Keywords: ad auction,bidding,simulation,online advertising
|
|
6
|
+
Author: NovelioPI
|
|
7
|
+
Author-email: NovelioPI <novelioputra99@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering
|
|
17
|
+
Requires-Dist: cloudpickle>=3.0
|
|
18
|
+
Requires-Dist: numpy>=2.0
|
|
19
|
+
Requires-Dist: scipy>=1.13
|
|
20
|
+
Requires-Dist: pandas>=2.0 ; extra == 'pandas'
|
|
21
|
+
Requires-Python: >=3.12
|
|
22
|
+
Project-URL: Homepage, https://github.com/NovelioPI/bidlab
|
|
23
|
+
Project-URL: Source, https://github.com/NovelioPI/bidlab
|
|
24
|
+
Project-URL: Issues, https://github.com/NovelioPI/bidlab/issues
|
|
25
|
+
Project-URL: Changelog, https://github.com/NovelioPI/bidlab/blob/main/CHANGELOG.md
|
|
26
|
+
Provides-Extra: pandas
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# bidlab
|
|
30
|
+
|
|
31
|
+
A Python library for testing ad bidding methods, such as pacing, bid shading, and learning bidders, in simulated auctions.
|
|
32
|
+
|
|
33
|
+
You write a bidder class and a short Python script. bidlab runs the auctions, hides what a real bidder could not see, and reports the same metrics for every method.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install bidlab # core: numpy, scipy, cloudpickle
|
|
39
|
+
pip install "bidlab[pandas]" # adds Results.to_pandas()
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
bidlab needs Python 3.12 or later. To work on bidlab itself, run `uv sync` in a clone of this repo. Changes per release are in the [changelog](https://github.com/NovelioPI/bidlab/blob/main/CHANGELOG.md).
|
|
43
|
+
|
|
44
|
+
## Quickstart
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import bidlab as bl
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def true_value(bidder):
|
|
51
|
+
# OracleValue outputs the true value; put your own estimator here to test it.
|
|
52
|
+
return bl.Stack(bl.OracleValue(), bidder)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
config = bl.SimConfig(
|
|
56
|
+
campaigns=[
|
|
57
|
+
bl.Campaign("truthful", true_value(bl.Linear()), budget=50, base_value=5),
|
|
58
|
+
bl.Campaign("pid", true_value(bl.PidPacing()), budget=15, base_value=5),
|
|
59
|
+
bl.Campaign("bandit", true_value(bl.UcbMultiplier()), budget=50, base_value=5),
|
|
60
|
+
],
|
|
61
|
+
auction=bl.SecondPrice(reserve=0.01),
|
|
62
|
+
episodes=5,
|
|
63
|
+
steps=500,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
results = bl.run_many(config, seeds=range(3))
|
|
67
|
+
print(results.summary())
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`summary()` shows, for each bidder, the mean across seeds and a 95% Student-t interval.
|
|
71
|
+
|
|
72
|
+
## How one step works
|
|
73
|
+
|
|
74
|
+
1. The market draws the impression's public features and each campaign's conversion probability pᵢ, and optionally a click probability qᵢ. The default market, `LogisticMarket`, uses pᵢ = σ(x · φᵢ + βᵢ) for a random feature vector x, with no click stage (qᵢ = 1).
|
|
75
|
+
2. Each bidder's `forward` gets the inputs it names, such as `time`, `budget_left`, `floor`, `market` and each public feature. The simulator passes no value: each bidder estimates its own. `bl.OracleValue` reads the truth from `market`: the campaign's base value w times the chance of its event, which is 1 for an impression, qᵢ for a click, and qᵢ × pᵢ for a conversion, the default. A bid policy such as `bl.PidPacing` sits after it in a `bl.Stack`.
|
|
76
|
+
3. Each bid is capped at the bidder's remaining budget. The bidder does not see that amount; it tracks its own spend.
|
|
77
|
+
4. The auction picks a winner: `FirstPrice` or `SecondPrice`, with an optional reserve price. A market can add a floor and a hidden market price, the highest bid from outside; a campaign must beat it to win.
|
|
78
|
+
5. The winner is clicked with probability q, then converts with probability p of the winner.
|
|
79
|
+
6. Each bidder gets its own `BidResult`: the auction's `time`, its bid, and whether it won. It also holds the price it paid, whether it was clicked and converted, and its `realized_value`. A bidder computes its own reward from it. A loser never sees the winning price.
|
|
80
|
+
|
|
81
|
+
`bl.OracleValue(noise=0.5)` makes that value wrong by a set amount. [Simulation](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/simulation.md) covers the clock and reproducibility.
|
|
82
|
+
|
|
83
|
+
## Write a bidder
|
|
84
|
+
|
|
85
|
+
Subclass `bl.Bidder` and implement `forward`. Like a PyTorch module, `forward` names the inputs it needs, such as `forward(self, time_left, budget_left)`. Its output is the bid. After another bidder in a `bl.Stack`, it also gets that bidder's output as `value`.
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
class FlatBid(bl.Bidder):
|
|
89
|
+
def __init__(self, amount):
|
|
90
|
+
self.amount = amount
|
|
91
|
+
|
|
92
|
+
def forward(self):
|
|
93
|
+
return self.amount
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
flat = bl.SimConfig(
|
|
97
|
+
campaigns=[
|
|
98
|
+
bl.Campaign("flat", FlatBid(0.2), budget=50, base_value=5),
|
|
99
|
+
bl.Campaign("truthful", true_value(bl.Linear()), budget=50, base_value=5),
|
|
100
|
+
],
|
|
101
|
+
episodes=2,
|
|
102
|
+
steps=200,
|
|
103
|
+
)
|
|
104
|
+
print(bl.run_many(flat, seeds=range(2)).summary())
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
[Bidders](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/bidders.md) covers every input, the other hooks, learning from results, and stacking bidders with `bl.Stack`.
|
|
108
|
+
|
|
109
|
+
## Guides
|
|
110
|
+
|
|
111
|
+
| Guide | Covers |
|
|
112
|
+
|---|---|
|
|
113
|
+
| [Simulation](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/simulation.md) | Each step in detail, the clock, parallel runs, reproducibility |
|
|
114
|
+
| [Campaigns](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/campaigns.md) | Budget, the event a campaign pays for, base value, CPA target, segments |
|
|
115
|
+
| [Bidders](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/bidders.md) | Inputs, hooks, value models and bid control, `Stack`, built-in bidders |
|
|
116
|
+
| [Composite bidders](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/composite-bidders.md) | Bidders that hold and call other bidders |
|
|
117
|
+
| [Markets](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/markets.md) | Built-in markets, segments and targeting, custom markets |
|
|
118
|
+
| [Rewards](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/rewards.md) | A reward in the bidder's own code, logging it, comparing bidders |
|
|
119
|
+
| [Logging and callbacks](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/logging.md) | `self.log` in a bidder, and watching a run |
|
|
120
|
+
| [Results](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/results.md) | `Results`, `RunLog`, metric functions, regret |
|
|
121
|
+
|
|
122
|
+
[Metrics](https://github.com/NovelioPI/bidlab/blob/main/docs/metrics.md) defines every metric and its limits.
|
|
123
|
+
|
|
124
|
+
## Examples
|
|
125
|
+
|
|
126
|
+
Each script runs on its own, prints its results, and ends with the answer to its question.
|
|
127
|
+
|
|
128
|
+
| Script | Question |
|
|
129
|
+
|---|---|
|
|
130
|
+
| [getting_started/basic.py](https://github.com/NovelioPI/bidlab/blob/main/examples/getting_started/basic.py) | When the budget is tight, does PID pacing earn more surplus than truthful bidding? |
|
|
131
|
+
| [campaigns/events.py](https://github.com/NovelioPI/bidlab/blob/main/examples/campaigns/events.py) | With the same budget, does a click campaign pay less per click than a conversion campaign? |
|
|
132
|
+
| [bidders/segment_rate.py](https://github.com/NovelioPI/bidlab/blob/main/examples/bidders/segment_rate.py) | Does a bidder that counts conversions per segment learn that sports converts better than news? |
|
|
133
|
+
| [bidders/value_estimators.py](https://github.com/NovelioPI/bidlab/blob/main/examples/bidders/value_estimators.py) | Does a two-stage model on the public features estimate conversions better than counting? |
|
|
134
|
+
| [bidders/oracle_noise.py](https://github.com/NovelioPI/bidlab/blob/main/examples/bidders/oracle_noise.py) | Does noise in the value estimate cost a truthful bidder surplus? |
|
|
135
|
+
| [composite/night_shade.py](https://github.com/NovelioPI/bidlab/blob/main/examples/composite/night_shade.py) | When a parent shades harder at night, does its child PID raise its multiplier at night? |
|
|
136
|
+
| [markets/segments.py](https://github.com/NovelioPI/bidlab/blob/main/examples/markets/segments.py) | Does a sports-only bidder win any auction outside sports? |
|
|
137
|
+
| [markets/custom_market.py](https://github.com/NovelioPI/bidlab/blob/main/examples/markets/custom_market.py) | Does the all-day bidder pay more per win at night, when the night-only bidder joins? |
|
|
138
|
+
| [markets/independent_values.py](https://github.com/NovelioPI/bidlab/blob/main/examples/markets/independent_values.py) | In a first-price auction with uniform values, does shading to (n-1)/n beat truthful bidding? |
|
|
139
|
+
| [rewards/cpa_target.py](https://github.com/NovelioPI/bidlab/blob/main/examples/rewards/cpa_target.py) | Does bidding target/value of the value meet a CPA target that truthful bidding misses? |
|
|
140
|
+
| [rewards/custom_reward.py](https://github.com/NovelioPI/bidlab/blob/main/examples/rewards/custom_reward.py) | Does a bandit rewarded for conversions pick a higher multiplier than one rewarded for surplus? |
|
|
141
|
+
| [logging/pid_trace.py](https://github.com/NovelioPI/bidlab/blob/main/examples/logging/pid_trace.py) | Does PID pacing spend its whole budget in each episode? |
|
|
142
|
+
| [simulation/clock.py](https://github.com/NovelioPI/bidlab/blob/main/examples/simulation/clock.py) | With a 12-hour day from 9:00, does an even-schedule bidder still have budget at 20:00, when truthful bidding has run out? |
|
|
143
|
+
| [results/regret.py](https://github.com/NovelioPI/bidlab/blob/main/examples/results/regret.py) | With no budget limit in a second-price auction, is truthful bidding's regret zero? |
|
|
144
|
+
| [results/reserve.py](https://github.com/NovelioPI/bidlab/blob/main/examples/results/reserve.py) | Does a reserve price of 0.1 raise the platform's revenue? |
|
bidlab-0.1.0/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# bidlab
|
|
2
|
+
|
|
3
|
+
A Python library for testing ad bidding methods, such as pacing, bid shading, and learning bidders, in simulated auctions.
|
|
4
|
+
|
|
5
|
+
You write a bidder class and a short Python script. bidlab runs the auctions, hides what a real bidder could not see, and reports the same metrics for every method.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install bidlab # core: numpy, scipy, cloudpickle
|
|
11
|
+
pip install "bidlab[pandas]" # adds Results.to_pandas()
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
bidlab needs Python 3.12 or later. To work on bidlab itself, run `uv sync` in a clone of this repo. Changes per release are in the [changelog](https://github.com/NovelioPI/bidlab/blob/main/CHANGELOG.md).
|
|
15
|
+
|
|
16
|
+
## Quickstart
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
import bidlab as bl
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def true_value(bidder):
|
|
23
|
+
# OracleValue outputs the true value; put your own estimator here to test it.
|
|
24
|
+
return bl.Stack(bl.OracleValue(), bidder)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
config = bl.SimConfig(
|
|
28
|
+
campaigns=[
|
|
29
|
+
bl.Campaign("truthful", true_value(bl.Linear()), budget=50, base_value=5),
|
|
30
|
+
bl.Campaign("pid", true_value(bl.PidPacing()), budget=15, base_value=5),
|
|
31
|
+
bl.Campaign("bandit", true_value(bl.UcbMultiplier()), budget=50, base_value=5),
|
|
32
|
+
],
|
|
33
|
+
auction=bl.SecondPrice(reserve=0.01),
|
|
34
|
+
episodes=5,
|
|
35
|
+
steps=500,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
results = bl.run_many(config, seeds=range(3))
|
|
39
|
+
print(results.summary())
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`summary()` shows, for each bidder, the mean across seeds and a 95% Student-t interval.
|
|
43
|
+
|
|
44
|
+
## How one step works
|
|
45
|
+
|
|
46
|
+
1. The market draws the impression's public features and each campaign's conversion probability pᵢ, and optionally a click probability qᵢ. The default market, `LogisticMarket`, uses pᵢ = σ(x · φᵢ + βᵢ) for a random feature vector x, with no click stage (qᵢ = 1).
|
|
47
|
+
2. Each bidder's `forward` gets the inputs it names, such as `time`, `budget_left`, `floor`, `market` and each public feature. The simulator passes no value: each bidder estimates its own. `bl.OracleValue` reads the truth from `market`: the campaign's base value w times the chance of its event, which is 1 for an impression, qᵢ for a click, and qᵢ × pᵢ for a conversion, the default. A bid policy such as `bl.PidPacing` sits after it in a `bl.Stack`.
|
|
48
|
+
3. Each bid is capped at the bidder's remaining budget. The bidder does not see that amount; it tracks its own spend.
|
|
49
|
+
4. The auction picks a winner: `FirstPrice` or `SecondPrice`, with an optional reserve price. A market can add a floor and a hidden market price, the highest bid from outside; a campaign must beat it to win.
|
|
50
|
+
5. The winner is clicked with probability q, then converts with probability p of the winner.
|
|
51
|
+
6. Each bidder gets its own `BidResult`: the auction's `time`, its bid, and whether it won. It also holds the price it paid, whether it was clicked and converted, and its `realized_value`. A bidder computes its own reward from it. A loser never sees the winning price.
|
|
52
|
+
|
|
53
|
+
`bl.OracleValue(noise=0.5)` makes that value wrong by a set amount. [Simulation](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/simulation.md) covers the clock and reproducibility.
|
|
54
|
+
|
|
55
|
+
## Write a bidder
|
|
56
|
+
|
|
57
|
+
Subclass `bl.Bidder` and implement `forward`. Like a PyTorch module, `forward` names the inputs it needs, such as `forward(self, time_left, budget_left)`. Its output is the bid. After another bidder in a `bl.Stack`, it also gets that bidder's output as `value`.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
class FlatBid(bl.Bidder):
|
|
61
|
+
def __init__(self, amount):
|
|
62
|
+
self.amount = amount
|
|
63
|
+
|
|
64
|
+
def forward(self):
|
|
65
|
+
return self.amount
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
flat = bl.SimConfig(
|
|
69
|
+
campaigns=[
|
|
70
|
+
bl.Campaign("flat", FlatBid(0.2), budget=50, base_value=5),
|
|
71
|
+
bl.Campaign("truthful", true_value(bl.Linear()), budget=50, base_value=5),
|
|
72
|
+
],
|
|
73
|
+
episodes=2,
|
|
74
|
+
steps=200,
|
|
75
|
+
)
|
|
76
|
+
print(bl.run_many(flat, seeds=range(2)).summary())
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
[Bidders](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/bidders.md) covers every input, the other hooks, learning from results, and stacking bidders with `bl.Stack`.
|
|
80
|
+
|
|
81
|
+
## Guides
|
|
82
|
+
|
|
83
|
+
| Guide | Covers |
|
|
84
|
+
|---|---|
|
|
85
|
+
| [Simulation](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/simulation.md) | Each step in detail, the clock, parallel runs, reproducibility |
|
|
86
|
+
| [Campaigns](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/campaigns.md) | Budget, the event a campaign pays for, base value, CPA target, segments |
|
|
87
|
+
| [Bidders](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/bidders.md) | Inputs, hooks, value models and bid control, `Stack`, built-in bidders |
|
|
88
|
+
| [Composite bidders](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/composite-bidders.md) | Bidders that hold and call other bidders |
|
|
89
|
+
| [Markets](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/markets.md) | Built-in markets, segments and targeting, custom markets |
|
|
90
|
+
| [Rewards](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/rewards.md) | A reward in the bidder's own code, logging it, comparing bidders |
|
|
91
|
+
| [Logging and callbacks](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/logging.md) | `self.log` in a bidder, and watching a run |
|
|
92
|
+
| [Results](https://github.com/NovelioPI/bidlab/blob/main/docs/guides/results.md) | `Results`, `RunLog`, metric functions, regret |
|
|
93
|
+
|
|
94
|
+
[Metrics](https://github.com/NovelioPI/bidlab/blob/main/docs/metrics.md) defines every metric and its limits.
|
|
95
|
+
|
|
96
|
+
## Examples
|
|
97
|
+
|
|
98
|
+
Each script runs on its own, prints its results, and ends with the answer to its question.
|
|
99
|
+
|
|
100
|
+
| Script | Question |
|
|
101
|
+
|---|---|
|
|
102
|
+
| [getting_started/basic.py](https://github.com/NovelioPI/bidlab/blob/main/examples/getting_started/basic.py) | When the budget is tight, does PID pacing earn more surplus than truthful bidding? |
|
|
103
|
+
| [campaigns/events.py](https://github.com/NovelioPI/bidlab/blob/main/examples/campaigns/events.py) | With the same budget, does a click campaign pay less per click than a conversion campaign? |
|
|
104
|
+
| [bidders/segment_rate.py](https://github.com/NovelioPI/bidlab/blob/main/examples/bidders/segment_rate.py) | Does a bidder that counts conversions per segment learn that sports converts better than news? |
|
|
105
|
+
| [bidders/value_estimators.py](https://github.com/NovelioPI/bidlab/blob/main/examples/bidders/value_estimators.py) | Does a two-stage model on the public features estimate conversions better than counting? |
|
|
106
|
+
| [bidders/oracle_noise.py](https://github.com/NovelioPI/bidlab/blob/main/examples/bidders/oracle_noise.py) | Does noise in the value estimate cost a truthful bidder surplus? |
|
|
107
|
+
| [composite/night_shade.py](https://github.com/NovelioPI/bidlab/blob/main/examples/composite/night_shade.py) | When a parent shades harder at night, does its child PID raise its multiplier at night? |
|
|
108
|
+
| [markets/segments.py](https://github.com/NovelioPI/bidlab/blob/main/examples/markets/segments.py) | Does a sports-only bidder win any auction outside sports? |
|
|
109
|
+
| [markets/custom_market.py](https://github.com/NovelioPI/bidlab/blob/main/examples/markets/custom_market.py) | Does the all-day bidder pay more per win at night, when the night-only bidder joins? |
|
|
110
|
+
| [markets/independent_values.py](https://github.com/NovelioPI/bidlab/blob/main/examples/markets/independent_values.py) | In a first-price auction with uniform values, does shading to (n-1)/n beat truthful bidding? |
|
|
111
|
+
| [rewards/cpa_target.py](https://github.com/NovelioPI/bidlab/blob/main/examples/rewards/cpa_target.py) | Does bidding target/value of the value meet a CPA target that truthful bidding misses? |
|
|
112
|
+
| [rewards/custom_reward.py](https://github.com/NovelioPI/bidlab/blob/main/examples/rewards/custom_reward.py) | Does a bandit rewarded for conversions pick a higher multiplier than one rewarded for surplus? |
|
|
113
|
+
| [logging/pid_trace.py](https://github.com/NovelioPI/bidlab/blob/main/examples/logging/pid_trace.py) | Does PID pacing spend its whole budget in each episode? |
|
|
114
|
+
| [simulation/clock.py](https://github.com/NovelioPI/bidlab/blob/main/examples/simulation/clock.py) | With a 12-hour day from 9:00, does an even-schedule bidder still have budget at 20:00, when truthful bidding has run out? |
|
|
115
|
+
| [results/regret.py](https://github.com/NovelioPI/bidlab/blob/main/examples/results/regret.py) | With no budget limit in a second-price auction, is truthful bidding's regret zero? |
|
|
116
|
+
| [results/reserve.py](https://github.com/NovelioPI/bidlab/blob/main/examples/results/reserve.py) | Does a reserve price of 0.1 raise the platform's revenue? |
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "bidlab"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Bidder-side ad auction simulator for research on bidding methods"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
keywords = [
|
|
10
|
+
"ad auction",
|
|
11
|
+
"bidding",
|
|
12
|
+
"simulation",
|
|
13
|
+
"online advertising",
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Topic :: Scientific/Engineering",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"cloudpickle>=3.0",
|
|
26
|
+
"numpy>=2.0",
|
|
27
|
+
"scipy>=1.13",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[[project.authors]]
|
|
31
|
+
name = "NovelioPI"
|
|
32
|
+
email = "novelioputra99@gmail.com"
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
pandas = ["pandas>=2.0"]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://github.com/NovelioPI/bidlab"
|
|
39
|
+
Source = "https://github.com/NovelioPI/bidlab"
|
|
40
|
+
Issues = "https://github.com/NovelioPI/bidlab/issues"
|
|
41
|
+
Changelog = "https://github.com/NovelioPI/bidlab/blob/main/CHANGELOG.md"
|
|
42
|
+
|
|
43
|
+
[dependency-groups]
|
|
44
|
+
dev = [
|
|
45
|
+
"hypothesis>=6.170.15",
|
|
46
|
+
"mutmut>=3.8.1",
|
|
47
|
+
"pyright>=1.1.414",
|
|
48
|
+
"pytest>=8.0",
|
|
49
|
+
"ruff>=0.17.5",
|
|
50
|
+
"scipy-stubs>=1.18.1.1",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
[build-system]
|
|
54
|
+
requires = ["uv_build>=0.11,<0.12"]
|
|
55
|
+
build-backend = "uv_build"
|
|
56
|
+
|
|
57
|
+
[tool.mutmut]
|
|
58
|
+
source_paths = ["src/bidlab/"]
|
|
59
|
+
do_not_mutate = [
|
|
60
|
+
"src/bidlab/__init__.py",
|
|
61
|
+
"src/bidlab/config.py",
|
|
62
|
+
"src/bidlab/results.py",
|
|
63
|
+
"src/bidlab/runner.py",
|
|
64
|
+
"src/bidlab/simulator.py",
|
|
65
|
+
"src/bidlab/types.py",
|
|
66
|
+
"src/bidlab/bidders/*",
|
|
67
|
+
]
|
|
68
|
+
pytest_add_cli_args_test_selection = ["tests/"]
|
|
69
|
+
also_copy = [
|
|
70
|
+
"docs/",
|
|
71
|
+
"README.md",
|
|
72
|
+
"pyproject.toml",
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
[tool.pytest.ini_options]
|
|
76
|
+
testpaths = ["tests"]
|
|
77
|
+
|
|
78
|
+
[tool.ruff.lint]
|
|
79
|
+
extend-select = ["D"]
|
|
80
|
+
ignore = ["D105"]
|
|
81
|
+
|
|
82
|
+
[tool.ruff.lint.pydocstyle]
|
|
83
|
+
convention = "numpy"
|
|
84
|
+
|
|
85
|
+
[tool.ruff.lint.per-file-ignores]
|
|
86
|
+
"tests/*" = ["D"]
|
|
87
|
+
"examples/*" = ["D"]
|
|
88
|
+
|
|
89
|
+
[tool.pyright]
|
|
90
|
+
include = ["src"]
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "bidlab"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Bidder-side ad auction simulator for research on bidding methods"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "NovelioPI", email = "novelioputra99@gmail.com" },
|
|
11
|
+
]
|
|
12
|
+
keywords = ["ad auction", "bidding", "simulation", "online advertising"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Science/Research",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Topic :: Scientific/Engineering",
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"cloudpickle>=3.0",
|
|
24
|
+
"numpy>=2.0",
|
|
25
|
+
"scipy>=1.13",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
pandas = [
|
|
30
|
+
"pandas>=2.0",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/NovelioPI/bidlab"
|
|
35
|
+
Source = "https://github.com/NovelioPI/bidlab"
|
|
36
|
+
Issues = "https://github.com/NovelioPI/bidlab/issues"
|
|
37
|
+
Changelog = "https://github.com/NovelioPI/bidlab/blob/main/CHANGELOG.md"
|
|
38
|
+
|
|
39
|
+
[dependency-groups]
|
|
40
|
+
dev = [
|
|
41
|
+
"hypothesis>=6.170.15",
|
|
42
|
+
"mutmut>=3.8.1",
|
|
43
|
+
"pyright>=1.1.414",
|
|
44
|
+
"pytest>=8.0",
|
|
45
|
+
"ruff>=0.17.5",
|
|
46
|
+
"scipy-stubs>=1.18.1.1",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[build-system]
|
|
50
|
+
requires = ["uv_build>=0.11,<0.12"]
|
|
51
|
+
build-backend = "uv_build"
|
|
52
|
+
|
|
53
|
+
[tool.mutmut]
|
|
54
|
+
source_paths = ["src/bidlab/"]
|
|
55
|
+
# Mutate only the core modules for this feature; the rest is copied so imports work.
|
|
56
|
+
do_not_mutate = [
|
|
57
|
+
"src/bidlab/__init__.py",
|
|
58
|
+
"src/bidlab/config.py",
|
|
59
|
+
"src/bidlab/results.py",
|
|
60
|
+
"src/bidlab/runner.py",
|
|
61
|
+
"src/bidlab/simulator.py",
|
|
62
|
+
"src/bidlab/types.py",
|
|
63
|
+
"src/bidlab/bidders/*",
|
|
64
|
+
]
|
|
65
|
+
pytest_add_cli_args_test_selection = ["tests/"]
|
|
66
|
+
# The docs and API tests read these files from the mutants copy.
|
|
67
|
+
also_copy = ["docs/", "README.md", "pyproject.toml"]
|
|
68
|
+
|
|
69
|
+
[tool.pytest.ini_options]
|
|
70
|
+
testpaths = ["tests"]
|
|
71
|
+
|
|
72
|
+
[tool.ruff.lint]
|
|
73
|
+
extend-select = ["D"]
|
|
74
|
+
# Magic methods such as __post_init__ and __len__ describe themselves.
|
|
75
|
+
ignore = ["D105"]
|
|
76
|
+
|
|
77
|
+
[tool.ruff.lint.pydocstyle]
|
|
78
|
+
convention = "numpy"
|
|
79
|
+
|
|
80
|
+
[tool.ruff.lint.per-file-ignores]
|
|
81
|
+
"tests/*" = ["D"]
|
|
82
|
+
"examples/*" = ["D"]
|
|
83
|
+
|
|
84
|
+
[tool.pyright]
|
|
85
|
+
# Tests pass wrong types on purpose to check the error messages.
|
|
86
|
+
include = ["src"]
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""bidlab: simulate ad auctions to test and compare bidding methods.
|
|
2
|
+
|
|
3
|
+
Examples
|
|
4
|
+
--------
|
|
5
|
+
>>> import bidlab as bl
|
|
6
|
+
>>> config = bl.SimConfig(
|
|
7
|
+
... campaigns=[
|
|
8
|
+
... bl.Campaign(
|
|
9
|
+
... "truthful",
|
|
10
|
+
... bl.Stack(bl.OracleValue(), bl.Linear()),
|
|
11
|
+
... budget=50,
|
|
12
|
+
... base_value=5,
|
|
13
|
+
... ),
|
|
14
|
+
... bl.Campaign(
|
|
15
|
+
... "pid",
|
|
16
|
+
... bl.Stack(bl.OracleValue(), bl.PidPacing()),
|
|
17
|
+
... budget=15,
|
|
18
|
+
... base_value=5,
|
|
19
|
+
... ),
|
|
20
|
+
... ],
|
|
21
|
+
... auction=bl.SecondPrice(reserve=0.01),
|
|
22
|
+
... episodes=2,
|
|
23
|
+
... steps=100,
|
|
24
|
+
... )
|
|
25
|
+
>>> results = bl.run_many(config, seeds=range(2))
|
|
26
|
+
>>> len(results)
|
|
27
|
+
4
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
from bidlab import bidders, markets
|
|
31
|
+
from bidlab.auctions import FirstPrice, SecondPrice
|
|
32
|
+
from bidlab.bidders import (
|
|
33
|
+
Bidder,
|
|
34
|
+
Linear,
|
|
35
|
+
OracleValue,
|
|
36
|
+
PidPacing,
|
|
37
|
+
Stack,
|
|
38
|
+
UcbMultiplier,
|
|
39
|
+
)
|
|
40
|
+
from bidlab.callbacks import Callback
|
|
41
|
+
from bidlab.config import Campaign, SimConfig
|
|
42
|
+
from bidlab.metrics import campaign_metrics, platform_metrics, regret, segment_metrics
|
|
43
|
+
from bidlab.results import Results
|
|
44
|
+
from bidlab.runner import run_many
|
|
45
|
+
from bidlab.simulator import RunLog, run
|
|
46
|
+
from bidlab.types import BidResult, EpisodeReport, Event, MarketTruth
|
|
47
|
+
|
|
48
|
+
__all__ = [
|
|
49
|
+
"BidResult",
|
|
50
|
+
"Bidder",
|
|
51
|
+
"Callback",
|
|
52
|
+
"Campaign",
|
|
53
|
+
"EpisodeReport",
|
|
54
|
+
"Event",
|
|
55
|
+
"FirstPrice",
|
|
56
|
+
"Linear",
|
|
57
|
+
"MarketTruth",
|
|
58
|
+
"OracleValue",
|
|
59
|
+
"PidPacing",
|
|
60
|
+
"Results",
|
|
61
|
+
"RunLog",
|
|
62
|
+
"SecondPrice",
|
|
63
|
+
"SimConfig",
|
|
64
|
+
"Stack",
|
|
65
|
+
"UcbMultiplier",
|
|
66
|
+
"bidders",
|
|
67
|
+
"campaign_metrics",
|
|
68
|
+
"markets",
|
|
69
|
+
"platform_metrics",
|
|
70
|
+
"regret",
|
|
71
|
+
"run",
|
|
72
|
+
"run_many",
|
|
73
|
+
"segment_metrics",
|
|
74
|
+
]
|