-
-
Notifications
You must be signed in to change notification settings - Fork 208
Changed calculation of log_sum_exp(x1, x2) #1772
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
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5fd8e2b
change derivative calculation for log_sum_exp; fixes #1679
pgree 0869a16
remove white space
pgree 2f5432f
remove more white space
pgree 8aa6a50
Merge commit '114985aaf0798584525c0cf7fd6cab0168222f54' into HEAD
yashikno b513358
[Jenkins] auto-formatting by clang-format version 5.0.0-3~16.04.1 (ta…
stan-buildbot 3a03bd9
replaced calculate_chain and removed function
pgree 088ee0c
Merge remote-tracking branch 'pgree/bugfix/1679-log-sum-exp' into bug…
pgree 817dec8
included inv_logit, added new test
pgree 67a1b13
Merge commit 'fe3a41c3e854fe604841b237fa0475f26d29fe98' into HEAD
yashikno 829be7f
[Jenkins] auto-formatting by clang-format version 6.0.0 (tags/google/…
stan-buildbot c261931
added test for var and double
pgree 197831a
merged with current
pgree 62a3c1f
updated header
pgree a793873
updated another header
pgree File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include <stan/math/rev.hpp> | ||
| #include <gtest/gtest.h> | ||
| #include <test/unit/math/rev/fun/util.hpp> | ||
| #include <test/unit/math/rev/util.hpp> | ||
|
|
||
| TEST(log_sum_exp_tests, large_values) { | ||
| using stan::math::var; | ||
|
|
||
| var a = 1e50; | ||
| var output = stan::math::log_sum_exp(a, a); | ||
| output.grad(); | ||
| EXPECT_FLOAT_EQ(output.val(), log(2.0) + value_of(a)); | ||
| EXPECT_FLOAT_EQ(a.adj(), 1.0); | ||
|
|
||
| var a1 = 1e50; | ||
| var a2 = 1; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once you remove the other calculate_chain thing we'll need some tests where a1 is a var and a2 is a double. |
||
| var output2 = stan::math::log_sum_exp(a1, a2); | ||
| output2.grad(); | ||
| EXPECT_FLOAT_EQ(a1.adj(), 1.0); | ||
| EXPECT_FLOAT_EQ(a2.adj(), 0.0); | ||
|
|
||
| var a3 = 1; | ||
| var a4 = 1e50; | ||
| var output3 = stan::math::log_sum_exp(a3, a4); | ||
| output3.grad(); | ||
| EXPECT_FLOAT_EQ(a3.adj(), 0.0); | ||
| EXPECT_FLOAT_EQ(a4.adj(), 1.0); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would it be possible to get rid of calculate_chain everywhere? It seems like a strange function.
Also used here (which should be fixed as part of this pull):
math/stan/math/rev/fun/log_sum_exp.hpp
Line 37 in b513358
In stan/math/rev/fun/log_diff_exp.hpp and in stan/math/rev/fun/log1p_exp.hpp.