Surge-based adds (onset, or plays jumping well above the artist's own baseline and staying up): finds 77% of DR's real song adds vs 64% for onset only; addcheck validation against the lists
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+44
-44
@@ -1,56 +1,56 @@
|
|||||||
# Backtest: if the artist releases a new song, will DR add it?
|
# Backtest: if the artist releases a new song, will DR add it?
|
||||||
|
|
||||||
Events: an artist in the panel releases something (Deezer) in week t0+1, with no other release in the 6 weeks before (so an add can't be the previous song's); target: a DR add (entering rotation after 4+ weeks out) within the 8 weeks from the release week. The model knows the artist's state the week before; the new song's NMF Denmark placement is blended from the artist's history. 2302 release events scored, 100 (4.3%) got an add on some DR channel.
|
Events: an artist in the panel releases something (Deezer) in week t0+1, with no other release in the 6 weeks before (so an add can't be the previous song's); target: a DR add (entering rotation after 4+ weeks out) within the 8 weeks from the release week. The model knows the artist's state the week before; the new song's NMF Denmark placement is blended from the artist's history. 2302 release events scored, 130 (5.6%) got an add on some DR channel.
|
||||||
|
|
||||||
| Model | Log-loss, any channel | PR-AUC, any channel | Log-loss, per channel | PR-AUC, per channel |
|
| Model | Log-loss, any channel | PR-AUC, any channel | Log-loss, per channel | PR-AUC, per channel |
|
||||||
|---|---|---|---|---|
|
|---|---|---|---|---|
|
||||||
| rate by in-rotation-now | 0.1791 | 0.042 | 0.0572 | 0.011 |
|
| rate by in-rotation-now | 0.2073 | 0.118 | 0.0666 | 0.052 |
|
||||||
| rate by last-12-weeks level | 0.1604 | 0.116 | 0.0434 | 0.123 |
|
| rate by last-12-weeks level | 0.1831 | 0.201 | 0.0492 | 0.190 |
|
||||||
| event model | 0.1555 | 0.186 | 0.0373 | 0.273 |
|
| event model | 0.1803 | 0.258 | 0.0436 | 0.320 |
|
||||||
|
|
||||||
Skill of the event model, any channel: 0.132 (0.090 to 0.200) vs in-rotation-now, 0.031 (0.010 to 0.079) vs last-12-weeks level.
|
Skill of the event model, any channel: 0.130 (0.085 to 0.187) vs in-rotation-now, 0.015 (-0.036 to 0.061) vs last-12-weeks level.
|
||||||
|
|
||||||
| Any-channel feature (all events) | Coefficient |
|
| Any-channel feature (all events) | Coefficient |
|
||||||
|---|---|
|
|---|---|
|
||||||
| intercept | -5.512 |
|
| intercept | -3.676 |
|
||||||
| log DR plays t | +0.487 |
|
| log DR plays t | +0.461 |
|
||||||
| log DR plays 4w | +0.863 |
|
| log DR plays 4w | +0.667 |
|
||||||
| log DR plays 12w | -0.818 |
|
| log DR plays 12w | -0.467 |
|
||||||
| log max DR plays 12w | +0.446 |
|
| log max DR plays 12w | +0.260 |
|
||||||
| in rotation anywhere now | -1.356 |
|
| in rotation anywhere now | -0.464 |
|
||||||
| station groups in rotation now (/5) | -0.502 |
|
| station groups in rotation now (/5) | -0.219 |
|
||||||
| current run anywhere (/12) | -1.526 |
|
| current run anywhere (/12) | -1.217 |
|
||||||
| weeks since in rotation anywhere (/12) | +0.130 |
|
| weeks since in rotation anywhere (/12) | -0.542 |
|
||||||
| Track Top-40 score | -0.490 |
|
| Track Top-40 score | -0.339 |
|
||||||
| Airplay Top-20 score | -0.429 |
|
| Airplay Top-20 score | -0.125 |
|
||||||
| chart entry recency 6w | +0.331 |
|
| chart entry recency 6w | +0.509 |
|
||||||
| chart entry recency 26w | -0.122 |
|
| chart entry recency 26w | +0.377 |
|
||||||
| log Track Top-40 hits | -0.308 |
|
| log Track Top-40 hits | -0.310 |
|
||||||
| log Airplay Top-20 hits | -0.100 |
|
| log Airplay Top-20 hits | -0.180 |
|
||||||
| Danish | +0.759 |
|
| Danish | +0.640 |
|
||||||
| group | -0.008 |
|
| group | +0.038 |
|
||||||
| female | +0.124 |
|
| female | -0.081 |
|
||||||
| career years (/50) | +0.528 |
|
| career years (/50) | +0.505 |
|
||||||
| debut unknown | +0.596 |
|
| debut unknown | +0.552 |
|
||||||
| Christmas in window | +0.000 |
|
| Christmas in window | +0.000 |
|
||||||
| discography known | -0.000 |
|
| discography known | -0.000 |
|
||||||
| release recency 4w | -0.124 |
|
| release recency 4w | +0.167 |
|
||||||
| release recency 12w | -0.866 |
|
| release recency 12w | -0.863 |
|
||||||
| log releases last 52w | -0.177 |
|
| log releases last 52w | -0.208 |
|
||||||
| releases in the window | -0.000 |
|
| releases in the window | -0.000 |
|
||||||
| releases in window x not in rotation now | +1.356 |
|
| releases in window x not in rotation now | +0.464 |
|
||||||
| DR: weeks since last add 13-25 | +0.144 |
|
| DR: weeks since last add 13-25 | -0.027 |
|
||||||
| DR: last add 26+ weeks ago | +0.659 |
|
| DR: last add 26+ weeks ago | +0.411 |
|
||||||
| DR: no add in the panel yet | -0.622 |
|
| DR: no add in the panel yet | -0.679 |
|
||||||
| Airplay Top-20: last new song 13-25 weeks ago | +0.398 |
|
| Airplay Top-20: last new song 13-25 weeks ago | +0.478 |
|
||||||
| Airplay Top-20: 0.5-1.25x own usual gap | -0.496 |
|
| Airplay Top-20: 0.5-1.25x own usual gap | -0.177 |
|
||||||
| Airplay Top-20: last new song 2+ years ago | -0.070 |
|
| Airplay Top-20: last new song 2+ years ago | -0.035 |
|
||||||
| log archive plays per 100 sampled hours (2012-21) | +0.317 |
|
| log archive plays per 100 sampled hours (2012-21) | +0.583 |
|
||||||
| log DR lists with the artist before t (2023-) | +0.431 |
|
| log DR lists with the artist before t (2023-) | +0.192 |
|
||||||
| DR list recency 26w | +0.046 |
|
| DR list recency 26w | -0.900 |
|
||||||
| DR lists known before t at all | -0.014 |
|
| DR lists known before t at all | +0.491 |
|
||||||
| NMF Denmark in the window | +0.769 |
|
| NMF Denmark in the window | +0.886 |
|
||||||
| NMF Denmark top 10 in the window | +0.783 |
|
| NMF Denmark top 10 in the window | +0.810 |
|
||||||
| log NMF Denmark placements last 52w | -0.056 |
|
| log NMF Denmark placements last 52w | -0.024 |
|
||||||
| share of releases on NMF Denmark (2 years) | -0.600 |
|
| share of releases on NMF Denmark (2 years) | -0.468 |
|
||||||
| season index of the window (log, IFPI 2002-24) | +0.451 |
|
| season index of the window (log, IFPI 2002-24) | +0.414 |
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
//! How well the artist-level add definitions find real song adds: a song new on a DR list
|
||||||
|
//! (vs the previous list) should come with an add for the artist in between.
|
||||||
|
|
||||||
|
use super::adds::{Rot, ADD_RULE};
|
||||||
|
use super::common::thresholds;
|
||||||
|
use super::panel::{key, Panel, CHANNELS};
|
||||||
|
use crate::db::Db;
|
||||||
|
use anyhow::Result;
|
||||||
|
use chrono::{Duration, NaiveDate};
|
||||||
|
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||||
|
use std::fmt::Write as _;
|
||||||
|
|
||||||
|
pub fn run(db: &Db, p: &Panel) -> Result<String> {
|
||||||
|
let mut lists: BTreeMap<NaiveDate, HashMap<String, HashSet<(String, String)>>> = BTreeMap::new();
|
||||||
|
for r in db.conn.prepare("SELECT list_date, channel, artist, title FROM rotation_lists WHERE category IN ('A', 'B', 'C', 'LIST')")?
|
||||||
|
.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?, r.get::<_, String>(2)?, r.get::<_, String>(3)?)))? {
|
||||||
|
let (d, ch, a, t) = r?;
|
||||||
|
if let Ok(d) = NaiveDate::parse_from_str(&d, "%Y-%m-%d") {
|
||||||
|
let primary = a.split(" [+] ").next().unwrap_or(&a).split(" feat").next().unwrap_or(&a).to_string();
|
||||||
|
lists.entry(d + Duration::days(3)).or_default().entry(ch).or_default().insert((key(&primary), key(t.split(" (").next().unwrap_or(&t))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let by_name: HashMap<String, usize> = p.artists.iter().enumerate().map(|(i, a)| (key(&a.name), i)).collect();
|
||||||
|
let week_of: HashMap<NaiveDate, usize> = p.weeks.iter().enumerate().map(|(i, d)| (*d, i)).collect();
|
||||||
|
let tau = thresholds(p, p.w());
|
||||||
|
let mut md = String::new();
|
||||||
|
writeln!(md, "# Add definitions vs DR's own lists\n\nA song new on a list (vs the previous list for the channel) should come with an add for its artist between the two lists (± 1 week).\n")?;
|
||||||
|
writeln!(md, "| Definition | New songs on lists (artist in the pool) | Artist add found | Recall | Artist adds per artist-week |\n|---|---|---|---|---|")?;
|
||||||
|
for rule in ["onset", "surge"] {
|
||||||
|
let _ = ADD_RULE.set(rule.to_string()); // OnceLock: only the first set counts; run each rule in its own process
|
||||||
|
if ADD_RULE.get().map(String::as_str) != Some(rule) { continue; }
|
||||||
|
let r = Rot::new(p, &tau);
|
||||||
|
let (mut n, mut hit) = (0usize, 0usize);
|
||||||
|
let dates: Vec<NaiveDate> = lists.keys().copied().collect();
|
||||||
|
for ch in ["p3", "p4", "p5", "p6beat", "p8jazz"] {
|
||||||
|
let ds: Vec<&NaiveDate> = dates.iter().filter(|d| lists[d].contains_key(ch)).collect();
|
||||||
|
for pair in ds.windows(2) {
|
||||||
|
let (Some(&w0), Some(&w1)) = (week_of.get(pair[0]), week_of.get(pair[1])) else { continue };
|
||||||
|
let (old, new) = (&lists[pair[0]][ch], &lists[pair[1]][ch]);
|
||||||
|
let chans: Vec<usize> = (0..CHANNELS.len()).filter(|&c| if ch == "p4" { CHANNELS[c].starts_with("p4") } else { CHANNELS[c] == ch }).collect();
|
||||||
|
for (artist, song) in new.difference(old) {
|
||||||
|
let _ = song;
|
||||||
|
let Some(&a) = by_name.get(artist) else { continue };
|
||||||
|
n += 1;
|
||||||
|
let lo = w0.saturating_sub(1);
|
||||||
|
let hi = (w1 + 1).min(p.w() - 1);
|
||||||
|
if (lo..=hi).any(|w| chans.iter().any(|&c| r.add(a, c, w))) { hit += 1; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let total: usize = (0..p.a()).map(|a| (0..p.w()).filter(|&w| r.add_any(a, w)).count()).sum();
|
||||||
|
writeln!(md, "| {rule} | {n} | {hit} | {:.0}% | {:.4} |", 100.0 * hit as f64 / n.max(1) as f64, total as f64 / (p.a() * p.w()) as f64)?;
|
||||||
|
}
|
||||||
|
Ok(md)
|
||||||
|
}
|
||||||
+36
-3
@@ -230,8 +230,16 @@ pub struct Rot {
|
|||||||
pub tau: [u32; C],
|
pub tau: [u32; C],
|
||||||
rot: Vec<bool>, // [a][c][w]
|
rot: Vec<bool>, // [a][c][w]
|
||||||
any: Vec<bool>, // [a][w]
|
any: Vec<bool>, // [a][w]
|
||||||
|
adds: Vec<bool>, // [a][c][w]
|
||||||
|
adds_any: Vec<bool>, // [a][w]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Which add definition: "onset" = entering rotation after GAP+ weeks out (the original); "surge" =
|
||||||
|
/// onset, or plays jumping well above the artist's own 8-week baseline and staying up the next
|
||||||
|
/// week (catches new songs of artists who never leave rotation). Default: surge.
|
||||||
|
pub static ADD_RULE: std::sync::OnceLock<String> = std::sync::OnceLock::new();
|
||||||
|
fn surge_rule() -> bool { ADD_RULE.get().is_none_or(|r| r != "onset") }
|
||||||
|
|
||||||
impl Rot {
|
impl Rot {
|
||||||
pub fn new(p: &Panel, tau: &[u32; C]) -> Rot {
|
pub fn new(p: &Panel, tau: &[u32; C]) -> Rot {
|
||||||
let nw = p.w();
|
let nw = p.w();
|
||||||
@@ -242,12 +250,37 @@ impl Rot {
|
|||||||
rot[(a * C + c) * nw + w] = r;
|
rot[(a * C + c) * nw + w] = r;
|
||||||
if r { any[a * nw + w] = true; }
|
if r { any[a * nw + w] = true; }
|
||||||
} } }
|
} } }
|
||||||
Rot { nw, tau: *tau, rot, any }
|
let mut adds = vec![false; p.a() * C * nw];
|
||||||
|
let mut adds_any = vec![false; p.a() * nw];
|
||||||
|
let surge = surge_rule();
|
||||||
|
for a in 0..p.a() {
|
||||||
|
for c in 0..C {
|
||||||
|
let on = |w: usize| rot[(a * C + c) * nw + w];
|
||||||
|
let t = tau[c] as f64;
|
||||||
|
for w in GAP..nw {
|
||||||
|
let onset = on(w) && (1..=GAP).all(|k| !on(w - k));
|
||||||
|
let jump = surge && w >= 8 && w + 1 < nw && {
|
||||||
|
let mut b: Vec<f64> = (w - 8..w).map(|k| p.y(a, c, k)).collect();
|
||||||
|
b.sort_by(f64::total_cmp);
|
||||||
|
let base = b[4];
|
||||||
|
let (y0, y1) = (p.y(a, c, w), p.y(a, c, w + 1));
|
||||||
|
y0 >= (0.6 * t).max(base + (0.5 * t).max(0.5 * base)) && y1 >= (0.6 * t).max(base + (0.25 * t).max(0.25 * base))
|
||||||
|
};
|
||||||
|
if (onset || jump) && (1..=GAP).all(|k| !adds[(a * C + c) * nw + w - k]) { adds[(a * C + c) * nw + w] = true; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for w in GAP..nw {
|
||||||
|
let classic = any[a * nw + w] && (1..=GAP).all(|k| !any[a * nw + w - k]);
|
||||||
|
let some = if surge { (0..C).any(|c| adds[(a * C + c) * nw + w]) } else { classic };
|
||||||
|
if some && (1..=GAP).all(|k| !adds_any[a * nw + w - k]) { adds_any[a * nw + w] = true; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rot { nw, tau: *tau, rot, any, adds, adds_any }
|
||||||
}
|
}
|
||||||
pub fn on(&self, a: usize, c: usize, w: usize) -> bool { self.rot[(a * C + c) * self.nw + w] }
|
pub fn on(&self, a: usize, c: usize, w: usize) -> bool { self.rot[(a * C + c) * self.nw + w] }
|
||||||
pub fn any(&self, a: usize, w: usize) -> bool { self.any[a * self.nw + w] }
|
pub fn any(&self, a: usize, w: usize) -> bool { self.any[a * self.nw + w] }
|
||||||
pub fn add(&self, a: usize, c: usize, w: usize) -> bool { w >= GAP && self.on(a, c, w) && (1..=GAP).all(|k| !self.on(a, c, w - k)) }
|
pub fn add(&self, a: usize, c: usize, w: usize) -> bool { w < self.nw && self.adds[(a * C + c) * self.nw + w] }
|
||||||
pub fn add_any(&self, a: usize, w: usize) -> bool { w >= GAP && self.any(a, w) && (1..=GAP).all(|k| !self.any(a, w - k)) }
|
pub fn add_any(&self, a: usize, w: usize) -> bool { w < self.nw && self.adds_any[a * self.nw + w] }
|
||||||
/// An add in weeks t+h+1 ..= t+h+W (all inside the panel).
|
/// An add in weeks t+h+1 ..= t+h+W (all inside the panel).
|
||||||
pub fn add_in_window(&self, a: usize, c: usize, t: usize, h: usize) -> bool { self.add_in(a, c, t, h, W) }
|
pub fn add_in_window(&self, a: usize, c: usize, t: usize, h: usize) -> bool { self.add_in(a, c, t, h, W) }
|
||||||
pub fn add_any_in_window(&self, a: usize, t: usize, h: usize) -> bool { self.add_any_in(a, t, h, W) }
|
pub fn add_any_in_window(&self, a: usize, t: usize, h: usize) -> bool { self.add_any_in(a, t, h, W) }
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
//! airplay model adds [--h 0,4] [--out docs/BACKTEST-ADDS.md] backtest of the new-add model
|
//! airplay model adds [--h 0,4] [--out docs/BACKTEST-ADDS.md] backtest of the new-add model
|
||||||
//! airplay model rank [--h 4] [--max-h 12] [--top 50]
|
//! airplay model rank [--h 4] [--max-h 12] [--top 50]
|
||||||
|
|
||||||
|
pub mod addcheck;
|
||||||
pub mod adds;
|
pub mod adds;
|
||||||
pub mod backtest;
|
pub mod backtest;
|
||||||
pub mod calibrate;
|
pub mod calibrate;
|
||||||
@@ -83,7 +84,12 @@ pub fn run(db: &Db, args: &[String]) -> Result<()> {
|
|||||||
if let Some(out) = arg(args, "--out") { std::fs::write(out, &md)?; }
|
if let Some(out) = arg(args, "--out") { std::fs::write(out, &md)?; }
|
||||||
print!("{md}");
|
print!("{md}");
|
||||||
}
|
}
|
||||||
|
Some("addcheck") => {
|
||||||
|
if let Some(r) = arg(args, "--rule") { let _ = adds::ADD_RULE.set(r); }
|
||||||
|
print!("{}", addcheck::run(db, &p)?);
|
||||||
|
}
|
||||||
Some("events") => {
|
Some("events") => {
|
||||||
|
if let Some(r) = arg(args, "--rule") { let _ = adds::ADD_RULE.set(r); }
|
||||||
let tau = common::thresholds(&p, 26);
|
let tau = common::thresholds(&p, 26);
|
||||||
let mut md = String::new();
|
let mut md = String::new();
|
||||||
let rows = adds::backtest_events(&p, &tau, 26, &mut md)?;
|
let rows = adds::backtest_events(&p, &tau, 26, &mut md)?;
|
||||||
@@ -97,6 +103,7 @@ pub fn run(db: &Db, args: &[String]) -> Result<()> {
|
|||||||
print!("{md}");
|
print!("{md}");
|
||||||
}
|
}
|
||||||
Some("adds") => {
|
Some("adds") => {
|
||||||
|
if let Some(r) = arg(args, "--rule") { let _ = adds::ADD_RULE.set(r); }
|
||||||
if let Some(w) = arg(args, "--without") { let _ = adds::WITHOUT.set(w.split(',').map(str::to_string).collect()); }
|
if let Some(w) = arg(args, "--without") { let _ = adds::WITHOUT.set(w.split(',').map(str::to_string).collect()); }
|
||||||
let horizons: Vec<usize> = arg(args, "--h").unwrap_or_else(|| "0,4".into()).split(',').filter_map(|s| s.trim().parse().ok()).collect();
|
let horizons: Vec<usize> = arg(args, "--h").unwrap_or_else(|| "0,4".into()).split(',').filter_map(|s| s.trim().parse().ok()).collect();
|
||||||
let tau = common::thresholds(&p, 26);
|
let tau = common::thresholds(&p, 26);
|
||||||
|
|||||||
Reference in New Issue
Block a user