Skip to content
Prev 7913 / 10988 Next

[Rcpp-devel] RcppBugs - Weibull, Lognormal

Hi, Tony, and thanks Dirk and JL.

The answer is that before alias templates (
http://en.cppreference.com/w/cpp/language/type_alias) each distribution
needed its own class definition and header file.  There was basically a
large amount of overhead in maintaining each distribution.

When the package was changing rapidly, I had to refactor those classes
several times, so it made sense to focus on the design a bit more and get
it stable before I built out all the distribution classes.

Now that we can use alias templates, it is trivial to add more
distributions.  See the examples here:
https://github.com/armstrtw/CppBugs/blob/master/cppbugs/mcmc.distributions.hpp

For instance, now a normal distribution node is declared this way (where
the 2p means 2 parameters):
template <class T,class U,class V> using Normal =
Stochastic2p<T,U,V,normal_logp>;

So, the only thing you really need to supply is the logp function.  If you
want to point me to weibull, I can add it pretty easily.  Or write one and
send it to me.  It needs to be templated, like so:
template<typename T, typename U, typename V>
  double normal_logp(const T& x, const U& mu, const V& tau) {
    return arma::accu(0.5*log_approx(0.5*tau/arma::math::pi()) - 0.5 *
arma::schur(tau, square(x - mu)));
  }

If I don't like the wikipedia version, I often consult the pymc
documentation (those guys have done a great job):
http://pymc-devs.github.io/pymc/distributions.html#continuous-distributions

-Whit
On Mon, Aug 11, 2014 at 2:07 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140811/b0de3103/attachment.html>