Wider artist pool (artists credited on DR-played tracks, groups; weekly refresh, oldest first); Platt recalibration of the add model on recent closed windows; Bauer plays per artist on the site

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 03:16:28 +00:00
co-authored by Claude Opus 5.5
parent 33a3c3f2e5
commit 7815ed417c
5 changed files with 130 additions and 18 deletions
+44 -3
View File
@@ -126,15 +126,56 @@ pub struct AddModel {
pub h: usize,
pub channel: Vec<f64>,
pub any: Vec<f64>,
/// Platt recalibration (a, b): p' = sigmoid(a + b * logit(p)); identity when there wasn't
/// enough history to fit it honestly.
pub platt_channel: (f64, f64),
pub platt_any: (f64, f64),
}
/// Recent origins used to fit the recalibration.
const CAL_ORIGINS: usize = 6;
fn logit(p: f64) -> f64 { let p = p.clamp(1e-6, 1.0 - 1e-6); (p / (1.0 - p)).ln() }
fn platt(ab: (f64, f64), p: f64) -> f64 { glm::sigmoid(ab.0 + ab.1 * logit(p)).clamp(1e-6, 1.0 - 1e-6) }
fn origins(h: usize, last_week: usize) -> std::ops::RangeInclusive<usize> {
let hi = last_week.saturating_sub(h + W);
LAGS - 1..=hi
}
impl AddModel {
/// The logits on every window closed by `last_week`, then a recalibration: an inner model fitted
/// on windows closed before the last CAL_ORIGINS origins predicts those origins, and a Platt fit
/// maps its probabilities to what happened. (The raw fits were overconfident above ~0.4.)
pub fn fit(p: &Panel, r: &Rot, h: usize, last_week: usize) -> AddModel {
let mut m = Self::fit_raw(p, r, h, last_week);
let hi = last_week.saturating_sub(h + W);
if hi + 1 >= CAL_ORIGINS + LAGS {
let c0 = hi + 1 - CAL_ORIGINS;
// the inner model may only use windows that closed before the first calibration origin
if c0 >= LAGS - 1 + h + W + 4 {
let inner = Self::fit_raw(p, r, h, c0);
let (mut dc, mut da) = (Design::new(2), Design::new(2));
for t in c0..=hi {
for a in 0..p.a() {
let (pc, pa) = inner.predict(p, r, a, t, None);
for c in 0..C {
if pc[c] < 1e-4 && !r.add_in_window(a, c, t, h) { continue; } // certain zeros carry no information
dc.push(&[1.0, logit(pc[c])], r.add_in_window(a, c, t, h) as i32 as f64, 1.0);
}
da.push(&[1.0, logit(pa)], r.add_any_in_window(a, t, h) as i32 as f64, 1.0);
}
}
let (bc, ba) = (glm::logit(&dc, 0.0), glm::logit(&da, 0.0));
// keep the map monotone and sane
if bc[1] > 0.2 { m.platt_channel = (bc[0], bc[1]); }
if ba[1] > 0.2 { m.platt_any = (ba[0], ba[1]); }
}
}
m
}
fn fit_raw(p: &Panel, r: &Rot, h: usize, last_week: usize) -> AddModel {
let (mut dc, mut da) = (Design::new(PC), Design::new(PA));
let (mut x, mut xa) = (vec![0.0; PC], vec![0.0; PA]);
for t in origins(h, last_week) {
@@ -150,7 +191,7 @@ impl AddModel {
da.push(&xa, r.add_any_in_window(a, t, h) as i32 as f64, 1.0);
}
}
AddModel { h, channel: glm::logit(&dc, 1.0), any: glm::logit(&da, 1.0) }
AddModel { h, channel: glm::logit(&dc, 1.0), any: glm::logit(&da, 1.0), platt_channel: (0.0, 1.0), platt_any: (0.0, 1.0) }
}
/// (P(add) per channel, P(add on any channel)) from origin t.
@@ -160,12 +201,12 @@ impl AddModel {
for c in 0..C {
row_channel(p, r, a, c, t, self.h, &mut x);
if let Some(f) = chart { f(&mut x, CHART_IDX_CHANNEL); }
pc[c] = glm::sigmoid(glm::dot(&self.channel, &x)).clamp(1e-6, 1.0 - 1e-6);
pc[c] = platt(self.platt_channel, glm::sigmoid(glm::dot(&self.channel, &x)));
}
let mut xa = vec![0.0; PA];
row_any(p, r, a, t, self.h, &mut xa);
if let Some(f) = chart { f(&mut xa, CHART_IDX_ANY); }
(pc, glm::sigmoid(glm::dot(&self.any, &xa)).clamp(1e-6, 1.0 - 1e-6))
(pc, platt(self.platt_any, glm::sigmoid(glm::dot(&self.any, &xa))))
}
}