aboutsummaryrefslogtreecommitdiff
path: root/src/intuition.rs
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 /src/intuition.rs
parentab2097f633e63a80024ab191c012ab527a04e54b (diff)
add half-life to history weighting
Diffstat (limited to 'src/intuition.rs')
-rw-r--r--src/intuition.rs20
1 files changed, 13 insertions, 7 deletions
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;
}
}
}