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

xexpx, xexpy #35

Merged
merged 1 commit into from
Mar 7, 2022
Merged

xexpx, xexpy #35

merged 1 commit into from
Mar 7, 2022

Conversation

cossio
Copy link
Contributor

@cossio cossio commented Mar 4, 2022

Adds functions xexpx(x) and xexpy(x, y), which compute x * exp(x) and x * exp(y), respectively, but taking the "correct" limit when the exponent is infinite.

Close #15 .

@cossio cossio mentioned this pull request Mar 4, 2022
Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

Thanks!

Can you add and test ChainRules derivatives as well?

test/basicfuns.jl Outdated Show resolved Hide resolved
test/basicfuns.jl Outdated Show resolved Hide resolved
test/basicfuns.jl Outdated Show resolved Hide resolved
test/basicfuns.jl Outdated Show resolved Hide resolved
src/basicfuns.jl Show resolved Hide resolved
src/basicfuns.jl Show resolved Hide resolved
@cossio
Copy link
Contributor Author

cossio commented Mar 6, 2022

I added the ChainRules and addressed your comments @devmotion @tpapp . Care for another look?

src/basicfuns.jl Outdated Show resolved Hide resolved
src/basicfuns.jl Outdated Show resolved Hide resolved
src/chainrules.jl Outdated Show resolved Hide resolved
src/chainrules.jl Outdated Show resolved Hide resolved
test/basicfuns.jl Outdated Show resolved Hide resolved
test/basicfuns.jl Outdated Show resolved Hide resolved
test/chainrules.jl Outdated Show resolved Hide resolved
test/chainrules.jl Outdated Show resolved Hide resolved
Copy link
Collaborator

@tpapp tpapp left a comment

Choose a reason for hiding this comment

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

As I said in the comments, I am fine with the branch structure as is, so it is up to you. For all other minor changes I agree with @devmotion's comments (marked them by a 👍).

Once this is done, this PR should be ready to merge. Thanks for doing it!

src/basicfuns.jl Outdated Show resolved Hide resolved
src/basicfuns.jl Show resolved Hide resolved
src/basicfuns.jl Outdated Show resolved Hide resolved
@cossio cossio force-pushed the xexpx branch 2 times, most recently from f0d3bea to 3d3d9a6 Compare March 6, 2022 14:13
@cossio
Copy link
Contributor Author

cossio commented Mar 6, 2022

I addressed the comments. Only thing I don't understand is the objection to using Ω / x in the chain rule @devmotion . I'd rather argue it is worth doing this optimization also for xlogx, etc. (in another PR)

@tpapp I think you requested some changes but I can't find them (probably bc I force pushed).

I would like to see a release once this is merged. Should I bump the version here (to 0.3.7)?

@cossio cossio requested review from devmotion and tpapp March 6, 2022 15:15
Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

Only thing I don't understand is the objection to using Ω / x in the chain rule @devmotion . I'd rather argue it is worth doing this optimization also for xlogx, etc. (in another PR)

I guess maybe I didn't express myself clearly enough: I'm not against optimizing the forward and reverse mode rules but I think computing Ω / x is the wrong thing to do here. Instead one should implement frule and rrule manually and reuse the result of exp(x) and exp(y) from the computation of the primal.

But I think it's fine to do that in a separate PR and use the unoptimized version initially.

@cossio
Copy link
Contributor Author

cossio commented Mar 6, 2022

but I think computing Ω / x is the wrong thing to do here

Why?

@devmotion
Copy link
Member

Because it is an unnecessary computation that you can avoid by just reusing exp(x)/exp(y), and it requires you to handle cases such as iszero(x). Hence IMO we should rather use the unoptimized version or implement frule/rrule.

@cossio
Copy link
Contributor Author

cossio commented Mar 6, 2022

I implemented the explicit frule and rrule as suggested by @devmotion . I also went ahead and used your suggested branches in the primal definitions since this looked more consistent with how the chain rules looked when reusing exp(x) etc.

I also bumped the version. Can we tag a release after merging?

Care to take another look? @devmotion @tpapp

@cossio cossio requested a review from devmotion March 6, 2022 17:15
Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

I think it looks good. I made some suggestions for how the code could be made more readable and simpler (in particular the CR derivatives), and how the tests could be extended.

src/basicfuns.jl Outdated Show resolved Hide resolved
src/basicfuns.jl Outdated Show resolved Hide resolved
src/chainrules.jl Outdated Show resolved Hide resolved
src/chainrules.jl Outdated Show resolved Hide resolved
src/chainrules.jl Outdated Show resolved Hide resolved
test/basicfuns.jl Outdated Show resolved Hide resolved
test/basicfuns.jl Outdated Show resolved Hide resolved
test/basicfuns.jl Outdated Show resolved Hide resolved
test/basicfuns.jl Outdated Show resolved Hide resolved
test/chainrules.jl Outdated Show resolved Hide resolved
@cossio cossio force-pushed the xexpx branch 5 times, most recently from a36c63e to 959298c Compare March 6, 2022 22:57
@cossio
Copy link
Contributor Author

cossio commented Mar 6, 2022

Incorporated most of your comments (with minor modifications) @devmotion

src/basicfuns.jl Outdated Show resolved Hide resolved
src/chainrules.jl Outdated Show resolved Hide resolved
src/chainrules.jl Outdated Show resolved Hide resolved
test/chainrules.jl Outdated Show resolved Hide resolved
test/chainrules.jl Outdated Show resolved Hide resolved
test/chainrules.jl Outdated Show resolved Hide resolved
Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

Thanks for the PR and for addressing all our comments 🙂

I think the PR is ready to be merged and released but I want to wait if @tpapp has any additional comments.

Copy link
Collaborator

@tpapp tpapp left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks again!

@devmotion devmotion merged commit 8ce6807 into JuliaStats:master Mar 7, 2022
@cossio cossio deleted the xexpx branch March 7, 2022 10:25
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.

xexpx(z)
3 participants