Skip to content

Commit

Permalink
Not using the term 'scenarios'
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoutanov committed Nov 10, 2023
1 parent f434784 commit 53e458e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
14 changes: 7 additions & 7 deletions src/mc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ impl<'a, R: Rand> MonteCarloEngine<'a, R> {

pub fn simulate_batch(
&mut self,
scenarios: &[Selections],
selections_list: &[Selections],
counts: &mut [u64],
) {
self.ensure_init();
// println!("simulating with: \n{}", self.probs.as_ref().unwrap().verbose());

simulate_batch(
self.trials,
scenarios,
selections_list,
counts,
self.probs.as_ref().unwrap(),
self.podium.as_mut().unwrap(),
Expand Down Expand Up @@ -193,7 +193,7 @@ impl From<DilatedProbs<'_>> for Matrix<f64> {

pub fn simulate_batch(
trials: u64,
scenarios: &[Selections],
selections_list: &[Selections],
counts: &mut [u64],
probs: &Matrix<f64>,
podium: &mut [usize],
Expand All @@ -203,17 +203,17 @@ pub fn simulate_batch(
) {
assert!(validate_args(probs, podium, bitmap, totals));
assert_eq!(
scenarios.len(),
selections_list.len(),
counts.len(),
"a count must exist for each scenario"
"a count must exist for each set of selections"
);

counts.fill(0);
for _ in 0..trials {
run_once(probs, podium, bitmap, totals, rand);
for (scenario_index, selections) in scenarios.iter().enumerate() {
for (selections_index, selections) in selections_list.iter().enumerate() {
if selections.iter().all(|selection| selection.matches(podium)) {
counts[scenario_index] += 1;
counts[selections_index] += 1;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ fn derive_prices(

let runners = weighted_probs.cols();
let mut counts = Matrix::allocate(PODIUM, runners);
let scenarios = selection::top_n_matrix(PODIUM, runners);
engine.simulate_batch(scenarios.flatten(), counts.flatten_mut());
let all_selections = selection::top_n_matrix(PODIUM, runners);
engine.simulate_batch(all_selections.flatten(), counts.flatten_mut());

let mut derived_probs = Matrix::allocate(PODIUM, runners);
for runner in 0..runners {
Expand Down
12 changes: 6 additions & 6 deletions src/model/fit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ pub fn fit_all(options: &FitOptions, markets: &[Market]) -> Result<AllFitOutcome
.with_podium_places(model::PODIUM)
.into();

let scenarios = selection::top_n_matrix(model::PODIUM, num_runners);
let all_selections = selection::top_n_matrix(model::PODIUM, num_runners);

let outcomes: Vec<_> = (1..model::PODIUM)
.map(|rank| {
let market = &markets[rank];
let outcome = fit_individual(
&scenarios,
&all_selections,
&weighted_probs,
options.mc_trials,
options.individual_target_msre,
Expand Down Expand Up @@ -166,9 +166,9 @@ pub fn fit_place(
) -> Result<PlaceFitOutcome, anyhow::Error> {
options.validate()?;
let num_runners = place_market.probs.len();
let scenarios = selection::top_n_matrix(model::PODIUM, num_runners);
let all_selections = selection::top_n_matrix(model::PODIUM, num_runners);
let outcome = fit_individual(
&scenarios,
&all_selections,
weighted_probs,
options.mc_trials,
options.individual_target_msre,
Expand Down Expand Up @@ -217,7 +217,7 @@ pub struct IndividualFitOutcome {
}

fn fit_individual(
scenarios: &Matrix<Selections>,
all_selections: &Matrix<Selections>,
weighted_probs: &Matrix<f64>,
mc_trials: u64,
target_msre: f64,
Expand Down Expand Up @@ -245,7 +245,7 @@ fn fit_individual(
Rank::index(rank)
);
let mut counts = Matrix::allocate(podium_places, runners);
engine.simulate_batch(scenarios.flatten(), counts.flatten_mut());
engine.simulate_batch(all_selections.flatten(), counts.flatten_mut());
let fitted_probs: Vec<_> = counts
.row_slice(rank)
.iter()
Expand Down
6 changes: 3 additions & 3 deletions src/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ impl<'a> FromStr for Selections<'a> {

/// Builds a `podium_places` x `num_runners` matrix populated with top-_N_ selections.
pub fn top_n_matrix(podium_places: usize, num_runners: usize) -> Matrix<Selections<'static>> {
let mut scenarios = Matrix::allocate(podium_places, num_runners);
let mut all_selections = Matrix::allocate(podium_places, num_runners);
for runner in 0..num_runners {
for rank in 0..podium_places {
scenarios[(rank, runner)] = vec![Runner::index(runner).top(Rank::index(rank))].into();
all_selections[(rank, runner)] = vec![Runner::index(runner).top(Rank::index(rank))].into();
}
}
scenarios
all_selections
}

pub fn validate_plausible_selections(selections: &[Selection]) -> Result<(), anyhow::Error> {
Expand Down

0 comments on commit 53e458e

Please sign in to comment.