aboutsummaryrefslogtreecommitdiff
path: root/src/learner.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/learner.rs')
-rw-r--r--src/learner.rs36
1 files changed, 3 insertions, 33 deletions
diff --git a/src/learner.rs b/src/learner.rs
index 59db567..942d52e 100644
--- a/src/learner.rs
+++ b/src/learner.rs
@@ -53,30 +53,6 @@ enum Episode {
},
}
-impl Episode {
- fn prune_mut(&mut self, valid: &HashSet<String>) -> bool {
- match self {
- Episode::Continue { group, avoid, .. } => {
- if let Some(a) = avoid
- && valid.contains(a)
- {
- } else {
- *avoid = None;
- };
- group.retain(|g| valid.contains(g));
- !group.is_empty()
- }
- Episode::Escape { from, to, .. } => {
- if !valid.contains(to) {
- return false;
- };
- from.retain(|f| valid.contains(f));
- !from.is_empty()
- }
- }
- }
-}
-
#[derive(Serialize, Deserialize, Default)]
pub struct Learner {
history: Vec<Episode>,
@@ -88,14 +64,8 @@ pub enum Learning {
}
impl Learner {
- pub fn prune(&mut self, valid: &HashSet<String>) {
- self.history.retain_mut(|e| e.prune_mut(valid));
- }
-}
-
-impl Learner {
pub fn learn(&mut self, learning: &Learning) {
- let stamp = chrono::Utc::now().format("U%Y%m%d-%H%M%S").to_string();
+ let stamp = chrono::Utc::now().format("%+").to_string();
match learning {
Learning::SkipToMore(trajectory, new) => {
self.history.push(Episode::Escape {
@@ -111,7 +81,7 @@ impl Learner {
committed: stamp,
});
}
- };
+ }
}
pub fn sample(
@@ -135,7 +105,7 @@ impl Learner {
let mut items: HashMap<String, f32> =
candidates.into_iter().map(|c| (c.clone(), 0.0)).collect();
- for episode in self.history.iter() {
+ for episode in &self.history {
match (episode, action) {
(Episode::Escape { from, to, .. }, Action::Skip) => {
let w = compute_weight(from, &trajectory);