Refactor some code

This commit is contained in:
2022-06-15 11:27:24 +02:00
parent 811a4ca418
commit 0a3327f076
5 changed files with 54 additions and 59 deletions

View File

@@ -37,6 +37,7 @@ impl Agent {
}
}
#[inline]
pub fn receive(&self, elapsed: f64) -> Gaussian {
if self.message != N_INF {
self.message.forget(self.player.gamma, elapsed)
@@ -191,12 +192,14 @@ impl Batch {
self.iteration(from, agents);
}
#[inline]
pub fn posterior(&self, agent: &PlayerIndex) -> Gaussian {
let skill = &self.skills[agent];
skill.likelihood * skill.backward * skill.forward
}
#[inline]
pub fn posteriors(&self) -> HashMap<PlayerIndex, Gaussian> {
self.skills
.keys()
@@ -204,6 +207,7 @@ impl Batch {
.collect::<HashMap<_, _>>()
}
#[inline]
fn within_prior(&self, item: &Item, agents: &mut HashMap<PlayerIndex, Agent>) -> Player {
let r = &agents[&item.index].player;
let g = self.posterior(&item.index) / item.likelihood;
@@ -278,12 +282,14 @@ impl Batch {
i
}
#[inline]
pub fn forward_prior_out(&self, agent: &PlayerIndex) -> Gaussian {
let skill = &self.skills[agent];
skill.forward * skill.likelihood
}
#[inline]
pub fn backward_prior_out(
&self,
agent: &PlayerIndex,
@@ -295,6 +301,7 @@ impl Batch {
n.forget(agents[agent].player.gamma, skill.elapsed)
}
#[inline]
pub fn new_backward_info(&mut self, agents: &mut HashMap<PlayerIndex, Agent>) {
for (agent, skill) in self.skills.iter_mut() {
skill.backward = agents[agent].message;
@@ -303,6 +310,7 @@ impl Batch {
self.iteration(0, agents);
}
#[inline]
pub fn new_forward_info(&mut self, agents: &mut HashMap<PlayerIndex, Agent>) {
for (agent, skill) in self.skills.iter_mut() {
skill.forward = agents[agent].receive(skill.elapsed);