All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
log1m_exp.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_REV_SCAL_FUN_LOG1M_EXP_HPP
#define STAN_MATH_REV_SCAL_FUN_LOG1M_EXP_HPP
#include <stan/math/rev/core.hpp>
#include <stan/math/prim/scal/fun/log1m_exp.hpp>
#include <stan/math/rev/scal/fun/calculate_chain.hpp>
#include <cmath>
#ifdef _MSC_VER
#include <boost/math/special_functions/expm1.hpp>
using boost::math::expm1;
#endif
namespace stan {
namespace math {
namespace {
class log1m_exp_v_vari : public op_v_vari {
public:
explicit log1m_exp_v_vari(vari* avi) :
op_v_vari(stan::math::log1m_exp(avi->val_),
avi) {
}
void chain() {
// derivative of
// log(1-exp(x)) = -exp(x)/(1-exp(x))
// = -1/(exp(-x)-1)
// = -1/expm1(-x)
avi_->adj_ -= adj_ / ::expm1(-(avi_->val_));
}
};
}
inline var log1m_exp(const stan::math::var& a) {
return var(new log1m_exp_v_vari(a.vi_));
}
}
}
#endif
core.hpp
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
stan::math::expm1
fvar< T > expm1(const fvar< T > &x)
Definition: expm1.hpp:12
stan::math::log1m_exp
fvar< T > log1m_exp(const fvar< T > &x)
Definition: log1m_exp.hpp:16
log1m_exp.hpp
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:44
calculate_chain.hpp

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