Skip to content

Commit

Permalink
Cap on max player goals
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoutanov committed Dec 22, 2023
1 parent 87aaead commit 932ef71
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 92 deletions.
8 changes: 4 additions & 4 deletions brumby-soccer/src/bin/soc_prices2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
expansions: Expansions {
ht_score: false,
ft_score: false,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: true,
Expand Down Expand Up @@ -544,7 +544,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
expansions: Expansions {
ht_score: false,
ft_score: false,
player_goal_stats: true,
max_player_goals: u8::MAX,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
Expand Down Expand Up @@ -657,7 +657,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
expansions: Expansions {
ht_score: false,
ft_score: false,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 1,
first_goalscorer: false,
Expand Down Expand Up @@ -1008,7 +1008,7 @@ fn explore_scores(h1_goals: BivariateProbs, h2_goals: BivariateProbs) -> Explora
expansions: Expansions {
ht_score: true,
ft_score: true,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
Expand Down
29 changes: 7 additions & 22 deletions brumby-soccer/src/fit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ use brumby::opt::{
use brumby::probs::SliceExt;

use crate::domain::{Offer, OfferType, OutcomeType, Player, Side};
use crate::domain::OfferType::{AnytimeAssist, FirstGoalscorer};
use crate::domain::Player::Named;
use crate::interval::{
BivariateProbs, Config, Expansions, explore, PlayerProbs, PruneThresholds, TeamProbs,
BivariateProbs, Config, explore, PlayerProbs, PruneThresholds, TeamProbs,
UnivariateProbs,
};
use crate::interval::query::{isolate, requirements};
use crate::scoregrid;

// const INTERVALS: usize = 18;
// const MAX_TOTAL_GOALS_HALF: u16 = 6;
// const MAX_TOTAL_GOALS_FULL: u16 = 8;
const GOALSCORER_MIN_PROB: f64 = 0.0;
const ERROR_TYPE: ErrorType = ErrorType::SquaredRelative;

Expand Down Expand Up @@ -298,6 +296,7 @@ pub fn fit_first_goalscorer_all<'a>(
Player::Other => unreachable!(),
};
let init_estimate = first_goalscorer.market.probs[index] / side_ratio;
// let start = Instant::now();
let player_search_outcome = fit_first_goalscorer_one(
h1_probs,
h2_probs,
Expand All @@ -307,7 +306,7 @@ pub fn fit_first_goalscorer_all<'a>(
intervals,
max_total_goals
);
println!("first goal for player {player:?}, {player_search_outcome:?}, sample prob. {}, init_estimate: {init_estimate}", first_goalscorer.market.probs[index]);
// println!("first goal for player {player:?}, {player_search_outcome:?}, sample prob. {}, init_estimate: {init_estimate}, took {:?}", first_goalscorer.market.probs[index], start.elapsed());
(player.clone(), player_search_outcome.optimal_value)
}
_ => unreachable!(),
Expand Down Expand Up @@ -349,14 +348,7 @@ fn fit_first_goalscorer_one(
max_total_goals,
min_prob: GOALSCORER_MIN_PROB,
},
expansions: Expansions {
ht_score: false,
ft_score: false,
player_goal_stats: false,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: true,
},
expansions: requirements(&FirstGoalscorer),
};
let outcome_type = OutcomeType::Player(player.clone());
univariate_descent(
Expand Down Expand Up @@ -420,7 +412,7 @@ pub fn fit_anytime_goalscorer_all<'a>(
intervals,
max_total_goals
);
println!("anytime goal for player {player:?}, {player_search_outcome:?}, sample prob. {}, init_estimate: {init_estimate}", anytime_goalscorer.market.probs[index]);
// println!("anytime goal for player {player:?}, {player_search_outcome:?}, sample prob. {}, init_estimate: {init_estimate}", anytime_goalscorer.market.probs[index]);
(player.clone(), player_search_outcome.optimal_value)
}
_ => unreachable!(),
Expand Down Expand Up @@ -567,14 +559,7 @@ fn fit_anytime_assist_one(
max_total_goals,
min_prob: GOALSCORER_MIN_PROB,
},
expansions: Expansions {
ht_score: false,
ft_score: false,
player_goal_stats: false,
player_split_goal_stats: false,
max_player_assists: 1,
first_goalscorer: false,
},
expansions: requirements(&AnytimeAssist),
};
let outcome_type = OutcomeType::Player(player.clone());
univariate_descent(
Expand Down
26 changes: 15 additions & 11 deletions brumby-soccer/src/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<'a> From<&'a [f64]> for BivariateProbs {
pub struct Expansions {
pub ht_score: bool,
pub ft_score: bool,
pub player_goal_stats: bool,
pub max_player_goals: u8,
pub player_split_goal_stats: bool,
pub max_player_assists: u8,
pub first_goalscorer: bool,
Expand All @@ -89,30 +89,30 @@ impl Expansions {
fn validate(&self) {
if self.player_split_goal_stats {
assert!(
self.player_goal_stats,
"cannot expand player split goal stats without player goal stats"
self.max_player_goals > 0,
"cannot expand player split goal stats without player goals"
);
}
assert!(
self.ft_score
|| self.ht_score
|| self.player_goal_stats
|| self.max_player_goals > 0
|| self.first_goalscorer
|| self.max_player_assists > 0,
"at least one expansion must be enabled"
)
}

pub fn requires_team_goal_probs(&self) -> bool {
self.ht_score || self.ft_score || self.player_goal_stats || self.first_goalscorer || self.max_player_assists > 0
self.ht_score || self.ft_score || self.max_player_goals > 0 || self.first_goalscorer || self.max_player_assists > 0
}

pub fn requires_team_assist_probs(&self) -> bool {
self.max_player_assists > 0
}

pub fn requires_player_goal_probs(&self) -> bool {
self.player_goal_stats || self.first_goalscorer
self.max_player_goals > 0 || self.first_goalscorer
}

pub fn requires_player_assist_probs(&self) -> bool {
Expand All @@ -125,7 +125,7 @@ impl Default for Expansions {
Self {
ft_score: true,
ht_score: true,
player_goal_stats: true,
max_player_goals: u8::MAX,
player_split_goal_stats: true,
max_player_assists: u8::MAX,
first_goalscorer: true,
Expand Down Expand Up @@ -423,8 +423,10 @@ fn merge(
Half::First => &mut merged.stats[player].h1,
Half::Second => &mut merged.stats[player].h2,
};
split_stats.goals += 1;
} else if expansions.player_goal_stats {
if split_stats.goals < expansions.max_player_goals {
split_stats.goals += 1;
}
} else if merged.stats[player].h2.goals < expansions.max_player_goals {
merged.stats[player].h2.goals += 1;
}

Expand All @@ -448,8 +450,10 @@ fn merge(
Half::First => &mut merged.stats[player].h1,
Half::Second => &mut merged.stats[player].h2,
};
split_stats.goals += 1;
} else if expansions.player_goal_stats {
if split_stats.goals < expansions.max_player_goals {
split_stats.goals += 1;
}
} else if merged.stats[player].h2.goals < expansions.max_player_goals {
merged.stats[player].h2.goals += 1;
}

Expand Down
6 changes: 3 additions & 3 deletions brumby-soccer/src/interval/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ mod tests {
expansions: Expansions {
ht_score: false,
ft_score: true,
player_goal_stats: true,
max_player_goals: u8::MAX,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
Expand Down Expand Up @@ -168,7 +168,7 @@ mod tests {
expansions: Expansions {
ht_score: false,
ft_score: true,
player_goal_stats: true,
max_player_goals: u8::MAX,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
Expand Down Expand Up @@ -230,7 +230,7 @@ mod tests {
expansions: Expansions {
ht_score: false,
ft_score: true,
player_goal_stats: true,
max_player_goals: u8::MAX,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
Expand Down
6 changes: 3 additions & 3 deletions brumby-soccer/src/interval/query/anytime_assist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub(crate) fn requirements() -> Expansions {
Expansions {
ht_score: false,
ft_score: false,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 1,
first_goalscorer: false,
Expand Down Expand Up @@ -91,7 +91,7 @@ mod tests {
expansions: Expansions {
ht_score: false,
ft_score: false,
player_goal_stats: true,
max_player_goals: u8::MAX,
player_split_goal_stats: false,
max_player_assists: 1,
first_goalscorer: false,
Expand Down Expand Up @@ -182,7 +182,7 @@ mod tests {
expansions: Expansions {
ht_score: false,
ft_score: true,
player_goal_stats: true,
max_player_goals: u8::MAX,
player_split_goal_stats: false,
max_player_assists: 1,
first_goalscorer: false,
Expand Down
2 changes: 1 addition & 1 deletion brumby-soccer/src/interval/query/anytime_goalscorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub(crate) fn requirements() -> Expansions {
Expansions {
ht_score: false,
ft_score: false,
player_goal_stats: true,
max_player_goals: 1,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
Expand Down
6 changes: 3 additions & 3 deletions brumby-soccer/src/interval/query/correct_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ pub(crate) fn requirements(period: &Period) -> Expansions {
Period::FirstHalf => Expansions {
ht_score: true,
ft_score: false,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
},
Period::SecondHalf => Expansions {
ht_score: true,
ft_score: true,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
},
Period::FullTime => Expansions {
ht_score: false,
ft_score: true,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
Expand Down
2 changes: 1 addition & 1 deletion brumby-soccer/src/interval/query/first_goalscorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub(crate) fn requirements() -> Expansions {
Expansions {
ht_score: false,
ft_score: false,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: true,
Expand Down
6 changes: 3 additions & 3 deletions brumby-soccer/src/interval/query/head_to_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ pub(crate) fn requirements(period: &Period) -> Expansions {
Period::FirstHalf => Expansions {
ht_score: true,
ft_score: false,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
},
Period::SecondHalf => Expansions {
ht_score: true,
ft_score: true,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
},
Period::FullTime => Expansions {
ht_score: false,
ft_score: true,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
Expand Down
6 changes: 3 additions & 3 deletions brumby-soccer/src/interval/query/total_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ pub(crate) fn requirements(period: &Period) -> Expansions {
Period::FirstHalf => Expansions {
ht_score: true,
ft_score: false,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
},
Period::SecondHalf => Expansions {
ht_score: true,
ft_score: true,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
},
Period::FullTime => Expansions {
ht_score: false,
ft_score: true,
player_goal_stats: false,
max_player_goals: 0,
player_split_goal_stats: false,
max_player_assists: 0,
first_goalscorer: false,
Expand Down
Loading

0 comments on commit 932ef71

Please sign in to comment.