Skip to content

Commit

Permalink
Use of StackVec in player_probs
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoutanov committed Dec 26, 2023
1 parent 3ac3e64 commit 4e8cf3b
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exclude = ["/images", "/bin", "/.idea", "/.github", "/coverage", "/doc", "/examp

[workspace.dependencies]
anyhow = "1.0.75"
bincode = "2.0.0-rc.3"
chrono = "0.4.31"
clap = { version = "4.4.6", features = ["derive"] }
racing_scraper = "0.0.18"
Expand All @@ -32,7 +33,6 @@ strum = "0.25.0"
strum_macros = "0.25.3"
serde = { version = "1.0.189", features = ["derive"] }
serde_json = "1.0.107"
bincode = "2.0.0-rc.3"
stanza = "0.5.1"
thiserror = "1.0.50"
rustc-hash = "1.1.0"
Expand Down
3 changes: 2 additions & 1 deletion brumby-soccer/benches/cri_interval.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use criterion::{criterion_group, criterion_main, Criterion};
use brumby::sv;

use brumby_soccer::interval;
use brumby_soccer::interval::{Config, PruneThresholds, BivariateProbs, TeamProbs, UnivariateProbs};
Expand All @@ -13,7 +14,7 @@ fn criterion_benchmark(c: &mut Criterion) {
h2_goals: BivariateProbs { home: 0.25, away: 0.25, common: 0.25 },
assists: UnivariateProbs { home: 1.0, away: 1.0 },
},
player_probs: vec![],
player_probs: sv![],
prune_thresholds: PruneThresholds {
max_total_goals,
min_prob: 1e-6,
Expand Down
3 changes: 2 additions & 1 deletion brumby-soccer/benches/cri_isolate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use brumby_soccer::domain::{OfferType, OutcomeType, Player, Side};
use criterion::{criterion_group, criterion_main, Criterion};
use brumby::sv;

use brumby_soccer::interval::{explore, Exploration, Config, BivariateProbs, PruneThresholds, PlayerProbs, TeamProbs, UnivariateProbs};
use brumby_soccer::interval::query::isolate;
Expand All @@ -15,7 +16,7 @@ fn criterion_benchmark(c: &mut Criterion) {
h2_goals: BivariateProbs { home: 0.25, away: 0.25, common: 0.25 },
assists: UnivariateProbs { home: 1.0, away: 1.0 },
},
player_probs: vec![(player, PlayerProbs { goal: Some(0.25), assist: None })],
player_probs: sv![(player, PlayerProbs { goal: Some(0.25), assist: None })],
prune_thresholds: PruneThresholds {
max_total_goals,
min_prob: 1e-6,
Expand Down
9 changes: 5 additions & 4 deletions brumby-soccer/src/bin/soc_prices2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use tracing::{debug, info};
use brumby::hash_lookup::HashLookup;
use brumby::market::{Market, Overround, OverroundMethod, PriceBounds};
use brumby::probs::SliceExt;
use brumby::sv;
use brumby_soccer::data::{download_by_id, ContestSummary, SoccerFeedId};
use brumby_soccer::domain::{Offer, OfferType, OutcomeType, Over, Period, Score};
use brumby_soccer::fit::{away_booksum, home_booksum, ErrorType, FittingErrors};
Expand Down Expand Up @@ -451,7 +452,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
away: 1.0,
},
},
player_probs: vec![(
player_probs: sv![(
player.clone(),
PlayerProbs {
goal: Some(*prob),
Expand Down Expand Up @@ -530,7 +531,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
away: 1.0,
},
},
player_probs: vec![(
player_probs: sv![(
player.clone(),
PlayerProbs {
goal: Some(*prob),
Expand Down Expand Up @@ -643,7 +644,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
h2_goals: BivariateProbs::from(adj_optimal_h2.as_slice()),
assists: assist_probs.clone(),
},
player_probs: vec![(
player_probs: sv![(
player.clone(),
PlayerProbs {
goal: None,
Expand Down Expand Up @@ -1000,7 +1001,7 @@ fn explore_scores(h1_goals: BivariateProbs, h2_goals: BivariateProbs) -> Explora
away: 1.0,
},
},
player_probs: vec![],
player_probs: sv![],
prune_thresholds: PruneThresholds {
max_total_goals: MAX_TOTAL_GOALS_FULL,
min_prob: 0.0,
Expand Down
3 changes: 0 additions & 3 deletions brumby-soccer/src/domain.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use std::iter::{Filter, Zip};
use std::slice::Iter;

use bincode::Encode;

use brumby::hash_lookup::HashLookup;
Expand Down
8 changes: 4 additions & 4 deletions brumby-soccer/src/fit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::Instant;

use tracing::debug;

use brumby::{factorial, poisson};
use brumby::{factorial, poisson, sv};
use brumby::capture::Capture;
use brumby::linear::matrix::Matrix;
use brumby::opt::{
Expand Down Expand Up @@ -333,7 +333,7 @@ fn fit_first_goalscorer_one(
h2_goals: h2_goals.clone(),
assists: UnivariateProbs::default(),
},
player_probs: vec![(
player_probs: sv![(
player.clone(),
PlayerProbs {
goal: Some(0.0),
Expand Down Expand Up @@ -436,7 +436,7 @@ fn fit_anytime_goalscorer_one(
h2_goals: h2_goals.clone(),
assists: UnivariateProbs::default(),
},
player_probs: vec![(
player_probs: sv![(
player.clone(),
PlayerProbs {
goal: Some(0.0),
Expand Down Expand Up @@ -541,7 +541,7 @@ fn fit_anytime_assist_one(
h2_goals: h2_goals.clone(),
assists: assist_probs.clone(),
},
player_probs: vec![(
player_probs: sv![(
player.clone(),
PlayerProbs {
goal: None,
Expand Down
7 changes: 4 additions & 3 deletions brumby-soccer/src/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ use crate::domain::{Player, Score, Side};
mod assist;
pub mod query;

const PLAYERS: usize = 4;
const NUM_PLAYERS: usize = 3;
const NUM_PLAYER_STATS: usize = NUM_PLAYERS + 1;

#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct Prospect {
pub ht_score: Score,
pub ft_score: Score,
pub stats: StackVec<PlayerStats, PLAYERS>,
pub stats: StackVec<PlayerStats, NUM_PLAYER_STATS>,
pub first_scorer: Option<usize>,
}
impl Prospect {
Expand Down Expand Up @@ -188,7 +189,7 @@ pub struct TeamProbs {
pub struct Config {
pub intervals: u8,
pub team_probs: TeamProbs,
pub player_probs: Vec<(Player, PlayerProbs)>,
pub player_probs: StackVec<(Player, PlayerProbs), NUM_PLAYERS>,
pub prune_thresholds: PruneThresholds,
pub expansions: Expansions,
}
Expand Down
7 changes: 4 additions & 3 deletions brumby-soccer/src/interval/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub fn isolate_set(

#[cfg(test)]
mod tests {
use brumby::sv;
use crate::domain::{Period, Score, Side};
use crate::interval::{explore, Config, BivariateProbs, TeamProbs, UnivariateProbs};

Expand All @@ -121,7 +122,7 @@ mod tests {
h2_goals: BivariateProbs { home: 0.25, away: 0.25, common: 0.25 },
assists: UnivariateProbs { home: 1.0, away: 1.0 },
},
player_probs: vec![],
player_probs: sv![],
prune_thresholds: Default::default(),
expansions: Expansions {
ht_score: false,
Expand Down Expand Up @@ -163,7 +164,7 @@ mod tests {
h2_goals: BivariateProbs { home: 0.25, away: 0.25, common: 0.25 },
assists: UnivariateProbs { home: 1.0, away: 1.0 },
},
player_probs: vec![],
player_probs: sv![],
prune_thresholds: Default::default(),
expansions: Expansions {
ht_score: false,
Expand Down Expand Up @@ -225,7 +226,7 @@ mod tests {
h2_goals: BivariateProbs { home: 0.25, away: 0.25, common: 0.25 },
assists: UnivariateProbs { home: 1.0, away: 1.0 },
},
player_probs: vec![],
player_probs: sv![],
prune_thresholds: Default::default(),
expansions: Expansions {
ht_score: false,
Expand Down
9 changes: 5 additions & 4 deletions brumby-soccer/src/interval/query/anytime_assist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub(crate) fn filter(query: &QuerySpec, prospect: &Prospect) -> bool {
#[cfg(test)]
mod tests {
use assert_float_eq::*;
use brumby::sv;
use super::*;
use crate::domain::{Period, Score, Side};
use crate::interval::{explore, Config, PlayerProbs, BivariateProbs, TeamProbs, UnivariateProbs};
Expand Down Expand Up @@ -71,7 +72,7 @@ mod tests {
},
assists: UnivariateProbs { home: 0.5, away: 1.0 },
},
player_probs: vec![
player_probs: sv![
(
alice.clone(),
PlayerProbs {
Expand All @@ -85,7 +86,7 @@ mod tests {
goal: Some(0.4),
assist: Some(0.4),
},
),
)
],
prune_thresholds: Default::default(),
expansions: Expansions {
Expand Down Expand Up @@ -162,7 +163,7 @@ mod tests {
},
assists: UnivariateProbs { home: 0.3, away: 0.4 },
},
player_probs: vec![
player_probs: sv![
(
alice.clone(),
PlayerProbs {
Expand All @@ -176,7 +177,7 @@ mod tests {
goal: Some(0.4),
assist: Some(0.4),
},
),
)
],
prune_thresholds: Default::default(),
expansions: Expansions {
Expand Down
14 changes: 7 additions & 7 deletions brumby-soccer/src/interval/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn explore_2x2() {
h2_goals: BivariateProbs { home: 0.25, away: 0.25, common: 0.25 },
assists: UnivariateProbs { home: 1.0, away: 1.0 },
},
player_probs: vec![],
player_probs: sv![],
prune_thresholds: Default::default(),
expansions: Default::default(),
},
Expand Down Expand Up @@ -267,7 +267,7 @@ fn explore_2x2_pruned_2_goals() {
h2_goals: BivariateProbs { home: 0.25, away: 0.25, common: 0.25 },
assists: UnivariateProbs { home: 1.0, away: 1.0 },
},
player_probs: vec![],
player_probs: sv![],
prune_thresholds: PruneThresholds {
max_total_goals: 2,
min_prob: 0.0,
Expand Down Expand Up @@ -409,7 +409,7 @@ fn explore_3x3() {
h2_goals: BivariateProbs { home: 0.25, away: 0.25, common: 0.25 },
assists: UnivariateProbs { home: 1.0, away: 1.0 },
},
player_probs: vec![],
player_probs: sv![],
prune_thresholds: Default::default(),
expansions: Default::default(),
},
Expand All @@ -431,7 +431,7 @@ fn explore_4x4() {
h2_goals: BivariateProbs { home: 0.25, away: 0.25, common: 0.25 },
assists: UnivariateProbs { home: 1.0, away: 1.0 },
},
player_probs: vec![],
player_probs: sv![],
prune_thresholds: Default::default(),
expansions: Default::default(),
},
Expand All @@ -454,7 +454,7 @@ fn explore_1x1_player_goal() {
h2_goals: BivariateProbs { home: 0.25, away: 0.25, common: 0.25 },
assists: UnivariateProbs { home: 1.0, away: 1.0 },
},
player_probs: vec![(player.clone(), PlayerProbs { goal: Some(0.25), assist: None })],
player_probs: sv![(player.clone(), PlayerProbs { goal: Some(0.25), assist: None })],
prune_thresholds: Default::default(),
expansions: Default::default(),
},
Expand Down Expand Up @@ -635,7 +635,7 @@ fn explore_2x2_player_goal() {
h2_goals: BivariateProbs { home: 0.25, away: 0.25, common: 0.25 },
assists: UnivariateProbs { home: 0.5, away: 0.5 },
},
player_probs: vec![(player.clone(), PlayerProbs { goal: Some(0.25), assist: None })],
player_probs: sv![(player.clone(), PlayerProbs { goal: Some(0.25), assist: None })],
prune_thresholds: Default::default(),
expansions: Default::default(),
},
Expand Down Expand Up @@ -681,7 +681,7 @@ fn explore_2x2_player_goal_asymmetric() {
h2_goals: BivariateProbs { home: 0.3, away: 0.2, common: 0.1 },
assists: UnivariateProbs { home: 1.0, away: 1.0 },
},
player_probs: vec![(player.clone(), PlayerProbs { goal: Some(0.25), assist: None })],
player_probs: sv![(player.clone(), PlayerProbs { goal: Some(0.25), assist: None })],
prune_thresholds: Default::default(),
expansions: Default::default(),
},
Expand Down
7 changes: 4 additions & 3 deletions brumby-soccer/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use brumby::capture::Capture;
use brumby::hash_lookup::HashLookup;
use brumby::market::{Market, Overround, PriceBounds};
use brumby::probs::SliceExt;
use brumby::sv;
use brumby::timed::Timed;

use crate::domain::error::{InvalidOffer, InvalidOutcome, MissingOutcome, UnvalidatedOffer};
Expand Down Expand Up @@ -232,7 +233,7 @@ impl Model {
let mut cache_stats = CacheStats::default();
for outcome in &stub.outcomes {
let player_probs = match outcome.get_player() {
None => vec![],
None => sv![],
Some(player) => {
let mut player_probs = PlayerProbs::default();
if requires_player_goal_probs {
Expand All @@ -241,7 +242,7 @@ impl Model {
if requires_player_assist_probs {
player_probs.assist = Some(self.require_player_assist_prob(player)?);
}
vec![(player.clone(), player_probs)]
sv![(player.clone(), player_probs)]
}
};

Expand Down Expand Up @@ -286,7 +287,7 @@ impl Model {
config: interval::Config {
intervals: self.config.intervals,
team_probs,
player_probs: vec![],
player_probs: sv![],
prune_thresholds,
expansions: reqs,
},
Expand Down
4 changes: 2 additions & 2 deletions brumby-soccer/src/scoregrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::interval::{explore, Config, PruneThresholds, BivariateProbs, TeamProb
use brumby::linear::matrix::Matrix;
use brumby::multinomial::bivariate_binomial;
use brumby::probs::SliceExt;
use brumby::{factorial, poisson};
use brumby::{factorial, poisson, sv};
use crate::domain::OfferType::CorrectScore;
use crate::interval::query::requirements;

Expand Down Expand Up @@ -168,7 +168,7 @@ pub fn from_interval(
h2_goals,
assists: UnivariateProbs { home: 1.0, away: 1.0 },
},
player_probs: vec![],
player_probs: sv![],
prune_thresholds: PruneThresholds {
max_total_goals,
min_prob: 0.0,
Expand Down
1 change: 1 addition & 0 deletions brumby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exclude.workspace = true

[dependencies]
anyhow = { workspace = true }
bincode = { workspace = true }
clap = { workspace = true }
racing_scraper = { workspace = true }
serde_json = { workspace = true }
Expand Down
Loading

0 comments on commit 4e8cf3b

Please sign in to comment.