Skip to content

Instantly share code, notes, and snippets.

@bbbales2
bbbales2 / dump.ecoli
Created May 13, 2014 17:10
Dump of chemcell ecoli example
ITEM: TIMESTEP
1000
ITEM: NUMBER OF ATOMS
38
ITEM: BOX BOUNDS
0 2.801
0 1.001
0 1.001
ITEM: ATOMS
892916343 5 0.188849 0.248032 0.763223
@bbbales2
bbbales2 / lognormal.py
Last active April 16, 2017 16:29
Log normal sampling
import pystan
import numpy
import matplotlib.pyplot as plt
y = numpy.random.lognormal(mean = 0.7, sigma = 1.0, size = 5)
# Both of these models produce the same results
model_code = """
data {
int<lower=1> N;
@bbbales2
bbbales2 / adjustment.py
Last active April 16, 2017 20:36
Constrain sigma to be [0.0, inf)
import pystan
import numpy
import matplotlib.pyplot as plt
# We gotta only have a few datapoints. Too much data and the mistake isn't visible
y = numpy.random.lognormal(mean = 0.7, sigma = 1.0, size = 5)
# This model does not have the adjustment and so is incorrect
model_code = """
data {
@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,
@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 / 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 / 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 / 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 / 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 / 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();
}