Skip to content

Commit 2099aed

Browse files
Merge pull request #15 from Mikata-Project/TransportS1measure2lossy-metrics-patch
Changed lossy case for metrics to match paper
2 parents 0a26a65 + d0cddd5 commit 2099aed

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

adcraft/experiment_utils/experiment_metrics.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ def get_explicit_kw_bid_cpc_impressions(
1313
"""Compute the auction win rate and approximate cost for each bid in bid array."""
1414
impression_rate = np.array([explicit_keyword.impression_rate(b) for b in bid_array])
1515
N = len(bid_array)
16-
cost = np.reshape(np.tile(np.reshape(bid_array, (1, -1)), (1, n_samples)), (-1,))
17-
explicit_keyword.cost_per_buyside_click(cost)
18-
med_cost_per_bid = np.median(np.reshape(cost, (n_samples, N)), axis=0)
16+
med_cost_per_bid = np.array([np.median(explicit_keyword.cost_per_buyside_click(bid, n_samples)) for bid in bid_array])
1917
return impression_rate, med_cost_per_bid
2018

2119

@@ -59,7 +57,7 @@ def get_max_expected_bid_profits(
5957
)
6058
return (
6159
max([0.0, expected_profits.max()]),
62-
np.sum(expected_profits > 0) / len(expected_cpc_per_bid),
60+
np.sum(expected_profits > 0) / len(expected_cpc_per_bid), np.argmax(expected_profits)
6361
)
6462

6563

@@ -70,10 +68,16 @@ def compute_AKNCP(kw_profits: np.array, ideal_profits: np.array) -> float:
7068
kw_params: ((vol_mean, vol_std), 50%_impression_bid, 50%_impression_slope, bctr, sctr, mean_revenue, std_revenue)
7169
expected_profits = vol_mean * impression_rate * bctr * (sctr * mean_revenue - costs).
7270
"""
73-
ideal_profits_edit = np.maximum(ideal_profits, 0.001)
74-
return np.median(kw_profits.mean(axis=0) / ideal_profits_edit.mean(axis=0))
71+
denominator = ideal_profits.copy()
72+
denominator[denominator <= 0] = 1.0
73+
denominator = denominator.mean(axis=0)
74+
# if ideal_profits is same as keyword_profits, then that should be 1.
75+
return np.median(kw_profits.mean(axis=0) / denominator)
7576

7677

7778
def compute_NCP(kw_profits: np.array, ideal_profits: np.array) -> float:
7879
"""Return the ratio of actual profit to ideal profits."""
79-
return kw_profits.sum() / ideal_profits.sum()
80+
denominator = ideal_profits.sum()
81+
if denominator <= 0.0:
82+
denominator = 1.0
83+
return kw_profits.sum() / denominator

0 commit comments

Comments
 (0)