Release-event model: 'if the artist releases a new song, will DR add it' trained on clean releases (no other release in the 6 weeks before), with its own walk-forward test; ranking defaults to it and leaves out artists who just released; pool note updated
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+19
-13
@@ -35,7 +35,8 @@ pub fn create_tables(db: &Db) -> Result<()> {
|
||||
target TEXT NOT NULL, -- 'rotation' (prob, mean plays) per channel, 'any' across channels;
|
||||
-- 'add' / 'add_any': P(new add in the 8 weeks from target_week), blended
|
||||
-- by the artist's chance of releasing ('p_release'); 'add_rel' /
|
||||
-- 'add_any_rel': the same if the artist releases in the window;
|
||||
-- 'add_any_rel' / 'add_rel': if the artist releases a NEW song (release-event model),
|
||||
-- 'add_any_nmf': ...placed on NMF Denmark; 'recent_release': released in the last 6 weeks;
|
||||
-- 'now': in rotation in the origin week (prob 1/0, mean = plays)
|
||||
key TEXT NOT NULL, -- '{dr artist id}:{channel}' or '{dr artist id}:any'
|
||||
horizon INTEGER NOT NULL, -- weeks after origin_week
|
||||
@@ -113,6 +114,16 @@ pub fn run(db: &Db, p: &Panel, max_h: usize, show_h: usize) -> Result<Vec<Line>>
|
||||
// New adds: windows of W weeks starting h = 0..=max_h weeks after the origin.
|
||||
let tau = thresholds(p, p.w());
|
||||
let rot = Rot::new(p, &tau);
|
||||
// The release-event model ("if they release a new song, will DR add it?"), the same for every
|
||||
// window start: the artist's state now, the new song's NMF placement blended from history.
|
||||
let ev = AddModel::fit_events(p, &rot, p.w() - 1);
|
||||
let t0 = p.w() - 1;
|
||||
let event: Vec<([f64; C], f64, f64, f64, bool)> = (0..p.a()).map(|a| {
|
||||
let q = super::adds::p_nmf(p, a, t0);
|
||||
let (pcn, pan) = ev.predict(p, &rot, a, t0, Scenario::new(true, true), None);
|
||||
let (pcr, par) = ev.predict(p, &rot, a, t0, Scenario::new(true, false), None);
|
||||
(std::array::from_fn(|c| q * pcn[c] + (1.0 - q) * pcr[c]), q * pan + (1.0 - q) * par, pan, q, super::adds::recent_release(p, a, t0))
|
||||
}).collect();
|
||||
for h in 0..=max_h {
|
||||
let m = AddModel::fit(p, &rot, h, p.w() - 1);
|
||||
let start = (origin + Duration::weeks(h as i64 + 1)).to_string();
|
||||
@@ -121,29 +132,24 @@ pub fn run(db: &Db, p: &Panel, max_h: usize, show_h: usize) -> Result<Vec<Line>>
|
||||
let mut ins = tx.prepare("INSERT OR REPLACE INTO forecasts VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)")?;
|
||||
for a in 0..p.a() {
|
||||
let id = &p.artists[a].id;
|
||||
// If they release in the window, if they don't, and blended by their release rate.
|
||||
let t0 = p.w() - 1;
|
||||
// If they release: placed on NMF Denmark or not, weighted by how often the artist's
|
||||
// releases were placed; if they don't release: no NMF placement.
|
||||
let q = super::adds::p_nmf(p, a, t0);
|
||||
let (pcn, pan) = m.predict(p, &rot, a, t0, Scenario::new(true, true), None);
|
||||
let (pcr, par) = m.predict(p, &rot, a, t0, Scenario::new(true, false), None);
|
||||
// Any add in the window (current songs included): no new release, or one at the usual rate.
|
||||
let (pc1, pa1) = m.predict(p, &rot, a, t0, Scenario::new(true, false), None);
|
||||
let (pc0, pa0) = m.predict(p, &rot, a, t0, Scenario::new(false, false), None);
|
||||
let pc1: [f64; C] = std::array::from_fn(|c| q * pcn[c] + (1.0 - q) * pcr[c]);
|
||||
let pa1 = q * pan + (1.0 - q) * par;
|
||||
let pr = super::adds::p_release(p, a, t0);
|
||||
let mix = |p1: f64, p0: f64| match pr { Some(r) => r * p1 + (1.0 - r) * p0, None => p0 };
|
||||
let (ec, ea, ean, q, recent) = event[a];
|
||||
let none = Option::<f64>::None;
|
||||
let mut put = |target: &str, ch: &str, prob: f64| ins.execute(params![made, VERSION, target, format!("{id}:{ch}"), h as i64,
|
||||
origin.to_string(), start, prob, none, none, none]);
|
||||
put("add_any", "any", mix(pa1, pa0))?;
|
||||
put("add_any_rel", "any", pa1)?;
|
||||
put("add_any_nmf", "any", pan)?;
|
||||
put("add_any_rel", "any", ea)?;
|
||||
put("add_any_nmf", "any", ean)?;
|
||||
put("p_nmf", "any", q)?;
|
||||
if recent { put("recent_release", "any", 1.0)?; }
|
||||
if let Some(r) = pr { put("p_release", "any", r)?; }
|
||||
for c in 0..C {
|
||||
put("add", CHANNELS[c], mix(pc1[c], pc0[c]))?;
|
||||
put("add_rel", CHANNELS[c], pc1[c])?;
|
||||
put("add_rel", CHANNELS[c], ec[c])?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user