Skip to content
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

ENH: Display more information in MonteCarlo prints and plots #760

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

EvanMad
Copy link

@EvanMad EvanMad commented Dec 28, 2024

Pull request type

  • Code changes (bugfix, features)

Checklist

  • Lint (black rocketpy/ tests/) has passed locally
  • All tests (pytest tests -m slow --runslow) have passed locally
  • CHANGELOG.md has been updated (if relevant)

Current behavior

Prints maximum, minimum, mean, std dev
Plots ^ parameters with histograms

New behavior

Prints maximum, minimum, mean, std dev, 95% PI Lower, 95% PI Upper
Plots ^ parameters with histograms and boxplots

Breaking change

  • Yes
  • No

Additional information

For issue #730

image
image

@EvanMad EvanMad marked this pull request as ready for review December 28, 2024 20:27
@EvanMad EvanMad requested a review from a team as a code owner December 28, 2024 20:27
@Gui-FernandesBR
Copy link
Member

@EvanMad tks for your submission.

I've noticed this PR is duplicated with #753 , therefore we will have to think decide how to proceed, either merging both PRs into one or selecting just one of them.

Copy link
Member

@Gui-FernandesBR Gui-FernandesBR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it is looking good

CHANGELOG.md Outdated
@@ -48,6 +48,7 @@ Attention: The newest changes should be on top -->

- REL: update version to 1.7.1 in configuration files [#750](https://github.com/RocketPy-Team/RocketPy/pull/750)
- MNT: Refactor Tank's testing Assertion with CAD data. [#678](https://github.com/RocketPy-Team/RocketPy/pull/678)
ENH: Display more information in MonteCarlo prints and plots [#760](https://github.com/RocketPy-Team/RocketPy/pull/760)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor, but new lines should be add to the top, not the bottom of sections. This is common confusion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, it's also in the wrong section. fixed now

Comment on lines 176 to 190
for key in keys:
plt.figure()
plt.hist(self.monte_carlo.results[key])
plt.title(f"Histogram of {key}")
plt.ylabel("Number of Occurrences")
fig, (ax1, ax2) = plt.subplots(2, 1, height_ratios=[1, 3], figsize=(8, 8))

# Plot boxplot
ax1.boxplot(self.monte_carlo.results[key], vert=False)
ax1.set_xlabel(key)
ax1.set_title(f"Box Plot of {key}")

# Plot histogram
ax2.hist(self.monte_carlo.results[key])
ax2.set_title(f"Histogram of {key}")
ax2.set_ylabel("Number of Occurrences")

plt.tight_layout()
plt.show()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lucas-Prates should we really plot the 3 plot altogether? Perhaps letting the user activate/deactivate some of them if needed?

Comment on lines 723 to 732
mean = np.mean(values)
stdev = np.std(values)
self.processed_results[result] = (mean, stdev)
pi_low = np.quantile(values, 0.025)
pi_high = np.quantile(values, 0.975)
median = np.median(values)
self.processed_results[result] = (mean, median, stdev, pi_low, pi_high)
except TypeError:
self.processed_results[result] = (None, None)
self.processed_results[result] = (None, None, None, None, None)

# Import methods
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try:
    mean = np.mean(values)
    stdev = np.std(values)
    self.processed_results[result] = (mean, stdev)
    pi_low = np.quantile(values, 0.025)
    pi_high = np.quantile(values, 0.975)
    median = np.median(values)
except TypeError:
    mean = None
    stdev = None
    pi_low = None
    pi_high = None
    median = None

 self.processed_results[result] = (mean, median, stdev, pi_low, pi_high)

Alternatively, we could make 5 try/except blocks instead of one single.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah sorry i missed that, I have committed this suggestion

I don't think 5 try/except blocks is necessary. A situation where only one of these calculations fails seems unlikely to me. ie: either they all fail or none fail so catching them all in the same makes sense.

@EvanMad
Copy link
Author

EvanMad commented Dec 28, 2024

Apologies for duplicate. I saw that before opening the PR but it seemed like it was unfinished and contained errors

I believe this PR gets closer to resolving the original issue by combining the graphs onto the same plot

Let me know anything I can do to resolve this

@Gui-FernandesBR
Copy link
Member

Apologies for duplicate. I saw that before opening the PR but it seemed like it was unfinished and contained errors

I believe this PR gets closer to resolving the original issue by combining the graphs onto the same plot

Let me know anything I can do to resolve this

No problems. Your approach looks good. Once again, thanks for your submission.

@EvanMad EvanMad changed the base branch from master to develop December 28, 2024 21:19
@Gui-FernandesBR
Copy link
Member

@EvanMad our team is officially on vacations until January 6th.
We appreciate your patience when waiting for the final review.

Meanwhile, what you could already do is to solve linter issues pointed out by the GitHub Actions CI, or also solving the merge conflicts error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

2 participants