-
-
Notifications
You must be signed in to change notification settings - Fork 360
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
Py monte carlo #184
Py monte carlo #184
Conversation
Thanks for your pull request, I like your version then #144 but you need to talk to jonasvandervennet on which python code to use. If you want to improve his python make a pull request to his fork. |
Hello and welcome, @GuyPozner! Thanks for contributing to the project! We always appreciate it when people spend their time to improve the Algorithm Archive. Unfortunately, we can't just take this pull request. As you know, people are already working on Monte Caro in Python over in #144. If you want to help with it or if you feel like something is wrong with it, you should join the discussion of the other pull request instead of creating a new one. You could even contribute code to the other PR like @Gathros already mentioned. I see that this is your first ever pull request, so I assume you're not very familiar with the Git and GitHub workflows. Don't worry, it's alright. It's not always very intuitive and you will eventually get used to it. Feel free to ask members of our community whenever you have questions about Git or GitHub and we'll be happy to help you out! |
I understand, so if I want to fix the versions which is currently in review, I have to either wait for the new one to be summited or send a pull request of that branch to the contributor of the older version? |
Yeah, you can pick either but I recommend going send the pull request to their branch. |
@GuyPozner That's about right I guess. For this situation, I recommend the first version, since it applies here. |
Also don't mind just pointing out things, you think, the author of a PR should change. You don't need to make a PR for that, the author usually changes things themselves, after getting input on what to do better. (If you have any questions on how to use the GitHub interface, feel free to ask.) |
I'm closing this PR now, if you have any questions, feel free to ask and/or join our Discord: https://discord.gg/Pr2E9S6 |
Previous PRs fell through. @GuyPozner, wanna take over? |
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.
A few quick changes. Also, the structure of the AAA had changed, so make sure you adapt to the current one.
import random | ||
|
||
|
||
def in_circle(x, y): |
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.
Make it in_circle(x, y, radius = 1)
it's cleaner
y = random.uniform(0,1) | ||
|
||
# Count the number of points inside the circle | ||
if(in_circle(x, y, radius)): |
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.
radius
should be dropped here.
|
||
# Since we've generated points on in upper left quadrant ([0,1], [0,1]) | ||
# We need to mulply the number of points by 4 | ||
pi_estimate = 4 * in_circle_count / (n_samples * radius * radius) |
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.
Drop radius
here too.
if __name__ == '__main__': | ||
|
||
pi_estimate = monte_carlo(100000) | ||
percent_error = abs(math.pi - pi_estimate)/math.pi |
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.
You need to multiply by 100 to get percents.
pi_estimate = monte_carlo(100000) | ||
percent_error = abs(math.pi - pi_estimate)/math.pi | ||
|
||
print("The estimate of pi is: %.3f" % pi_estimate) |
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.
I would use string interpolations "The estimate of pi is: {:.3f}".format(pi_estimate)
. Same for next line
chapters/monte_carlo/monte_carlo.md
Outdated
@@ -98,6 +100,8 @@ Feel free to submit your version via pull request, and thanks for reading! | |||
{%sample lang="go" %} | |||
### Go | |||
[import, lang:"golang"](code/go/monteCarlo.go) | |||
### Python |
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.
We decided to get rid of the ### Python
things.
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.
I'll commit the fixed version in 24 hours.
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.
Sure, take your time!
Also, please be careful that the structure of the AAA has changed since then. If you don't sync you branch first, there will be many many broken things :)
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.
Any chance you could commit the fixed version? We have received yet another PR for monte carlo in python, we really need to get this one done.
Ah, somehow I was reviewing an older version. Oh well, the comments that still appear are still valid. |
ea86ca2
to
935ae05
Compare
Fixed. |
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.
Thanks, the code is good.
However, you included change to 35 extra images files in your last commits, so I can't merge it like this. Can you fix it? Worst case scenario if it's too messy, open a new PR.
Also, please use descriptive commits. "garbage" and "garbage" simply won't do.
935ae05
to
e08a735
Compare
e08a735
to
a80cada
Compare
Again, it might be worth closing this one and opening a new PR. |
Hi @GuyPozner, I'm very sorry but I bypassed this PR, because we received yet another PR for Monte Carlo earlier today. Your code has been merged, byte for byte (actually, I added two byte in the |
I've review the current pull request for the python implementation and made change to resemble the current c and julia versions. Hope that it helps.