Refactor some code
This commit is contained in:
@@ -6,9 +6,10 @@ pub struct History {
|
||||
size: usize,
|
||||
batches: Vec<Batch>,
|
||||
agents: HashMap<PlayerIndex, Agent>,
|
||||
mu: f64,
|
||||
sigma: f64,
|
||||
gamma: f64,
|
||||
// mu: f64,
|
||||
// sigma: f64,
|
||||
// beta: f64,
|
||||
// gamma: f64,
|
||||
p_draw: f64,
|
||||
time: bool,
|
||||
pub epsilon: f64,
|
||||
@@ -18,9 +19,9 @@ pub struct History {
|
||||
|
||||
impl History {
|
||||
pub fn new(
|
||||
composition: Vec<Vec<Vec<PlayerIndex>>>,
|
||||
results: Vec<Vec<u16>>,
|
||||
times: Vec<f64>,
|
||||
composition: &[Vec<Vec<PlayerIndex>>],
|
||||
results: &[Vec<u16>],
|
||||
times: &[f64],
|
||||
priors: HashMap<PlayerIndex, Player>,
|
||||
mu: f64,
|
||||
sigma: f64,
|
||||
@@ -57,9 +58,6 @@ impl History {
|
||||
size: composition.len(),
|
||||
batches: Vec::new(),
|
||||
agents,
|
||||
mu,
|
||||
sigma,
|
||||
gamma,
|
||||
p_draw,
|
||||
time: !times.is_empty(),
|
||||
epsilon: 1e-6,
|
||||
@@ -74,12 +72,12 @@ impl History {
|
||||
|
||||
fn trueskill(
|
||||
&mut self,
|
||||
composition: Vec<Vec<Vec<PlayerIndex>>>,
|
||||
results: Vec<Vec<u16>>,
|
||||
times: Vec<f64>,
|
||||
composition: &[Vec<Vec<PlayerIndex>>],
|
||||
results: &[Vec<u16>],
|
||||
times: &[f64],
|
||||
) {
|
||||
let o = if self.time {
|
||||
utils::sort_time(×, false)
|
||||
utils::sort_time(times)
|
||||
} else {
|
||||
(0..composition.len()).collect::<Vec<_>>()
|
||||
};
|
||||
@@ -88,13 +86,13 @@ impl History {
|
||||
|
||||
while i < self.size {
|
||||
let mut j = i + 1;
|
||||
let t = if self.time {
|
||||
let time = if self.time {
|
||||
times[o[i]]
|
||||
} else {
|
||||
i as f64 + 1.0
|
||||
};
|
||||
|
||||
while self.time && j < self.size && times[o[j]] == t {
|
||||
while self.time && j < self.size && times[o[j]] == time {
|
||||
j += 1;
|
||||
}
|
||||
|
||||
@@ -104,20 +102,17 @@ impl History {
|
||||
|
||||
let results = (i..j).map(|e| results[o[e]].clone()).collect::<Vec<_>>();
|
||||
|
||||
let b = Batch::new(
|
||||
composition,
|
||||
results,
|
||||
t as f64,
|
||||
&mut self.agents,
|
||||
self.p_draw,
|
||||
);
|
||||
let b = Batch::new(composition, results, time, &mut self.agents, self.p_draw);
|
||||
|
||||
self.batches.push(b.clone());
|
||||
self.batches.push(b);
|
||||
|
||||
let idx = self.batches.len() - 1;
|
||||
let b = &mut self.batches[idx];
|
||||
|
||||
for a in b.skills.keys() {
|
||||
let agent = self.agents.get_mut(a).unwrap();
|
||||
|
||||
agent.last_time = if self.time { t as f64 } else { f64::INFINITY };
|
||||
agent.last_time = if self.time { time } else { f64::INFINITY };
|
||||
agent.message = b.forward_prior_out(a);
|
||||
}
|
||||
|
||||
@@ -285,9 +280,9 @@ mod tests {
|
||||
}
|
||||
|
||||
let mut h = History::new(
|
||||
composition,
|
||||
results,
|
||||
vec![1.0, 2.0, 3.0],
|
||||
&composition,
|
||||
&results,
|
||||
&[1.0, 2.0, 3.0],
|
||||
priors,
|
||||
MU,
|
||||
BETA,
|
||||
@@ -348,9 +343,9 @@ mod tests {
|
||||
}
|
||||
|
||||
let mut h1 = History::new(
|
||||
composition,
|
||||
results,
|
||||
times,
|
||||
&composition,
|
||||
&results,
|
||||
×,
|
||||
priors,
|
||||
MU,
|
||||
BETA,
|
||||
@@ -425,9 +420,9 @@ mod tests {
|
||||
}
|
||||
|
||||
let mut h2 = History::new(
|
||||
composition,
|
||||
results,
|
||||
times,
|
||||
&composition,
|
||||
&results,
|
||||
×,
|
||||
priors,
|
||||
MU,
|
||||
BETA,
|
||||
@@ -509,9 +504,9 @@ mod tests {
|
||||
}
|
||||
|
||||
let mut h = History::new(
|
||||
composition,
|
||||
results,
|
||||
times,
|
||||
&composition,
|
||||
&results,
|
||||
×,
|
||||
priors,
|
||||
MU,
|
||||
BETA,
|
||||
@@ -566,9 +561,9 @@ mod tests {
|
||||
let results = vec![vec![1, 0], vec![0, 1], vec![1, 0]];
|
||||
|
||||
let mut h = History::new(
|
||||
composition,
|
||||
results,
|
||||
Vec::new(),
|
||||
&composition,
|
||||
&results,
|
||||
&[],
|
||||
HashMap::new(),
|
||||
25.0,
|
||||
25.0 / 3.0,
|
||||
|
||||
Reference in New Issue
Block a user