Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
lgamma.hpp
Go to the documentation of this file.
1 #ifndef __STAN__AGRAD__REV__LGAMMA_HPP__
2 #define __STAN__AGRAD__REV__LGAMMA_HPP__
3 
4 #include <valarray>
5 #include <stan/agrad/rev/var.hpp>
8 #include <boost/math/special_functions/digamma.hpp>
9 #include <boost/math/special_functions/gamma.hpp>
10 
11 namespace stan {
12  namespace agrad {
13 
14  namespace {
15  class lgamma_vari : public op_v_vari {
16  public:
17  lgamma_vari(double value, vari* avi) :
18  op_v_vari(value, avi) {
19  }
20  void chain() {
21  avi_->adj_ += adj_ * boost::math::digamma(avi_->val_);
22  }
23  };
24  }
25 
36  inline var lgamma(const stan::agrad::var& a) {
37  double lgamma_a = boost::math::lgamma(a.val());
38  return var(new lgamma_vari(lgamma_a, a.vi_));
39  }
40 
41  }
42 }
43 #endif

     [ Stan Home Page ] © 2011–2013, Stan Development Team.