Skip to content

New chapter "Metropolis" with Python Implementation #929

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

Merged
merged 82 commits into from
Dec 3, 2021

Conversation

shudipto-amin
Copy link
Contributor

No description provided.

@PeanutbutterWarrior
Copy link
Contributor

PeanutbutterWarrior commented Nov 10, 2021

I feel like this would make more sense grouped together with monte carlo under "Monte Carlo Methods", and rename monte carlo to "Approximating Areas"

@leios leios self-requested a review November 10, 2021 20:01
@leios leios self-assigned this Nov 10, 2021
@PeanutbutterWarrior
Copy link
Contributor

PeanutbutterWarrior commented Nov 10, 2021

I dislike using numpy. It's specialised enough that not everyone will know it, and it has no counterpart in many languages. It could be replaced here with math.e**(-b1*(x-x1)**2), and random.uniform(-1, 1).

@shudipto-amin
Copy link
Contributor Author

I feel like this would make more sense grouped together with monte carlo under "Monte Carlo Methods", and rename monte carlo to "Approximating Areas"

I agree - they belong in a similar category.

@shudipto-amin
Copy link
Contributor Author

I dislike using numpy. It's specialised enough that not everyone will know it, and it has no counterpart in many languages. It could be replaced here with math.e**(-b1*(x-x1)**2), and random.uniform(-1, 1).

I'm not sure I agree, but I see where you're coming from, with math and random being built in libraries. Also, a bunch of other code on AAA uses numpy quite a bit. But perhaps here we don't need to use it, as it doesn't simplify the code like in the others. I am okay with changing it.

Copy link
Member

@leios leios left a comment

Choose a reason for hiding this comment

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

Overall, I think the quality here is good. I a few lingering remarks that I didn't mention yet:

  1. I think random walk should not be capitalized in the text body
  2. It would be nice to talk briefly about how this is used in practice. I know it's used a lot in various physical applications, so maybe pointing to those with citations would be nice. I like that the code is for a general PDF, but maybe mentioning Mawell--Boltzmann or something would make the physics folk happy

@leios
Copy link
Member

leios commented Nov 12, 2021

For numpy, I think it's fine in this case. As someone coming from an HPC background, I genuinely thought the first thing everyone did when using python was to import numpy. I think we should be cognizant of the fact that this is not true for everyone and maybe remove numpy from less numerical methods.

shudipto-amin and others added 2 commits November 25, 2021 12:12
Co-authored-by: James Schloss <jrs.schloss@gmail.com>
Mostly typos, spelling, punctuation, and grammar.

Co-authored-by: James Schloss <jrs.schloss@gmail.com>
@Amaras
Copy link
Member

Amaras commented Nov 25, 2021

I need to tell you two things @shudipto-amin.

First we receive a notification on the discord server after every single commit.
This gets overwhelming very quickly. So could you please commit suggestions in batches in the future? This applies to this chapter review and all future reviews.

Second, I have a few problems with your notation, since I come from a mathematical background, the main thing being that I have never seen the [2..12] notation used anywhere. I have already seen "double brackets" (something that looks like I[2, 12]I, I can't reproduce it better right now) and $ [2, 12] \cap \mathbb{N}$ for the integer interval [2, 12].
If you could point me to several mathematical sources that use your notation, I'll gladly read them and maybe even use it myself, but for now, it's not something I recognise easily.

@shudipto-amin
Copy link
Contributor Author

shudipto-amin commented Nov 26, 2021

@Amaras

I need to tell you two things @shudipto-amin.

First we receive a notification on the discord server after every single commit. This gets overwhelming very quickly. So could you please commit suggestions in batches in the future? This applies to this chapter review and all future reviews.

I'm sorry about that, I was adding from conversations where that seems to be the only option. Later, I did discover that option in the files tab, and started batching about half-way through.

Second, I have a few problems with your notation, since I come from a mathematical background, the main thing being that I have never seen the [2..12] notation used anywhere. I have already seen "double brackets" (something that looks like I[2, 12]I, I can't reproduce it better right now) and $ [2, 12] \cap \mathbb{N}$ for the integer interval [2, 12]. If you could point me to several mathematical sources that use your notation, I'll gladly read them and maybe even use it myself, but for now, it's not something I recognise easily.

I personally only discovered this notation recently - I normally see something like your example with $\mathbb{N}$. However, I thought this would be notationally simpler, since I explain it anyway. I also thought it would be a bit more familiar to people with some coding background, but I'm not really sure. The only public source I can remember right now is this Wikipedia page. If you think I should change it, I don't mind.

@Amaras
Copy link
Member

Amaras commented Nov 26, 2021

I'm sorry about that, I was adding from conversations where that seems to be the only option. Later, I did discover that option in the files tab, and started batching about half-way through.

No problem, but keep that in mind for the future.

I personally only discovered this notation recently - I normally see something like your example with $\mathbb{N}$. However, I thought this would be notationally simpler, since I explain it anyway. I also thought it would be a bit more familiar to people with some coding background, but I'm not really sure. The only public source I can remember right now is this Wikipedia page. If you think I should change it, I don't mind.

Yeah, that just tells me we need a mathematical notation chapter. I personally would prefer the ⟦a, b⟧ notation, but that's not a native latex symbol if I remember correctly.

Copy link
Member

@leios leios left a comment

Choose a reason for hiding this comment

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

Looks good! Mostly done, just have to look at the second half of Metropolis now!

@Amaras
Copy link
Member

Amaras commented Nov 26, 2021

@Amaras, I used this negative space hack, and it actually looks alright. Does this work?

Yeah, it looks good :)

Copy link
Member

@leios leios left a comment

Choose a reason for hiding this comment

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

Overall, very small changes to the text. Sorry to keep splitting this up into a bunch of smaller reviews.

I'll look at the code tomorrow and then I think the PR will be mostly ready to go!



## The Algorithm for a One Dimensional Example

Copy link
Member

Choose a reason for hiding this comment

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

There should be a comment here introducing the upcoming sections

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Couldn't come up with anything other than the line (147) below. Feel free to throw in some suggestions.

{% endmethod %}

However, $$g$$ can be any function symmetric about $$0$$ for the above algorithm to work.
For example, it can be a number chosen randomly from a discrete list, such as $$[ -3, -1, -1, +1, +1, +3]$$.
Copy link
Member

Choose a reason for hiding this comment

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

To be clear: this was meant to have multiple 1's, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, just to illustrate that g doesn't have to be uniform, only symmetric.

shudipto-amin and others added 2 commits November 27, 2021 09:30
Mostly grammar and sentence structure.

Co-authored-by: James Schloss <jrs.schloss@gmail.com>
Copy link
Contributor Author

@shudipto-amin shudipto-amin left a comment

Choose a reason for hiding this comment

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

Added a line to introduce subsections in " The Algorithm for a One D..." section. Not sure if it's sufficient. Addressed all other minor edits in a previous commit.

{% endmethod %}

However, $$g$$ can be any function symmetric about $$0$$ for the above algorithm to work.
For example, it can be a number chosen randomly from a discrete list, such as $$[ -3, -1, -1, +1, +1, +3]$$.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, just to illustrate that g doesn't have to be uniform, only symmetric.



## The Algorithm for a One Dimensional Example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Couldn't come up with anything other than the line (147) below. Feel free to throw in some suggestions.

Copy link
Member

@leios leios left a comment

Choose a reason for hiding this comment

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

Overall, this looks good to me. There are just a few small changes to be made, so I am happy to go ahead and approve this! Good work and thanks for the patience!

On the other hand, a walker with a large step size may not sample nearby regions accurately &ndash; and actually has a higher chance of being rejected if the walker is already in a high probability region, since the acceptance ratio is more drastic for large steps.
The effect of step-size on the walker's efficiency is far from obvious!

How to choose $$g$$ is in itself a research field and depends on what the goal of the sampling is.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
How to choose $$g$$ is in itself a research field and depends on what the goal of the sampling is.
How to choose $$g$$ is in itself a research field and depends on what the goal of the sampling is.
Suggested change
How to choose $$g$$ is in itself a research field and depends on what the goal of the sampling is.
How to choose $$g$$ is, itself, a research field and depends on what the goal of the sampling is.



if __name__ == "__main__":
xmin, xmax = -7, 7
Copy link
Member

Choose a reason for hiding this comment

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

Didn't we say in the chapter that our domain was from -10 to 10?

* Minor edits for grammar and clarity.
* Applies to both metropolis and probablity chapters.

Co-authored-by: James Schloss <jrs.schloss@gmail.com>
Copy link
Contributor Author

@shudipto-amin shudipto-amin left a comment

Choose a reason for hiding this comment

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

Suggesting changes to address remaining comments by Leios, namely:

  1. Changing the domain of x in python code,
  2. Rewording the statement regarding finding an optimal $$g$$.

leios and others added 2 commits December 3, 2021 14:14
Co-authored-by: Shudipto <32040453+shudipto-amin@users.noreply.github.com>
@leios leios merged commit 05e9758 into algorithm-archivists:main Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Chapter This provides a new chapter. (md files are edited) Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) lang: python Python programming language
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants