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

[equalizing_difference] Update numpy code in to remove vectorization #388

Merged
merged 2 commits into from
Feb 29, 2024

Conversation

HumphreyYang
Copy link
Collaborator

This PR completes the first stage of #385.

Copy link

netlify bot commented Feb 27, 2024

Deploy Preview for taupe-gaufre-c4e660 ready!

Name Link
🔨 Latest commit 568dcd5
🔍 Latest deploy log https://app.netlify.com/sites/taupe-gaufre-c4e660/deploys/65dfeddccf53f3000849e9e5
😎 Deploy Preview https://deploy-preview-388--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 configuration.

Copy link

github-actions bot commented Feb 27, 2024

@github-actions github-actions bot temporarily deployed to pull request February 27, 2024 00:17 Inactive
@mmcky
Copy link
Contributor

mmcky commented Feb 27, 2024

Wow -- nice work. this reduces a LOT of code.

@HumphreyYang
Copy link
Collaborator Author

Many thanks @mmcky,

Please let me know if you approve this PR. Once this is merged, I will work on improving the sympy code and migrating the entrepreneur model into exercise.

# one switches to the weak model by setting π
self.R, self.γ_h, self.γ_c, self.w_h0, self.D = R, γ_h, γ_c, w_h0, D
self.T, self.π = T, π
# Tweaked model
Copy link
Contributor

Choose a reason for hiding this comment

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

After π=None put # Extra parameter (modified version) and then replace Tweaked model with Modification for reinterpreted model

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @jstac,

Since $\pi$ is only used for the entrepreneur model, would it be a good idea to remove it here and create a new namedtuple for the entrepreneur model when moving it into the exercise?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @HumphreyYang , yes, good call. Let's do exactly that.


```{code-cell} ipython3
R_arr = np.linspace(1, 1.2, 50)
plt.plot(R_arr, φ_R(ex1, R_arr))
plt.plot(R_arr, compute_gap(create_edm(R=R_arr)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, this actually works?? That's amazing. So create_edm(R=R_arr) returns a numpy array of namedtuples??

This definitely needs some comments.

Copy link
Collaborator Author

@HumphreyYang HumphreyYang Feb 28, 2024

Choose a reason for hiding this comment

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

I think this is passing the model with parameter R as a numpy array into compute_gap but not creating a numpy array of namedtuple.

The R_arr is then unpacked in the compute_gap function, and the operation on the array is broadcasted within the function.

This definitely needs some comments.

I agree! Would you think a comment like # Create a model and compute the gap suffice?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please see my response below.

We find that raising the gross interest rate $R$ increases the initial college wage premium $\phi$, as we did with our graphical analysis earlier
Copy link
Contributor

Choose a reason for hiding this comment

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

"as we did with our graphical analysis earlier" -> "in line with our earlier graphical analysis"

@jstac
Copy link
Contributor

jstac commented Feb 28, 2024

Thanks @HumphreyYang , please see my comments.

@longye-tian , do you have any suggestions or are you happy with these changes?

@longye-tian
Copy link
Collaborator

@jstac Thank you for asking me. I learn a lot from how @HumphreyYang improve the code.

It's really amazing how he creates the array of namedtuples.

Maybe we can create some variables to store this array of namedtuples and the gap values using list comprehension.
This may be useful if we need to examine some changes in the gap values.

models = [create_edm(R=r) for r in R_arr]
gaps = [compute_gap(model) for model in models]
plt.plot(R_arr, gaps)

Best,
Longye
:)

@jstac
Copy link
Contributor

jstac commented Feb 28, 2024

Thanks @longye-tian for the nice suggestion.

@HumphreyYang , your code is elegant, fast and concise but @longye-tian 's version is more explicit and I think it's better for this intro lecture series. Can you please switch to his version?

@HumphreyYang
Copy link
Collaborator Author

Thanks @longye-tian for the nice suggestion.

@HumphreyYang , your code is elegant, fast and concise but @longye-tian 's version is more explicit and I think it's better for this intro lecture series. Can you please switch to his version?

Many thanks @jstac and @longye-tian for the suggestions. I will switch to the more explicit version.

@github-actions github-actions bot temporarily deployed to pull request February 29, 2024 02:45 Inactive
@jstac
Copy link
Contributor

jstac commented Feb 29, 2024

Very nice work @HumphreyYang and many thanks @longye-tian for helpful suggestions. This is a big improvement. Merging.

@jstac jstac merged commit 2b863a3 into main Feb 29, 2024
6 checks passed
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.

4 participants