[Rcpp-devel] RcppBugs - Weibull, Lognormal

Whit Armstrong armstrong.whit at gmail.com
Tue Aug 12 02:06:35 CEST 2014


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:

>
> Tony,
>
> On 11 August 2014 at 12:18, tony nwankwo wrote:
> | I must express gratitude to those that built this package.
> | I work in the oil & gas industry and a lot of what we do in Drilling
> follows Weibull, Lognormal distributions. Any particular reason these are
> not included in the cppbugs / rcppbugs ?
>
> You may get a quicker reply if you ask Whit directly. I'll add him as a CC.
>
> Dirk
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140811/b0de3103/attachment.html>


More information about the Rcpp-devel mailing list