Change time to use i64 instead of u64
This commit is contained in:
@@ -4,11 +4,11 @@ use crate::{gaussian::Gaussian, player::Player, N_INF};
|
||||
pub(crate) struct Agent {
|
||||
pub(crate) player: Player,
|
||||
pub(crate) message: Gaussian,
|
||||
pub(crate) last_time: u64,
|
||||
pub(crate) last_time: i64,
|
||||
}
|
||||
|
||||
impl Agent {
|
||||
pub(crate) fn receive(&self, elapsed: u64) -> Gaussian {
|
||||
pub(crate) fn receive(&self, elapsed: i64) -> Gaussian {
|
||||
if self.message != N_INF {
|
||||
self.message.forget(self.player.gamma, elapsed)
|
||||
} else {
|
||||
@@ -22,7 +22,7 @@ impl Default for Agent {
|
||||
Self {
|
||||
player: Player::default(),
|
||||
message: N_INF,
|
||||
last_time: u64::MIN,
|
||||
last_time: i64::MIN,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ pub(crate) fn clean<'a, A: Iterator<Item = &'a mut Agent>>(agents: A, last_time:
|
||||
a.message = N_INF;
|
||||
|
||||
if last_time {
|
||||
a.last_time = 0;
|
||||
a.last_time = i64::MIN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
src/batch.rs
12
src/batch.rs
@@ -9,7 +9,7 @@ pub(crate) struct Skill {
|
||||
pub(crate) forward: Gaussian,
|
||||
backward: Gaussian,
|
||||
likelihood: Gaussian,
|
||||
pub(crate) elapsed: u64,
|
||||
pub(crate) elapsed: i64,
|
||||
pub(crate) online: Gaussian,
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ impl Event {
|
||||
pub struct Batch {
|
||||
pub(crate) events: Vec<Event>,
|
||||
pub(crate) skills: HashMap<Index, Skill>,
|
||||
pub(crate) time: u64,
|
||||
pub(crate) time: i64,
|
||||
p_draw: f64,
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ impl Batch {
|
||||
composition: Vec<Vec<Vec<Index>>>,
|
||||
results: Vec<Vec<f64>>,
|
||||
weights: Vec<Vec<Vec<f64>>>,
|
||||
time: u64,
|
||||
time: i64,
|
||||
p_draw: f64,
|
||||
agents: &mut HashMap<Index, Agent>,
|
||||
) -> Self {
|
||||
@@ -444,10 +444,10 @@ impl Batch {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn compute_elapsed(last_time: u64, actual_time: u64) -> u64 {
|
||||
if last_time == u64::MIN {
|
||||
pub(crate) fn compute_elapsed(last_time: i64, actual_time: i64) -> i64 {
|
||||
if last_time == i64::MIN {
|
||||
0
|
||||
} else if last_time == u64::MAX {
|
||||
} else if last_time == i64::MAX {
|
||||
1
|
||||
} else {
|
||||
actual_time - last_time
|
||||
|
||||
@@ -42,7 +42,7 @@ impl Gaussian {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn forget(&self, gamma: f64, t: u64) -> Self {
|
||||
pub(crate) fn forget(&self, gamma: f64, t: i64) -> Self {
|
||||
Self {
|
||||
mu: self.mu,
|
||||
sigma: (self.sigma.powi(2) + t as f64 * gamma.powi(2)).sqrt(),
|
||||
|
||||
@@ -206,8 +206,8 @@ impl History {
|
||||
(step, i)
|
||||
}
|
||||
|
||||
pub fn learning_curves(&self) -> HashMap<Index, Vec<(u64, Gaussian)>> {
|
||||
let mut data: HashMap<Index, Vec<(u64, Gaussian)>> = HashMap::new();
|
||||
pub fn learning_curves(&self) -> HashMap<Index, Vec<(i64, Gaussian)>> {
|
||||
let mut data: HashMap<Index, Vec<(i64, Gaussian)>> = HashMap::new();
|
||||
|
||||
for b in &self.batches {
|
||||
for agent in b.skills.keys() {
|
||||
@@ -235,7 +235,7 @@ impl History {
|
||||
&mut self,
|
||||
composition: Vec<Vec<Vec<Index>>>,
|
||||
results: Vec<Vec<f64>>,
|
||||
times: Vec<u64>,
|
||||
times: Vec<i64>,
|
||||
weights: Vec<Vec<Vec<f64>>>,
|
||||
) {
|
||||
self.add_events_with_prior(composition, results, times, weights, HashMap::new())
|
||||
@@ -245,7 +245,7 @@ impl History {
|
||||
&mut self,
|
||||
composition: Vec<Vec<Vec<Index>>>,
|
||||
results: Vec<Vec<f64>>,
|
||||
times: Vec<u64>,
|
||||
times: Vec<i64>,
|
||||
weights: Vec<Vec<Vec<f64>>>,
|
||||
priors: HashMap<Index, Player>,
|
||||
) {
|
||||
@@ -302,7 +302,7 @@ impl History {
|
||||
|
||||
while i < n {
|
||||
let mut j = i + 1;
|
||||
let t = if self.time { times[o[i]] } else { i as u64 + 1 };
|
||||
let t = if self.time { times[o[i]] } else { i as i64 + 1 };
|
||||
|
||||
while self.time && j < n && times[o[j]] == t {
|
||||
j += 1;
|
||||
@@ -329,7 +329,7 @@ impl History {
|
||||
|
||||
let a = self.agents.get_mut(agent).unwrap();
|
||||
|
||||
a.last_time = if self.time { b.time } else { u64::MAX };
|
||||
a.last_time = if self.time { b.time } else { i64::MAX };
|
||||
a.message = b.forward_prior_out(agent);
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ impl History {
|
||||
for a in b.skills.keys() {
|
||||
let agent = self.agents.get_mut(a).unwrap();
|
||||
|
||||
agent.last_time = if self.time { t } else { u64::MAX };
|
||||
agent.last_time = if self.time { t } else { i64::MAX };
|
||||
agent.message = b.forward_prior_out(a);
|
||||
}
|
||||
} else {
|
||||
@@ -379,7 +379,7 @@ impl History {
|
||||
for a in b.skills.keys() {
|
||||
let agent = self.agents.get_mut(a).unwrap();
|
||||
|
||||
agent.last_time = if self.time { t } else { u64::MAX };
|
||||
agent.last_time = if self.time { t } else { i64::MAX };
|
||||
agent.message = b.forward_prior_out(a);
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ impl History {
|
||||
|
||||
let a = self.agents.get_mut(agent).unwrap();
|
||||
|
||||
a.last_time = if self.time { b.time } else { u64::MAX };
|
||||
a.last_time = if self.time { b.time } else { i64::MAX };
|
||||
a.message = b.forward_prior_out(agent);
|
||||
}
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ pub(crate) fn sort_perm(x: &[f64], reverse: bool) -> Vec<usize> {
|
||||
v.into_iter().map(|(i, _)| i).collect()
|
||||
}
|
||||
|
||||
pub(crate) fn sort_time(xs: &[u64], reverse: bool) -> Vec<usize> {
|
||||
pub(crate) fn sort_time(xs: &[i64], reverse: bool) -> Vec<usize> {
|
||||
let mut x = xs.iter().enumerate().collect::<Vec<_>>();
|
||||
|
||||
if reverse {
|
||||
|
||||
Reference in New Issue
Block a user