Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
binary_log_loss.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__FUNCTIONS__BINARY_LOG_LOSS_HPP
2 #define STAN__AGRAD__REV__FUNCTIONS__BINARY_LOG_LOSS_HPP
3 
4 #include <valarray>
5 #include <stan/agrad/rev/var.hpp>
9 
10 namespace stan {
11  namespace agrad {
12 
13  namespace {
14  class binary_log_loss_1_vari : public op_v_vari {
15  public:
16  binary_log_loss_1_vari(vari* avi) :
17  op_v_vari(-std::log(avi->val_),avi) {
18  }
19  void chain() {
20  avi_->adj_ -= adj_ / avi_->val_;
21  }
22  };
23 
24  class binary_log_loss_0_vari : public op_v_vari {
25  public:
26  binary_log_loss_0_vari(vari* avi) :
27  op_v_vari(-stan::math::log1p(-avi->val_),avi) {
28  }
29  void chain() {
30  avi_->adj_ += adj_ / (1.0 - avi_->val_);
31  }
32  };
33  }
34 
69  inline var binary_log_loss(const int y, const stan::agrad::var& y_hat) {
70  if (y == 0)
71  return var(new binary_log_loss_0_vari(y_hat.vi_));
72  else
73  return var(new binary_log_loss_1_vari(y_hat.vi_));
74  }
75 
76  }
77 }
78 #endif
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:40
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:27
fvar< T > binary_log_loss(const int y, const fvar< T > &y_hat)
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
fvar< T > log1p(const fvar< T > &x)
Definition: log1p.hpp:16

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