Skip to content

Edits to MC lecture - #105

Merged
jstac merged 4 commits into
mainfrom
mc_edits
Feb 27, 2023
Merged

jstac merged 4 commits into
mainfrom
mc_edits

Conversation

@jstac

@jstac jstac commented Feb 26, 2023

Copy link
Copy Markdown
Contributor

No description provided.

@netlify

netlify Bot commented Feb 26, 2023 •

Copy link
Copy Markdown

✅ Deploy Preview for taupe-gaufre-c4e660 ready!

Name Link
🔨 Latest commit 857297e
🔍 Latest deploy log https://app.netlify.com/sites/taupe-gaufre-c4e660/deploys/63fbfac2a6ea29000852cd4a
😎 Deploy Preview https://deploy-preview-105--taupe-gaufre-c4e660.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
github-actions Bot temporarily deployed to commit February 26, 2023 22:37 Inactive
@jstac

jstac commented Feb 26, 2023

Copy link
Copy Markdown
Contributor Author

@HumphreyYang , could you please use the logic in

ψ = (0.0, 0.2, 0.8)        # Initial condition

fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection='3d')

ax.set(xlim=(0, 1), ylim=(0, 1), zlim=(0, 1),
       xticks=(0.25, 0.5, 0.75),
       yticks=(0.25, 0.5, 0.75),
       zticks=(0.25, 0.5, 0.75))

x_vals, y_vals, z_vals = [], [], []
for t in range(20):
    x_vals.append(ψ[0])
    y_vals.append(ψ[1])
    z_vals.append(ψ[2])
    ψ = ψ @ P

ax.scatter(x_vals, y_vals, z_vals, c='r', s=60)
ax.view_init(30, 210)

mc = qe.MarkovChain(P)
ψ_star = mc.stationary_distributions[0]
ax.scatter(ψ_star[0], ψ_star[1], ψ_star[2], c='k', s=60)

plt.show()

in the two code cells that follow it --- see https://63fbdf37cab3e348c2918816--taupe-gaufre-c4e660.netlify.app/markov_chains.html

Perhaps you can unify these three code cells at least partially by writing a function that updates according to $\psi = \psi P$ and returns the time series of distributions $\psi, \psi P, \psi P^2, \ldots$?

Then you can extract coordinates for the plots.

Thanks.

@github-actions
github-actions Bot temporarily deployed to commit February 27, 2023 00:12 Inactive
@HumphreyYang

HumphreyYang commented Feb 27, 2023 •

Copy link
Copy Markdown
Member

Many thanks @jstac for your review.

I have integrated these code blocks with a function for simulating $\psi s$ and $\psi_0 s$

Please let me know if it needs further changes.

Comment thread lectures/markov_chains.md
Let's pick an initial distribution $\psi$ and trace out the sequence of distributions $\psi P^t$.

First, we write a function to simulate the sequence of distributions for `n` period

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@HumphreyYang I suggest we avoid the use of the word "simulate" here and in the name of the function, since there is no randomness involved. (We are just iterating on the deterministic vector difference equation $\psi_{t+1} = \psi_t P$.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Many thanks @jstac for picking this up. I have changed the function name to iterate_ψ.

@jstac

jstac commented Feb 27, 2023

Copy link
Copy Markdown
Contributor Author

Thanks @HumphreyYang for your quick response and nice update. Please see the comment above.

@github-actions
github-actions Bot temporarily deployed to commit February 27, 2023 00:32 Inactive
@github-actions
github-actions Bot temporarily deployed to commit February 27, 2023 00:38 Inactive
@jstac

jstac commented Feb 27, 2023

Copy link
Copy Markdown
Contributor Author

Nice work @HumphreyYang . Merging.

@jstac
jstac merged commit 9d3c9cf into main Feb 27, 2023
@jstac
jstac deleted the mc_edits branch February 27, 2023 00:59
Comment thread lectures/markov_chains.md
Comment on lines +363 to +364
if ψ is not None:
X_0 = qe.random.draw(np.cumsum(ψ))

@HumphreyYang HumphreyYang Feb 27, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @jstac,

Thanks for reminding me about the consistency in notation. It helps a lot to keep the code clear.

I just noticed that you were avoiding the use of ψ_0 in this function for initial distribution. I can see why this is preferred given no other $\psi$s are used, so _0 is redundant, but I also think it would be good if the notation for initial distributions is treated the same throughout this lecture. Please kindly let me know what you think about changing all initial distributions to ψ_0.

Many thanks in advance.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @HumphreyYang , I changed that one to be consistent with the mathematics above.

But you are right --- the code is now inconsistent with code that follows. Shall we change it back and then change the maths above it to use $\psi_0$ instead of $\psi$?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

BTW, I appreciate you raising this. Getting all the small things right is essential to creating a great lecture.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @HumphreyYang , I changed that one to be consistent with the mathematics above.

But you are right --- the code is now inconsistent with code that follows. Shall we change it back and then change the maths above it to use ψ0 instead of ψ?

Many thanks @jstac; I think changing to $ψ_0$ would be great. I will create a PR to check and change the math notation.

This branch was previously deployed

1 inactive deployment
commit — 857297e4 Deployed Feb 27, 2023 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants