Synthetic lists: top-N rule (N = typical DR list size), 4-week blocks (weekly samples are noise); long-history features (archive presence 2012-21, DR lists before t); NMF analysis on full artist histories
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+22
-6
@@ -52,6 +52,20 @@ pub fn wave_feats(p: &Panel, r: &Rot, a: usize, t: usize) -> [f64; WAVE] {
|
||||
f(known && (13.0..=25.0).contains(&air)), f(ratio_ok), f(known && air >= 104.0)]
|
||||
}
|
||||
|
||||
/// Long-history covariates: DR's 2012–2021 archive and DR's real rotation lists before week t.
|
||||
pub const LONG: usize = 4;
|
||||
pub const LONG_NAMES: &[&str] = &["log archive plays per 100 sampled hours (2012-21)", "log DR lists with the artist before t (2023-)",
|
||||
"DR list recency 26w", "DR lists known before t at all"];
|
||||
|
||||
pub fn long_feats(p: &Panel, a: usize, t: usize) -> [f64; LONG] {
|
||||
if off("long") { return [0.0; LONG]; }
|
||||
let end_t = p.weeks[t] + chrono::Duration::days(6);
|
||||
// A list published on a Friday is known from then.
|
||||
let before: Vec<&chrono::NaiveDate> = p.listed_on[a].iter().filter(|d| **d <= end_t).collect();
|
||||
let since = before.last().map(|d| (end_t - **d).num_days() as f64 / 7.0);
|
||||
[p.archive_rate[a].ln_1p(), (before.len() as f64).ln_1p(), since.map(|s| (-s / 26.0).exp()).unwrap_or(0.0), (!before.is_empty()) as i32 as f64]
|
||||
}
|
||||
|
||||
/// Release covariates (Deezer discography), appended to both row kinds.
|
||||
pub const REL: usize = 6;
|
||||
pub const REL_NAMES: &[&str] = &["discography known", "release recency 4w", "release recency 12w", "log releases last 52w",
|
||||
@@ -88,7 +102,7 @@ pub const EXTRA: &[&str] = &["in rotation on channel now", "in rotation anywhere
|
||||
"run on channel = 1 week", "run = 2 weeks", "run = 3-5 weeks", "run >= 6 weeks",
|
||||
"near threshold (>= half of tau, not in rotation)", "plays / tau (capped 3, /3)",
|
||||
"weeks since in rotation on channel (/12)"];
|
||||
pub const PC: usize = P + 10 + REL + WAVE;
|
||||
pub const PC: usize = P + 10 + REL + WAVE + LONG;
|
||||
|
||||
/// Artist-level ("any channel") rows.
|
||||
pub const ANY_NAMES: &[&str] = &[
|
||||
@@ -98,7 +112,7 @@ pub const ANY_NAMES: &[&str] = &[
|
||||
"log Track Top-40 hits", "log Airplay Top-20 hits", "Danish", "group", "female", "career years (/50)", "debut unknown",
|
||||
"Christmas in window",
|
||||
];
|
||||
pub const PA: usize = 21 + REL + WAVE;
|
||||
pub const PA: usize = 21 + REL + WAVE + LONG;
|
||||
/// Positions of the chart covariates (for the what-if): (t40 score, air score, recency 6w, recency 26w).
|
||||
pub const CHART_IDX_CHANNEL: [usize; 4] = [10, 11, 12, 13];
|
||||
pub const CHART_IDX_ANY: [usize; 4] = [9, 10, 11, 12];
|
||||
@@ -161,7 +175,8 @@ pub fn row_channel(p: &Panel, r: &Rot, a: usize, c: usize, t: usize, h: usize, r
|
||||
f(weeks == 1), f(weeks == 2), f((3..=5).contains(&weeks)), f(weeks >= 6),
|
||||
f(!on && ratio >= 0.5), ratio.min(3.0) / 3.0, since]);
|
||||
out[P + 10..P + 10 + REL].copy_from_slice(&rel_feats(p, a, t, h, rel, on));
|
||||
out[P + 10 + REL..PC].copy_from_slice(&wave_feats(p, r, a, t));
|
||||
out[P + 10 + REL..P + 10 + REL + WAVE].copy_from_slice(&wave_feats(p, r, a, t));
|
||||
out[P + 10 + REL + WAVE..PC].copy_from_slice(&long_feats(p, a, t));
|
||||
}
|
||||
|
||||
pub fn row_any(p: &Panel, r: &Rot, a: usize, t: usize, h: usize, rel: Option<bool>, out: &mut [f64]) {
|
||||
@@ -186,7 +201,8 @@ pub fn row_any(p: &Panel, r: &Rot, a: usize, t: usize, h: usize, rel: Option<boo
|
||||
];
|
||||
out[..21].copy_from_slice(&v);
|
||||
out[21..21 + REL].copy_from_slice(&rel_feats(p, a, t, h, rel, r.any(a, t)));
|
||||
out[21 + REL..PA].copy_from_slice(&wave_feats(p, r, a, t));
|
||||
out[21 + REL..21 + REL + WAVE].copy_from_slice(&wave_feats(p, r, a, t));
|
||||
out[21 + REL + WAVE..PA].copy_from_slice(&long_feats(p, a, t));
|
||||
}
|
||||
|
||||
/// Logit models for one h, trained on origins whose whole window is observed by `last_week`.
|
||||
@@ -416,9 +432,9 @@ pub fn backtest(p: &Panel, tau: &[u32; C], horizons: &[usize], start: usize, md:
|
||||
let m = AddModel::fit(p, &r, 0, p.w() - 1);
|
||||
writeln!(md, "## Coefficients, window starting now (h = 0), all closed windows\n\n| Any-channel feature | Coefficient |\n|---|---|")?;
|
||||
for (n, b) in ANY_NAMES.iter().zip(&m.any) { writeln!(md, "| {n} | {b:+.3} |")?; }
|
||||
for (n, b) in REL_NAMES.iter().chain(WAVE_NAMES).zip(&m.any[21..]) { writeln!(md, "| {n} | {b:+.3} |")?; }
|
||||
for (n, b) in REL_NAMES.iter().chain(WAVE_NAMES).chain(LONG_NAMES).zip(&m.any[21..]) { writeln!(md, "| {n} | {b:+.3} |")?; }
|
||||
writeln!(md, "\n| Per-channel feature | Coefficient |\n|---|---|")?;
|
||||
for (n, b) in features::NAMES.iter().chain(EXTRA).chain(REL_NAMES).chain(WAVE_NAMES).zip(&m.channel) { writeln!(md, "| {n} | {b:+.3} |")?; }
|
||||
for (n, b) in features::NAMES.iter().chain(EXTRA).chain(REL_NAMES).chain(WAVE_NAMES).chain(LONG_NAMES).zip(&m.channel) { writeln!(md, "| {n} | {b:+.3} |")?; }
|
||||
writeln!(md)?;
|
||||
Ok(rows)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user