Knowable pool (artists enter only from their first release/play/chart/list/NMF), pooled out-of-sample recalibration (Platt vs isotonic; the site uses pooled Platt per channel, isotonic any channel), release-timing baseline, 8-week bootstrap blocks, surge-rule precision/recall vs the lists with a constant grid (docs/ADDCHECK.md); backtests restructured to score all variants with calibration tables

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 00:34:30 +00:00
co-authored by Claude Opus 5.5
parent 94abfa0255
commit 37b3029e02
12 changed files with 767 additions and 339 deletions
+40 -1
View File
@@ -89,6 +89,9 @@ pub struct Panel {
/// How much DR plays the artist's genre on each station group, relative to all music: ln of
/// (genre's share of plays on the group / the group's share of all plays); 0 = genre unknown.
pub genre_fit: Vec<[f64; GROUPS]>,
/// The first week (index) at which the artist was knowable: their first release, DR play,
/// chart entry, DR list, archived play or NMF placement (0 = before the panel; w() = never).
pub first_known: Vec<usize>,
/// Season index per ISO week (1..=53): new songs reaching the Airplay Top-20 that week of the
/// year, relative to an average week, 2002–2024 (before the DR panel), smoothed over 5 weeks.
pub season: [f64; 54],
@@ -102,6 +105,10 @@ impl Panel {
#[inline]
pub fn chart(&self, a: usize, w: usize) -> Chart { self.chart[a * self.weeks.len() + w] }
/// Was the artist knowable by the end of week t (so a forecast made then could include them)?
#[inline]
pub fn known(&self, a: usize, t: usize) -> bool { self.first_known[a] <= t }
/// The panel as it was known at the end of week t: plays after t removed (and taken out of the
/// all-time counts), releases, NMF placements and lists after t dropped. For the leak test.
pub fn truncated(&self, t: usize) -> Panel {
@@ -180,7 +187,9 @@ impl Panel {
let nmf_dk = load_nmf_dk(db, &id_of, &artists)?;
let season = load_season(db)?;
let (alltime, genre_fit) = load_affinity(db, &id_of, artists.len())?;
Ok(Panel { weeks, artists, y, chart, list_tau, releases, archive_rate, listed_on, nmf_dk, season, alltime, genre_fit })
let mut p = Panel { weeks, artists, y, chart, list_tau, releases, archive_rate, listed_on, nmf_dk, season, alltime, genre_fit, first_known: Vec::new() };
p.first_known = first_known(db, &p, &id_of)?;
Ok(p)
}
}
@@ -427,3 +436,33 @@ fn load_affinity(db: &Db, id_of: &HashMap<String, usize>, n: usize) -> Result<(V
}
Ok((alltime, fit))
}
/// First knowable week per artist (see Panel::first_known).
fn first_known(db: &Db, p: &Panel, id_of: &HashMap<String, usize>) -> Result<Vec<usize>> {
let nw = p.w();
let week_of_date = |d: NaiveDate| -> usize {
if d < p.weeks[0] { 0 } else { (((d - p.weeks[0]).num_days() / 7) as usize).min(nw) }
};
let mut first = vec![nw; p.a()];
let mut old: HashMap<usize, NaiveDate> = HashMap::new();
let exists: i64 = db.conn.query_row("SELECT count(*) FROM sqlite_master WHERE name = 'dr_artist_history'", [], |r| r.get(0))?;
if exists > 0 {
for r in db.conn.prepare("SELECT artist_id, min(week_start) FROM dr_artist_history WHERE plays > 0 GROUP BY artist_id")?
.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?)))? {
let (id, d) = r?;
if let (Some(&a), Ok(d)) = (id_of.get(&id), NaiveDate::parse_from_str(&d, "%Y-%m-%d")) { old.insert(a, d); }
}
}
for a in 0..p.a() {
let mut f = nw;
if let Some(d) = p.releases[a].as_ref().and_then(|v| v.first()) { f = f.min(week_of_date(*d)); }
if let Some(w) = (0..nw).find(|&w| (0..C).any(|c| p.y(a, c, w) > 0.0)) { f = f.min(w); }
if let Some(w) = (0..nw).find(|&w| { let c = p.chart(a, w); c.t40_hits > 0 || c.air_hits > 0 }) { f = f.min(w); }
if let Some(d) = p.listed_on[a].first() { f = f.min(week_of_date(*d)); }
if let Some((d, _)) = p.nmf_dk[a].first() { f = f.min(week_of_date(*d)); }
if p.archive_rate[a] > 0.0 { f = 0; }
if let Some(d) = old.get(&a) { f = f.min(week_of_date(*d)); }
first[a] = f;
}
Ok(first)
}