Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
log_loss.hpp
Go to the documentation of this file.
1 #ifndef __STAN__AGRAD__REV__LOG_LOSS_HPP__
2 #define __STAN__AGRAD__REV__LOG_LOSS_HPP__
3 
4 #include <stan/agrad/rev/var.hpp>
7 
8 namespace stan {
9  namespace agrad {
10 
11  namespace {
12  class binary_log_loss_1_vari : public op_v_vari {
13  public:
14  binary_log_loss_1_vari(vari* avi) :
15  op_v_vari(-std::log(avi->val_),avi) {
16  }
17  void chain() {
18  avi_->adj_ -= adj_ / avi_->val_;
19  }
20  };
21 
22  class binary_log_loss_0_vari : public op_v_vari {
23  public:
24  binary_log_loss_0_vari(vari* avi) :
25  op_v_vari(-stan::math::log1p(-avi->val_),avi) {
26  }
27  void chain() {
28  avi_->adj_ += adj_ / (1.0 - avi_->val_);
29  }
30  };
31  }
32 
48  inline var log_loss(const int& y,
49  const stan::agrad::var& y_hat) {
50  return y == 0
51  ? var(new binary_log_loss_0_vari(y_hat.vi_))
52  : var(new binary_log_loss_1_vari(y_hat.vi_));
53  }
54 
55  }
56 }
57 #endif

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