I just want to install Stan so I can call its routines via my own C/C++ programs. Is this possible? I don’t see any documentation on how to do library installation of the C++ Stan Library itself anywhere.
It’s mostly a header library. Here’s an example file that should produce something:
#include <stan/math.hpp>
#include <iostream>
using namespace stan::math;
int main(int argc, char **argv) {
var a = 2.0;
var b = a * a;
b.grad();
std::cout << a.adj() << std::endl;
}
Put that somewhere on your hard drive. To figure out what flags you need to compile it, start the tests compiling (./runTests.py test/unit) and just steal the necessary includes paths from them.
There’s probably a document around here haha but I’ve forgotten if there is.
The extra flags you’ll need to steal from the tests are probably just paths to Stan headers, paths to the internal boost, eigen, and cvodes libraries, and hopefully that’s it.
If you end up using Cvodes stuff you’ll need to link against that as well. Just ask if something gives you an error.
Just realized this was a question about Stan itself… I was thinking Stan-math (where all the autodiff lives). Stan itself (where all the samplers live) I do not know about, but were you looking for autodiff or samplers?
Stan is basically header only (except for CVODES) so there is nothing really to install. You don’t need the parser, but you need everything else that comes with CmdStan, so just do
git clone https://github.com/stan-dev/cmdstan.git
make stan-update
make examples/bernoulli/bernoulli
Then write a C++ file that has the same methods as that in examples/bernoulli/bernoulli.hpp but the internals of all the methods would be different depending on what your model is. That is going to be very tedious to get right.
The stanc translator needs to be compiled. That’s the thing that converts Stan programs to C++ classes. The algorithms (like samplers, ADVI and optimization) have varying degrees of our compiled model concept built in.