-
-
Notifications
You must be signed in to change notification settings - Fork 378
Issue/3151 laplace logging newlines #3153
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 all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
dd093d6
merge from develop
mitzimorris 3a47cd9
merge
mitzimorris badf28e
merge
mitzimorris 8885b38
laplace_sample code fix
mitzimorris 230442b
unit test for console output
mitzimorris 9094798
reorder for code grokability(?)
mitzimorris 66b1f18
add test for jacobian adjustment
mitzimorris 258099c
lint fix
mitzimorris 321ad62
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 3f76565
changes per code review
mitzimorris c23efad
merge
mitzimorris b1c6477
Merge commit '6df07120b4550211b2d0a82978489019a38a7bd8' into HEAD
yashikno 0bdca78
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot eb311c7
Merge branch 'issue/3151-laplace-logging-newlines' of https://github.…
mitzimorris 30c3723
Merge branch 'develop' of https://github.com/stan-dev/stan into issue…
mitzimorris 2d5853f
changes per code review
mitzimorris c9fe51f
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 535b6b8
this time for sure
mitzimorris 415abfa
merge fix
mitzimorris 9a49f4f
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot 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,6 @@ | ||
| parameters { | ||
| real<lower=0> sigma; | ||
| } | ||
| model { | ||
| sigma ~ normal(3, 1); | ||
| } |
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,75 @@ | ||
| #include <boost/algorithm/string.hpp> | ||
| #include <gtest/gtest.h> | ||
| #include <stan/callbacks/stream_logger.hpp> | ||
| #include <stan/callbacks/stream_writer.hpp> | ||
| #include <stan/io/dump.hpp> | ||
| #include <stan/io/empty_var_context.hpp> | ||
| #include <stan/io/stan_csv_reader.hpp> | ||
| #include <stan/services/error_codes.hpp> | ||
| #include <stan/services/optimize/laplace_sample.hpp> | ||
| #include <test/test-models/good/optimization/constrain_sigma.hpp> | ||
| #include <test/unit/services/instrumented_callbacks.hpp> | ||
| #include <test/unit/util.hpp> | ||
| #include <cmath> | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| class ServicesLaplaceJacobian : public ::testing::Test { | ||
| public: | ||
| ServicesLaplaceJacobian() : logger(msgs, msgs, msgs, msgs, msgs) {} | ||
|
|
||
| void SetUp() { | ||
| stan::io::empty_var_context var_context; | ||
| model = new stan_model(var_context); // typedef from multi_normal.hpp | ||
| } | ||
|
|
||
| void TearDown() { delete model; } | ||
|
|
||
| stan_model* model; | ||
| std::stringstream msgs; | ||
| stan::callbacks::stream_logger logger; | ||
| stan::test::unit::instrumented_interrupt interrupt; | ||
| }; | ||
|
|
||
| TEST_F(ServicesLaplaceJacobian, laplace_jacobian_adjust) { | ||
| Eigen::VectorXd theta_hat(1); | ||
| theta_hat << 1.09; // test for mode sigma at 3.1, take log | ||
| int draws = 5; | ||
| unsigned int seed = 1234; | ||
| int refresh = 1; | ||
| std::stringstream sample1_ss; | ||
| stan::callbacks::stream_writer sample_writer(sample1_ss, ""); | ||
| int return_code = stan::services::laplace_sample<true>( | ||
| *model, theta_hat, draws, seed, refresh, interrupt, logger, | ||
| sample_writer); | ||
| EXPECT_EQ(stan::services::error_codes::OK, return_code); | ||
| std::stringstream out; | ||
| stan::io::stan_csv draws1 | ||
| = stan::io::stan_csv_reader::parse(sample1_ss, &out); | ||
|
|
||
| std::stringstream sample2_ss; | ||
| stan::callbacks::stream_writer sample_writer2(sample2_ss, ""); | ||
| return_code = stan::services::laplace_sample<false>(*model, theta_hat, draws, | ||
| seed, refresh, interrupt, | ||
| logger, sample_writer2); | ||
| EXPECT_EQ(stan::services::error_codes::OK, return_code); | ||
| stan::io::stan_csv draws2 | ||
| = stan::io::stan_csv_reader::parse(sample2_ss, &out); | ||
|
|
||
| EXPECT_EQ(3, draws1.header.size()); | ||
| EXPECT_EQ("sigma", draws1.header[0]); | ||
| EXPECT_EQ("log_p", draws1.header[1]); | ||
| EXPECT_EQ("log_q", draws1.header[2]); | ||
|
|
||
| EXPECT_EQ(3, draws2.header.size()); | ||
| EXPECT_EQ("sigma", draws2.header[0]); | ||
| EXPECT_EQ("log_p", draws2.header[1]); | ||
| EXPECT_EQ("log_q", draws2.header[2]); | ||
|
|
||
| Eigen::MatrixXd sample1 = draws1.samples; | ||
| Eigen::MatrixXd sample2 = draws2.samples; | ||
|
|
||
| EXPECT_EQ(sample1.coeff(0, 0), sample2.coeff(0, 0)); | ||
| EXPECT_NE(sample1.coeff(0, 1), sample2.coeff(0, 1)); | ||
| EXPECT_EQ(sample1.coeff(0, 2), sample2.coeff(0, 2)); | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.