Channel affinity (share of the artist's DR plays per station before t, never played there) and genre fit (DR genre x station) in the per-station rows; Best week: any date range up to 12 months
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+25
-4
@@ -153,6 +153,26 @@ pub fn season_feat(p: &Panel, t: usize, h: usize, win: usize) -> [f64; SEASON] {
|
||||
[v]
|
||||
}
|
||||
|
||||
/// Channel affinity and genre fit (per-channel rows only): the share of the artist's DR plays that
|
||||
/// were on this station group (all-time top tracks, minus panel plays after week t), the log of
|
||||
/// those plays, "never played here", and how much DR plays the artist's genre on this group.
|
||||
pub const AFF: usize = 4;
|
||||
pub const AFF_NAMES: &[&str] = &["share of the artist's DR plays on this station (before t)", "log DR plays on this station (before t)",
|
||||
"never played on this station (before t)", "genre fit for this station"];
|
||||
pub fn aff_feats(p: &Panel, a: usize, c: usize, t: usize) -> [f64; AFF] {
|
||||
if off("aff") { return [0.0; AFF]; }
|
||||
// Plays after week t (the future, as seen from t) taken out of the all-time counts.
|
||||
let after = |g: usize| -> f64 {
|
||||
let cs: Vec<usize> = (0..C).filter(|&k| group(k) == g).collect();
|
||||
let n = cs.len() as f64;
|
||||
(t + 1..p.w()).map(|w| cs.iter().map(|&k| p.y(a, k, w)).sum::<f64>() / n).sum()
|
||||
};
|
||||
let before: [f64; GROUPS] = std::array::from_fn(|g| (p.alltime[a][g] - after(g)).max(0.0));
|
||||
let tot: f64 = before.iter().sum();
|
||||
let g = group(c);
|
||||
[if tot > 0.0 { before[g] / tot } else { 0.0 }, before[g].ln_1p(), (before[g] == 0.0) as i32 as f64, p.genre_fit[a][g]]
|
||||
}
|
||||
|
||||
/// 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",
|
||||
@@ -190,7 +210,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 + LONG + NMF + SEASON;
|
||||
pub const PC: usize = P + 10 + REL + WAVE + LONG + NMF + SEASON + AFF;
|
||||
|
||||
/// Artist-level ("any channel") rows.
|
||||
pub const ANY_NAMES: &[&str] = &[
|
||||
@@ -267,8 +287,9 @@ pub fn row_channel(p: &Panel, r: &Rot, a: usize, c: usize, t: usize, h: usize, s
|
||||
out[P + 10..P + 10 + REL].copy_from_slice(&rel_feats(p, a, t, h, sc, on));
|
||||
out[P + 10 + REL..P + 10 + REL + WAVE].copy_from_slice(&wave_feats(p, r, a, t, sc.shift));
|
||||
out[P + 10 + REL + WAVE..P + 10 + REL + WAVE + LONG].copy_from_slice(&long_feats(p, a, t, sc.shift));
|
||||
out[P + 10 + REL + WAVE + LONG..PC - SEASON].copy_from_slice(&nmf_feats(p, a, t, h, sc));
|
||||
out[PC - SEASON..PC].copy_from_slice(&season_feat(p, t, h, sc.win));
|
||||
out[P + 10 + REL + WAVE + LONG..PC - SEASON - AFF].copy_from_slice(&nmf_feats(p, a, t, h, sc));
|
||||
out[PC - SEASON - AFF..PC - AFF].copy_from_slice(&season_feat(p, t, h, sc.win));
|
||||
out[PC - AFF..PC].copy_from_slice(&aff_feats(p, a, c, t));
|
||||
}
|
||||
|
||||
pub fn row_any(p: &Panel, r: &Rot, a: usize, t: usize, h: usize, sc: Scenario, out: &mut [f64]) {
|
||||
@@ -551,7 +572,7 @@ pub fn backtest(p: &Panel, tau: &[u32; C], horizons: &[usize], start: usize, md:
|
||||
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).chain(LONG_NAMES).chain(NMF_NAMES).chain(SEASON_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).chain(LONG_NAMES).chain(NMF_NAMES).chain(SEASON_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).chain(NMF_NAMES).chain(SEASON_NAMES).chain(AFF_NAMES).zip(&m.channel) { writeln!(md, "| {n} | {b:+.3} |")?; }
|
||||
writeln!(md)?;
|
||||
Ok(rows)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user