-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c04eab
commit 42af1d2
Showing
7 changed files
with
84 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -2,5 +2,5 @@ build | |
.vscode | ||
.* | ||
!.travis.yml | ||
lib | ||
lib/* | ||
!lib/CMakeLists.txt |
This file contains 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 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,4 @@ | ||
|
||
add_executable(normal_two_prior_distribution ${CMAKE_CURRENT_SOURCE_DIR}/normal_two_prior_distribution.cpp) | ||
target_include_directories(normal_two_prior_distribution PRIVATE ${GBENCH_DIR}/include ${AUTOPPL_INCLUDE_DIRS}) | ||
target_link_libraries(normal_two_prior_distribution benchmark benchmark_main pthread ${AUTOPPL_LIBS}) |
This file contains 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,33 @@ | ||
#include <benchmark/benchmark.h> | ||
#include <autoppl/autoppl.hpp> | ||
|
||
namespace ppl { | ||
|
||
static void BM_NormalTwoPrior(benchmark::State& state) { | ||
std::normal_distribution n(0.0, 1.0); | ||
std::mt19937 gen(0); | ||
ppl::Data<double> y; | ||
|
||
ppl::Param<double> lambda1, lambda2; | ||
auto model = ( | ||
lambda1 |= ppl::normal(0.0, 10.0), | ||
lambda2 |= ppl::normal(0.0, 10.0), | ||
y |= ppl::normal(lambda1 + lambda2, 1.0) | ||
); | ||
|
||
for (int i = 0; i < 100; i++) { | ||
y.observe(n(gen)); | ||
} | ||
|
||
std::array<double, 1000> l1_storage, l2_storage; | ||
lambda1.set_storage(l1_storage.data()); | ||
lambda2.set_storage(l2_storage.data()); | ||
|
||
for (auto _ : state) { | ||
ppl::nuts(model, 1000, 1000, 1000); | ||
} | ||
} | ||
|
||
BENCHMARK(BM_NormalTwoPrior); | ||
|
||
} // namespace ppl |
This file contains 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,30 @@ | ||
import pystan | ||
import numpy as np | ||
|
||
cool_code = """ | ||
data { | ||
int N; | ||
real y[N]; | ||
} | ||
parameters { | ||
real lambda1; | ||
real lambda2; | ||
} | ||
transformed parameters { | ||
real mu; | ||
mu = lambda1 + lambda2; | ||
} | ||
model { | ||
lambda1 ~ normal(0, 10); | ||
lambda2 ~ normal(0, 10); | ||
y ~ normal(mu, 1); | ||
} | ||
""" | ||
|
||
N = 100 | ||
y = np.random.normal(size = N) | ||
cool_dat = { 'N' : N, 'y' : y } | ||
|
||
sm = pystan.StanModel(model_code=cool_code) | ||
fit = sm.sampling(data=cool_dat, chains=1) | ||
print(fit) |
This file contains 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 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