Repository navigation
BUG: let a batch_size=1 convergence study reach a second result #1233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
umutKaracelebi
wants to merge
2
commits into
RocketPy-Team:develop
Choose a base branch
from
umutKaracelebi:bug/convergence-first-batch-single-result
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -238,6 +238,7 @@ def test_estimate_confidence_interval_raises_type_error_for_invalid_statistic(): | |||||||||||||||||||||||||||||||||||||
| ({"batch_size": 0}, "batch_size"), | ||||||||||||||||||||||||||||||||||||||
| ({"batch_size": -5}, "batch_size"), | ||||||||||||||||||||||||||||||||||||||
| ({"max_simulations": 0}, "max_simulations"), | ||||||||||||||||||||||||||||||||||||||
| ({"max_simulations": 1}, "max_simulations"), | ||||||||||||||||||||||||||||||||||||||
| ({"tolerance": 0}, "tolerance"), | ||||||||||||||||||||||||||||||||||||||
| ({"tolerance": -1.0}, "tolerance"), | ||||||||||||||||||||||||||||||||||||||
| ({"target_confidence": 1.5}, "target_confidence"), | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -541,6 +542,7 @@ def __init__(self, width_model): | |||||||||||||||||||||||||||||||||||||
| self.filename = pathlib.Path("dummy_mc") | ||||||||||||||||||||||||||||||||||||||
| self._width_model = width_model | ||||||||||||||||||||||||||||||||||||||
| self.simulate_calls = 0 | ||||||||||||||||||||||||||||||||||||||
| self.estimate_calls = [] | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def import_outputs(self, *args, **kwargs): # no-op, avoids file I/O | ||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -552,6 +554,7 @@ def simulate(self, number_of_simulations, append=True, **kwargs): | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def estimate_confidence_interval(self, attribute, confidence_level=0.95, **kwargs): | ||||||||||||||||||||||||||||||||||||||
| # pylint: disable=arguments-differ,unused-argument | ||||||||||||||||||||||||||||||||||||||
| self.estimate_calls.append(self.num_of_loaded_sims) | ||||||||||||||||||||||||||||||||||||||
| width = self._width_model(self.num_of_loaded_sims) | ||||||||||||||||||||||||||||||||||||||
| return _CI(low=0.0, high=width) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
@@ -575,6 +578,26 @@ def test_simulate_convergence_stops_early_when_tolerance_met(): | |||||||||||||||||||||||||||||||||||||
| assert mc.num_of_loaded_sims < 1000 # did not exhaust the simulation budget | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_simulate_convergence_never_estimates_from_a_single_result(): | ||||||||||||||||||||||||||||||||||||||
| """A fresh study with batch_size=1 must wait for its second result. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ``scipy.stats.bootstrap`` needs two or more observations, so the first | ||||||||||||||||||||||||||||||||||||||
| batch of a one-row-per-batch study could not be summarised (#1229). | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| mc = ConvergenceMockMonteCarlo(width_model=lambda n: 10.0) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| history = mc.simulate_convergence( | ||||||||||||||||||||||||||||||||||||||
| target_attribute="apogee_time", | ||||||||||||||||||||||||||||||||||||||
| tolerance=0.5, | ||||||||||||||||||||||||||||||||||||||
| max_simulations=4, | ||||||||||||||||||||||||||||||||||||||
| batch_size=1, | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| assert mc.simulate_calls == 4 | ||||||||||||||||||||||||||||||||||||||
| assert mc.estimate_calls == [2, 3, 4] # never a lone observation | ||||||||||||||||||||||||||||||||||||||
| assert len(history) == 3 | ||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No test covers
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_simulate_convergence_runs_until_max_when_not_converging(): | ||||||||||||||||||||||||||||||||||||||
| """When the CI width never drops below the tolerance, the loop must run | ||||||||||||||||||||||||||||||||||||||
| until max_simulations and never exceed it.""" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
batch_size=1, the study can now stop as converged after only two simulations.The first width is computed at n=2, and a bootstrap interval on two draws is roughly the gap between them. With
tolerance=0.5, two flights whoseapogee_timelands 0.3 s apart passwidth <= toleranceat line 1061, and the loop returns after 2 flights.batch_size=2already behaved like this, but this PR opens the same path forbatch_size=1. Could the tolerance check wait for a minimum number of results (a small floor, separate from the bootstrap minimum of 2), or the docstring at least warn that small batches can stop this early?