Skip to content

Commit

Permalink
Include slot machine index in telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed Aug 7, 2023
1 parent f468ed5 commit ba6fb7f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
17 changes: 9 additions & 8 deletions experiments/heuristic-research/src/solver/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub struct SearchResult(pub usize, pub f64, pub (usize, usize), pub usize);

/// Heuristic state result represented as (state idx, alpha, beta, mu, v, n).
#[derive(Default, Serialize, Deserialize)]
pub struct HeuristicResult(pub usize, pub f64, pub f64, pub f64, pub f64, pub usize);
pub struct HeuristicResult(pub usize, pub usize, pub f64, pub f64, pub f64, pub f64, pub usize);

/// Keeps track of dynamic selective hyper heuristic state.
#[derive(Default, Serialize, Deserialize)]
Expand Down Expand Up @@ -189,24 +189,25 @@ impl HyperHeuristicState {

let generation: usize = fields[0].parse().unwrap();
let state = fields[1].clone();
let alpha = fields[2].parse().unwrap();
let beta = fields[3].parse().unwrap();
let mu = fields[4].parse().unwrap();
let v = fields[5].parse().unwrap();
let n = fields[6].parse().unwrap();
let idx = fields[2].parse().unwrap();
let alpha = fields[3].parse().unwrap();
let beta = fields[4].parse().unwrap();
let mu = fields[5].parse().unwrap();
let v = fields[6].parse().unwrap();
let n = fields[7].parse().unwrap();

insert_to_map(&mut states, state.clone());
let state = states.get(&state).copied().unwrap();

data.entry(generation)
.or_insert_with(Vec::default)
.push(HeuristicResult(state, alpha, beta, mu, v, n));
.push(HeuristicResult(state, idx, alpha, beta, mu, v, n));

data
});
heuristic_states
.values_mut()
.for_each(|states| states.sort_by(|HeuristicResult(a, ..), HeuristicResult(b, ..)| a.cmp(b)));
.for_each(|states| states.sort_by(|HeuristicResult(_, a, ..), HeuristicResult(_, b, ..)| a.cmp(b)));

Some(Self { names, states, search_states, heuristic_states })
} else {
Expand Down
19 changes: 12 additions & 7 deletions rosomaxa/src/hyper/dynamic_selective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,14 @@ where
}

self.slot_machines.iter().for_each(|(state, slots)| {
slots.iter().map(|slot| slot.get_params()).for_each(|(alpha, beta, mu, v, n)| {
self.tracker
.observe_params(generation, HeuristicSample { state: state.clone(), alpha, beta, mu, v, n });
})
slots.iter().enumerate().map(|(idx, slot)| (idx, slot.get_params())).for_each(
|(idx, (alpha, beta, mu, v, n))| {
self.tracker.observe_params(
generation,
HeuristicSample { state: state.clone(), idx, alpha, beta, mu, v, n },
);
},
)
});
}
}
Expand All @@ -290,11 +294,11 @@ where
}

f.write_fmt(format_args!("heuristic:\n"))?;
f.write_fmt(format_args!("generation,state,alpha,beta,mu,v,n\n"))?;
f.write_fmt(format_args!("generation,state,idx,alpha,beta,mu,v,n\n"))?;
for (generation, sample) in self.agent.tracker.heuristic_telemetry.iter() {
f.write_fmt(format_args!(
"{},{},{},{},{},{},{}\n",
generation, sample.state, sample.alpha, sample.beta, sample.mu, sample.v, sample.n
"{},{},{},{},{},{},{},{}\n",
generation, sample.state, sample.idx, sample.alpha, sample.beta, sample.mu, sample.v, sample.n
))?;
}

Expand Down Expand Up @@ -437,6 +441,7 @@ struct SearchSample {

struct HeuristicSample {
state: SearchState,
idx: usize,
alpha: f64,
beta: f64,
mu: f64,
Expand Down

0 comments on commit ba6fb7f

Please sign in to comment.