Working on History struct. First test is passing.

This commit is contained in:
2022-06-12 23:11:13 +02:00
parent 5a7053fb5d
commit 4227617513
6 changed files with 241 additions and 18 deletions

View File

@@ -2,6 +2,7 @@ use std::collections::{HashMap, HashSet};
use crate::{Game, Gaussian, Player, N_INF};
#[derive(Clone)]
pub struct Skill {
pub forward: Gaussian,
pub backward: Gaussian,
@@ -20,6 +21,7 @@ impl Default for Skill {
}
}
#[derive(Clone, Copy, Debug)]
pub struct Agent {
pub player: Player,
pub message: Gaussian,
@@ -44,16 +46,19 @@ impl Agent {
}
}
#[derive(Clone)]
pub struct Item {
name: String,
likelihood: Gaussian,
}
#[derive(Clone)]
pub struct Team {
items: Vec<Item>,
output: u16,
}
#[derive(Clone)]
pub struct Event {
teams: Vec<Team>,
evidence: f64,
@@ -86,8 +91,9 @@ fn compute_elapsed(last_time: f64, actual_time: f64) -> f64 {
}
}
#[derive(Clone)]
pub struct Batch {
skills: HashMap<String, Skill>,
pub skills: HashMap<String, Skill>,
events: Vec<Event>,
time: f64,
agents: HashMap<String, Agent>,
@@ -170,7 +176,7 @@ impl Batch {
self.iteration(from);
}
fn posterior(&self, agent: &str) -> Gaussian {
pub fn posterior(&self, agent: &str) -> Gaussian {
let skill = &self.skills[agent];
skill.likelihood * skill.backward * skill.forward
@@ -190,7 +196,7 @@ impl Batch {
Player::new(g, r.beta, r.gamma, N_INF)
}
fn within_priors(&self, event: usize) -> Vec<Vec<Player>> {
pub fn within_priors(&self, event: usize) -> Vec<Vec<Player>> {
self.events[event]
.teams
.iter()
@@ -262,8 +268,15 @@ impl Batch {
step = dict_diff(old, self.posteriors())
i += 1
return i
def forward_prior_out(self, agent):
return self.skills[agent].forward * self.skills[agent].likelihood
*/
pub fn forward_prior_out(&self, agent: &str) -> Gaussian {
let skill = &self.skills[agent];
skill.forward * skill.likelihood
}
/*
def backward_prior_out(self, agent):
N = self.skills[agent].likelihood*self.skills[agent].backward
return N.forget(self.agents[agent].player.gamma, self.skills[agent].elapsed)