Skip to content

Commit

Permalink
Player stats modelled as Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoutanov committed Dec 1, 2023
1 parent 21190a5 commit 30b0379
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 171 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ harness = false
name = "cri_interval"
harness = false

[[bench]]
name = "cri_isolate"
harness = false

[[bench]]
name = "cri_mc"
harness = false
Expand Down
24 changes: 18 additions & 6 deletions benches/cri_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,35 @@ use brumby::interval;
use brumby::interval::IntervalConfig;

fn criterion_benchmark(c: &mut Criterion) {
fn run(intervals: u8) -> usize {
fn run(intervals: u8, max_total_goals: u16) -> usize {
interval::explore(&IntervalConfig {
intervals,
home_prob: 0.25,
away_prob: 0.25,
common_prob: 0.25,
max_total_goals: u16::MAX,
scorers: vec![],
max_total_goals,
players: vec![],
}).prospects.len()
}

// sanity check
assert_eq!(16, run(3));
assert_eq!(16, run(3, u16::MAX));

c.bench_function("cri_interval_90", |b| {
c.bench_function("cri_interval_18_unbounded", |b| {
b.iter(|| {
run(90)
run(18, u16::MAX)
});
});

c.bench_function("cri_interval_90_unbounded", |b| {
b.iter(|| {
run(90, u16::MAX)
});
});

c.bench_function("cri_interval_90_max_8", |b| {
b.iter(|| {
run(90, 8)
});
});
}
Expand Down
41 changes: 41 additions & 0 deletions benches/cri_isolate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use criterion::{Criterion, criterion_group, criterion_main};
use brumby::entity::{MarketType, OutcomeType, Player, Side};

use brumby::interval::{Exploration, explore, IntervalConfig, isolate};

fn criterion_benchmark(c: &mut Criterion) {
let player = Player::Named(Side::Home, "Markos".into());
fn prepare(intervals: u8, max_total_goals: u16, player: Player) -> Exploration {
explore(&IntervalConfig {
intervals,
home_prob: 0.25,
away_prob: 0.25,
common_prob: 0.25,
max_total_goals,
players: vec![(player, 0.25)],
})
}

// sanity check
let exploration = prepare(18, u16::MAX,player.clone());
// println!("prospects: {}", exploration.prospects.len());
let isolated = isolate(&MarketType::AnytimeGoalscorer, &OutcomeType::Player(player.clone()), &exploration.prospects, &exploration.player_lookup);
assert!(isolated > 0.0);

c.bench_function("cri_isolate_first_goalscorer_18_unbounded", |b| {
let exploration = prepare(18, u16::MAX, player.clone());
b.iter(|| {
isolate(&MarketType::AnytimeGoalscorer, &OutcomeType::Player(player.clone()), &exploration.prospects, &exploration.player_lookup)
});
});

c.bench_function("cri_isolate_first_goalscorer_90_max_8", |b| {
let exploration = prepare(90, 8, player.clone());
b.iter(|| {
isolate(&MarketType::AnytimeGoalscorer, &OutcomeType::Player(player.clone()), &exploration.prospects, &exploration.player_lookup)
});
});
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
12 changes: 6 additions & 6 deletions src/bin/soccer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ pub fn main() {
away_prob: search_outcome.optimal_values[1],
common_prob: search_outcome.optimal_values[2],
max_total_goals: MAX_TOTAL_GOALS,
scorers: vec![(player.clone(), *prob)],
players: vec![(player.clone(), *prob)],
});
let isolated_prob = isolate(&MarketType::FirstGoalscorer, &OutcomeType::Player(player.clone()), &exploration.prospects);
let isolated_prob = isolate(&MarketType::FirstGoalscorer, &OutcomeType::Player(player.clone()), &exploration.prospects, &exploration.player_lookup);
fitted_first_goalscorer_probs.push(isolated_prob);
// println!("first scorer {player:?}, prob: {isolated_prob:.3}");
}
Expand All @@ -324,9 +324,9 @@ pub fn main() {
away_prob: search_outcome.optimal_values[1],
common_prob: search_outcome.optimal_values[2],
max_total_goals: MAX_TOTAL_GOALS,
scorers: vec![(player.clone(), *prob)],
players: vec![(player.clone(), *prob)],
});
let isolated_prob = isolate(&MarketType::AnytimeGoalscorer, &OutcomeType::Player(player.clone()), &exploration.prospects);
let isolated_prob = isolate(&MarketType::AnytimeGoalscorer, &OutcomeType::Player(player.clone()), &exploration.prospects, &exploration.player_lookup);
fitted_anytime_goalscorer_probs.push(isolated_prob);
// println!("anytime scorer {player:?}, prob: {isolated_prob:.3}");
}
Expand Down Expand Up @@ -475,9 +475,9 @@ fn fit_first_goalscorer(optimal_scoring_probs: &[f64], player: &Player, expected
away_prob: optimal_scoring_probs[1],
common_prob: optimal_scoring_probs[2],
max_total_goals: MAX_TOTAL_GOALS,
scorers: vec![(player.clone(), values[0])],
players: vec![(player.clone(), values[0])],
});
let isolated_prob = isolate(&MarketType::FirstGoalscorer, &OutcomeType::Player(player.clone()), &exploration.prospects);
let isolated_prob = isolate(&MarketType::FirstGoalscorer, &OutcomeType::Player(player.clone()), &exploration.prospects, &exploration.player_lookup);
((isolated_prob - expected_prob)/expected_prob).powi(2)
},
)
Expand Down
Loading

0 comments on commit 30b0379

Please sign in to comment.