On 11/12/12 5:37 PM, Jiqiang Guo wrote:
> [to stan-dev]
>
> 1. reading csv files of samples in RStan
>
> Currently, no functionality in RStan to do that. I guess I should work on it so maybe in the release after 1.0.4, we
> can have it.
This would be really useful for scalability in R or even
just for running from Stan command line and then
reading into R for later analysis.
> 2. keeping `samples so far'
>
> I do not know now. I have never encounter an error in R of `out of memory`.
Lucky you.
If you use 32-bit R and try to run JAGS models,
you'll run into it fast enough. I rewrote some models in
Stan that took up way less memory than their JAGS counterparts
in R.
Any model that calls iterative solvers on matrices may
take up a lot of memory during sampling the way things are
implemented now. The issue is that we build up the entire
expression tree over the iterations before propagating the
chain rule backwards for calculating gradients. We plan to
make this more efficient by extracting the double values,
calling the iterative algorithsm on those, then partially
evaluating the gradients using all the rules in The Matrix
Cookbook and Magnus and Neudecker's book.
> I do not know how R or OS deals with this
> case. And in the case if it is R calling a C++ function that is running out of memory, I am not sure we can do
> something in R then.
It's going to be handled by process. When R calls the
C function, it's all in the same process, and so sharing
all the memory from the OSes point of view. Thus if you run
R in 32-bit mode, the OS is going to put a low ceiling on
how much memory can be used. A C function called from R
might not be well behaved with respect to R -- it can call its
own malloc() and play havoc with R's memory model.
I don't know how well Rcpp deals with these issues and how
much is up to the user.
You can try something like object.size() in R. memory.profile()
also looks useful.
There may also be extra objects hanging around in the R environment
taking up space that have nothing to do with Stan. R uses
garbage collection, but doesn't appear to do it very well. So
one probably shouldn't use long-running R sessions even if you get
rid of local variables and call gc() to try to clean things up.
> In short, it is difficult. Unless this happens a lot, I would not put the investigation on top
> priority.
We should probably test the scalability to make sure we're
not doing something sub-optimally. If it's a deep issue with
R, I agree that it's not a priority for us to try to fix it!
- Bob