aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2026-07-15 12:04:48 +0100
committertslil <tslil@posteo.de>2026-07-15 12:06:45 +0100
commit322271f3d322bc25c30ebe936c7428f1b0df479d (patch)
tree22a7fa3eb7aff47feb034b731db6f12d1a2677e8
parentab2097f633e63a80024ab191c012ab527a04e54b (diff)
add half-life to history weighting
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/config.rs2
-rw-r--r--src/intuition.rs20
4 files changed, 17 insertions, 9 deletions
diff --git a/Cargo.lock b/Cargo.lock
index f5b2350..91b1eb3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -314,7 +314,7 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
[[package]]
name = "mood"
-version = "0.4.0"
+version = "0.5.0"
dependencies = [
"chrono",
"directories",
diff --git a/Cargo.toml b/Cargo.toml
index 2996395..762f2d5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "mood"
-version = "0.4.0"
+version = "0.5.0"
description = "A music player governed by your moods."
edition = "2024"
license = "GPL-3.0-or-later"
diff --git a/src/config.rs b/src/config.rs
index 67721b4..5fdcfe8 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -14,6 +14,7 @@ pub struct Config {
pub mid_weight: f32,
pub high_weight: f32,
pub max_weight: f32,
+ pub lookback_window_halflife_in_entries: u16,
}
fn default_config_path() -> String {
@@ -65,6 +66,7 @@ impl Default for Config {
mid_weight: 0.5,
high_weight: 0.75,
max_weight: 1.0,
+ lookback_window_halflife_in_entries: 128,
}
}
}
diff --git a/src/intuition.rs b/src/intuition.rs
index f994029..46eb92a 100644
--- a/src/intuition.rs
+++ b/src/intuition.rs
@@ -91,6 +91,11 @@ impl Intuition {
candidates: &HashSet<String>,
config: &Config,
) -> Option<(String, f32)> {
+ let decay = f32::powf(
+ 0.5,
+ 1.0 / (config.lookback_window_halflife_in_entries as f32),
+ );
+
let trajectory: HashSet<_> = trajectory.iter().collect();
let candidates: Vec<_> = candidates
@@ -105,16 +110,17 @@ impl Intuition {
let mut items: HashMap<String, f32> =
candidates.into_iter().map(|c| (c.clone(), 0.0)).collect();
- for episode in &self.history {
+ for (dist, episode) in self.history.iter().rev().enumerate() {
+ let kernel = decay.powf(dist as f32);
match (episode, action) {
(Episode::Escape { from, to, .. }, Action::Skip) => {
let w = compute_weight(from, &trajectory);
if let Some(to_w) = items.get_mut(to) {
- *to_w += config.max_weight * w;
+ *to_w += config.max_weight * w * kernel;
}
for f in from {
if let Some(from_weight) = items.get_mut(f) {
- *from_weight -= config.mid_weight * w;
+ *from_weight -= config.mid_weight * w * kernel;
}
}
}
@@ -123,7 +129,7 @@ impl Intuition {
if trajectory.contains(to) {
for f in from {
if let Some(f_w) = items.get_mut(f) {
- *f_w -= config.low_weight * w;
+ *f_w -= config.low_weight * w * kernel;
}
}
}
@@ -132,18 +138,18 @@ impl Intuition {
let w = compute_weight(group, &trajectory);
for g in group {
if let Some(g_w) = items.get_mut(g) {
- *g_w += config.max_weight * w;
+ *g_w += config.max_weight * w * kernel;
}
}
if let Some(a_w) = items.get_mut(avoid) {
- *a_w -= config.low_weight * w;
+ *a_w -= config.low_weight * w * kernel;
}
}
(Episode::Continue { group, .. }, Action::Skip) => {
let w = compute_weight(group, &trajectory);
for g in group {
if let Some(v) = items.get_mut(g) {
- *v -= config.high_weight * w;
+ *v -= config.high_weight * w * kernel;
}
}
}