Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bbbales2
bbbales2 / adj_jac_apply_benchmark_test.cpp
Last active September 4, 2018 14:17
adj_jac_apply additiion benchmarks
#include <stan/math/rev/core.hpp>
#include <test/unit/math/rev/mat/util.hpp>
#include <gtest/gtest.h>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <vector>
#include <chrono>
namespace stan {
@bbbales2
bbbales2 / solve_functor_test.cpp
Last active September 4, 2018 17:22
Example use of adj_jac_apply to solve Ax = b
#include <stan/math/rev/core.hpp>
#include <test/unit/math/rev/mat/util.hpp>
#include <gtest/gtest.h>
#include <algorithm>
#include <random>
#include <sstream>
#include <tuple>
namespace stan {
namespace math {
@bbbales2
bbbales2 / test_jacobian.cpp
Created September 9, 2017 18:30
File for benchmarking different ways to compute Jacobians
#include <iostream>
#include "stan/math.hpp"
#include "stan/math/fwd/mat.hpp"
using namespace stan::math;
template<typename T1, typename T2>
std::vector<typename stan::return_type<T1, T2>::type > ode(const double& t,
const std::vector<T1>& u,
const std::vector<T2>& D,
@bbbales2
bbbales2 / fwd.cpp
Created September 8, 2017 17:47
Forward mode Jacobian
for(int i = 0; i < y.size(); i++) {
if(i > 0)
y_var[i - 1].d_ = 0.0;
y_var[i].d_ = 1.0;
vector<fvar<double> > dy_dt_var = f_(t, y_var, thetavar, x_, x_int_, msgs_);
if(i == 0) {
for(int j = 0; j < y.size(); j++) {
dy_dt(j) = dy_dt_var[j].val();
}
@bbbales2
bbbales2 / test2.cpp
Created September 7, 2017 22:15
ODE example
// Build with: clang++ -Wall -I . -isystem lib/eigen_3.3.3 -isystem lib/boost_1.64.0 -isystem lib/cvodes_2.9.0/include -std=c++1y -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -Wno-unused-function -Wno-uninitialized -DNO_FPRINTF_OUTPUT -pipe test2.cpp -O3 -o test2 lib/cvodes_2.9.0/lib/libsundials_nvecserial.a lib/cvodes_2.9.0/lib/libsundials_cvodes.a
#include <iostream>
#include "stan/math.hpp"
using namespace stan::math;
// This is a 1D diffusion PDE with a spatially varying diffusion coefficient.
// So if the domain is like this:
// x--o--x--o--x--o--x
// Then diffusion coefficients are defined at the xs and the state is at the o
@bbbales2
bbbales2 / jacobian.py
Created May 23, 2017 17:12
Jacobian adjustment thing
#%%
import matplotlib.pyplot as plt
import pystan
import numpy
model_code = """
data {
int<lower=1> N;
vector[N] y;
@bbbales2
bbbales2 / badfit.py
Created May 23, 2017 15:32
Comparison of lots of data vs. not much data for a bad fit
#%%
import matplotlib.pyplot as plt
import pystan
import numpy
model_code = """
data {
int<lower=1> N; // Number of single samples
vector[N] t;
@bbbales2
bbbales2 / test.out
Created April 22, 2017 03:14
Failing to build stan-math unit tests
bbales2@frog:~/smath$ make test/unit/math/mix/mat/prob/categorical_test
make: Warning: Archive 'test/libgtest.a' seems to have been created in deterministic mode. 'test/gtest.o' will always be updated. Please consider passing the U flag to ar to avoid the problem.
ar rv test/libgtest.a test/gtest.o
r - test/gtest.o
make: Warning: Archive 'test/libgtest.a' seems to have been created in deterministic mode. 'test/gtest.o' will always be updated. Please consider passing the U flag to ar to avoid the problem.
g++ -I . -isystem lib/eigen_3.2.9 -isystem lib/boost_1.62.0 -isystemlib/cvodes_2.9.0/include -Wall -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DNO_FPRINTF_OUTPUT -pipe -fPIC -c -O3 -DGTEST_USE_OWN_TR1_TUPLE -DGTEST_HAS_PTHREAD=0 -isystem lib/gtest_1.7.0/include -isystem lib/gtest_1.7.0 test/unit/math/mix/mat/prob/categorical_test.cpp -o test/unit/math/mix/mat/prob/categorical_test.o
In file included from ./stan/math/fwd/core.hpp:4:0,
from ./stan/math/mix/mat/fun/t
@bbbales2
bbbales2 / lf2build.log
Last active April 20, 2017 03:24
g++ build log
bbales2@frog:~/stan3$ make test/unit/mcmc/hmc/integrators/impl_leapfrog2
make: Warning: Archive 'test/libgtest.a' seems to have been created in deterministic mode. 'test/gtest.o' will always be updated. Please consider passing the U flag to ar to avoid the problem.
ar rv test/libgtest.a test/gtest.o
r - test/gtest.o
make: Warning: Archive 'test/libgtest.a' seems to have been created in deterministic mode. 'test/gtest.o' will always be updated. Please consider passing the U flag to ar to avoid the problem.
g++ -I src -isystem lib/stan_math/lib/eigen_3.2.9 -isystem lib/stan_math/lib/boost_1.62.0 -isystem lib/stan_math/lib/cvodes_2.9.0/include -isystem lib/stan_math/ -Wall -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DFUSION_MAX_VECTOR_SIZE=12 -DNO_FPRINTF_OUTPUT -pipe -c -O3 -DGTEST_USE_OWN_TR1_TUPLE -DGTEST_HAS_PTHREAD=0 -isystem lib/stan_math/lib/gtest_1.7.0/include -isystem lib/stan_math/lib/gtest_1.7.0 src/test/unit/mcmc/hmc/integrators/impl_leapfrog2_test.cpp -o test/unit/mcmc/
@bbbales2
bbbales2 / glennsstuff.hpp
Last active April 19, 2017 17:12
Glenn's stuff
// Adjusted version of stan-generated cpp code for the calculate_r() function
inline Eigen::Matrix<var, Eigen::Dynamic,1> calculate_r(
const Eigen::Matrix<var, Eigen::Dynamic,1>& lambda,
const std::vector<std::vector<int> >& lambda_select,
const Eigen::Matrix<double, Eigen::Dynamic,Eigen::Dynamic>& M,
const std::vector<std::vector<std::vector<int> > >& ht_select,
const std::vector<std::vector<std::vector<std::vector<int> > > >& ht_gmap,
const std::vector<std::vector<int> >& Ht,
const Eigen::Matrix<double, Eigen::Dynamic,Eigen::Dynamic>& Z,
const std::vector<int>& Z_type,