diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.rs | 2 | ||||
| -rw-r--r-- | src/intuition.rs | 20 |
2 files changed, 15 insertions, 7 deletions
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; } } } |
