You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the issue for things that would be nice to get into the manual in the future. Rather than closing this issue, we'll just tick things off as part of the regular round of "next manual" issues.
Regarding the Kalman filter examples, I have examples and fully implemented Kalman filtering (of several flavors: with / without missing values, as batch / sequentially) with backward sampling in the generated quantities block here: https://github.com/jrnold/ssmodels-in-stan. I could probably write up that section.
There's really nothing we can do about such models numerically. What you have to do from a user perspective is use a parameterizations z = y - 1, which can be handled stably because you can represent numbers close to zero well.
parameters { real z; } model { z ~ normal(0,1e-20); }
The problem is that there's still no way to represent y = z + 1 as a real value using double-precision floating-point arithmetic, but you can get close to log(y) by using
Regarding the Kalman filter examples, I have examples and fully implemented Kalman filtering (of several flavors: with / without missing values, as batch / sequentially) with backward sampling in the generated quantities block here: https://github.com/jrnold/ssmodels-in-stan. I could probably write up that section.
From Andrew on stan-dev, an example of a model for the problematic posteriors section:
Next I decided, just for fun, to fit a nonlinear model: y = a_exp(-b_x) + c + error, with N(0,sigma) errors. I simulated some data (x taking on the values between 0 and 23, setting a=.5, b=1/10, c=1, sigma=.2, and I fit it constraining all the parameters to be positive. (In retrospect I’m thinking I should’ve just constrained b and sigma to be positive; constraining a and c made sense in the context of my hypothetical example, but in general it’s poor practice to put in hard constraints unless absolutely necessary.)
I simulated data and fit the model and all was fine. But then I repeated and the fit blew up, I was getting some estimates of b that were either really close to 0 (1e-10, etc) or really high (1e10, etc), I can’t remember which. The point is that there can be instability at the extremes, and I realized the model need a bit of hand-holding. As a kluge I constrained b to be between 1/50 and 1 (which made sense in the context of the example). A hard constraint was ugly but was easy enough to understand. I didn’t want to confuse the class by introducing a normal prior here.
So this second example was a bit of a mess. Which suggests to me that in the manual/book we need to throw in an example to explicitly address instability and constraints. Since, ultimately, this is an inherent difficulty with modeling, it’s not anything to do with Stan in particular.
Add a chapter on using Stan for pure Monte Carlo integration
Computing pi
/**
* Compute the mathematical constant pi by Monte Carlo integration.
*
* First, sample (x,y) uniformly from a square with vertices (-1,1),
* (-1,1), (1,-1), (1,1) by sampling x and y independently from the
* interval (-1,1).
*
* Second, determine if (x,y) lies within the circle circumscribed in
* the square, by testing if (x^2 + y^2 < 1). Then multiply the
* proportion of points inside the circle by the area of the square,
* which is 4.
*
* The posterior mean of the generated quantity pi will compute pi
* to within MC error.
*
* Run with fixed parameter algorithm and zero warmup iterations.
*/
model {
}
generated quantities {
real<lower=-1,upper=1> x;
real<lower=-1,upper=1> y;
real<lower=0,upper=4> pi;
x <- uniform_rng(-1,1);
y <- uniform_rng(-1,1);
pi <- 4 * (x^2 + y^2 < 1);
}
Generalization to volume of hypersphere
/**
* Compute the volume of a hypersphere of a given radius in a
* given number of dimensions by Monte Carlo integration.
*
* The volume will be the mean of the sapled sphere_volume values.
*/
data {
int<lower=1> N;
real<lower=0> r;
}
transformed data {
real cube_volume;
cube_volume <- (2 * r)^N;
}
model {
}
generated quantities {
vector<lower=-1, upper=1>[N] x;
real<lower=0,upper=cube_volume> sphere_volume;
for (n in 1:N)
x[n] <- uniform_rng(-1,1);
sphere_volume <- cube_volume * (dot_self(x) < r);
}
include an example of a spline model from BDA 3 (I still don't understand the description in the book, though, so hopefully someone else can code an example)
add Kalman filter examples (again, this is something I'm not that familiar with, but should be doable in Stan)
review all the recommendations w.r.t. Cholesky factorization to bring them up to current best practice in terms of computational and statistical efficiency
See stan-dev/stan#2273 for a discussion of numerical difficulties with simplexes used as regression coefficients in 5000 dimensions. I added a note to the simplex section of the manual on possible solutions, but going over the example itself would be a nice case study.
There used to be a section in the manual on error and warning messages. It was very incomplete and was removed for 2.18. Add one back in that properly catalogues all the
Activity
bob-carpenter commentedon Jan 22, 2015
Originally from Jeffrey Arnold here: stan-dev/stan#1081 (comment)
Regarding the Kalman filter examples, I have examples and fully implemented Kalman filtering (of several flavors: with / without missing values, as batch / sequentially) with backward sampling in the generated quantities block here: https://github.com/jrnold/ssmodels-in-stan. I could probably write up that section.
bob-carpenter commentedon Jan 22, 2015
half-t(4)).bob-carpenter commentedon Jan 22, 2015
https://ariddell.org/horseshoe-prior-with-stan.html
bob-carpenter commentedon Jan 22, 2015
For example, this model is problematic arithmetically:
and produces
There's really nothing we can do about such models numerically. What you have to do from a user perspective is use a parameterizations
z = y - 1, which can be handled stably because you can represent numbers close to zero well.The problem is that there's still no way to represent
y = z + 1as a real value using double-precision floating-point arithmetic, but you can get close tolog(y)by usingbob-carpenter commentedon Feb 4, 2015
Provide examples of log-mix for the manual mixture section.
bob-carpenter commentedon Feb 4, 2015
From Jeffrey Arnold:
Regarding the Kalman filter examples, I have examples and fully implemented Kalman filtering (of several flavors: with / without missing values, as batch / sequentially) with backward sampling in the generated quantities block here: https://github.com/jrnold/ssmodels-in-stan. I could probably write up that section.
bob-carpenter commentedon Feb 9, 2015
From Andrew on stan-dev, an example of a model for the problematic posteriors section:
Next I decided, just for fun, to fit a nonlinear model: y = a_exp(-b_x) + c + error, with N(0,sigma) errors. I simulated some data (x taking on the values between 0 and 23, setting a=.5, b=1/10, c=1, sigma=.2, and I fit it constraining all the parameters to be positive. (In retrospect I’m thinking I should’ve just constrained b and sigma to be positive; constraining a and c made sense in the context of my hypothetical example, but in general it’s poor practice to put in hard constraints unless absolutely necessary.)
I simulated data and fit the model and all was fine. But then I repeated and the fit blew up, I was getting some estimates of b that were either really close to 0 (1e-10, etc) or really high (1e10, etc), I can’t remember which. The point is that there can be instability at the extremes, and I realized the model need a bit of hand-holding. As a kluge I constrained b to be between 1/50 and 1 (which made sense in the context of the example). A hard constraint was ugly but was easy enough to understand. I didn’t want to confuse the class by introducing a normal prior here.
So this second example was a bit of a mess. Which suggests to me that in the manual/book we need to throw in an example to explicitly address instability and constraints. Since, ultimately, this is an inherent difficulty with modeling, it’s not anything to do with Stan in particular.
bob-carpenter commentedon Feb 14, 2015
Here's what the model should look like, but there's a bug in Stan 2.6 preventing the compilation:
Here's a program that will work, but isn't optimally efficient:
bob-carpenter commentedon Feb 14, 2015
Computing pi
Generalization to volume of hypersphere
bob-carpenter commentedon Feb 17, 2015
bob-carpenter commentedon Feb 17, 2015
bob-carpenter commentedon Feb 17, 2015
bob-carpenter commentedon Mar 6, 2015
bob-carpenter commentedon Mar 6, 2015
27 remaining items
bob-carpenter commentedon Jun 18, 2017
See stan-dev/stan#2273 for a discussion of numerical difficulties with simplexes used as regression coefficients in 5000 dimensions. I added a note to the simplex section of the manual on possible solutions, but going over the example itself would be a nice case study.
bob-carpenter commentedon Nov 9, 2017
I like the idea of defining the Bayesian posterior for R2, defined by @bgoodri in a response on StackOverflow: https://stackoverflow.com/questions/44759319/overall-predictive-power-e-g-r2-for-bayesian-linear-mixed-models
bob-carpenter commentedon Nov 9, 2017
bob-carpenter commentedon Nov 10, 2017
http://discourse.mc-stan.org/t/large-poisson-model-with-individual-effects-is-too-slow/2112/2
I started this in the programming.tex and added the reference, but I can't quite follow what is being reparameterized to what.
bob-carpenter commentedon Jun 10, 2018
There used to be a section in the manual on error and warning messages. It was very incomplete and was removed for 2.18. Add one back in that properly catalogues all the
bob-carpenter commentedon Jun 10, 2018
so
and we can use
csr_matrix_times_vectorfor the multiplies.Initial attempt at documenting new ODE interface (design-doc #19)
Handling review comments (design-doc #19)
Responding to review comments (design-doc #19)
Added missing ode trajectory png file (design-doc #19)
Changed a bunch of 'integrators' to 'solvers' (desing-doc #19)
Added note on generating output at discontinuities and info on choosi…
Merge pull request #213 from stan-dev/feature/variadic-odes