Stan
2.5.0
probability, sampling & optimization
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
stan
agrad
fwd
functions
log_diff_exp.hpp
Go to the documentation of this file.
1
#ifndef STAN__AGRAD__FWD__FUNCTIONS__LOG_DIFF_EXP_HPP
2
#define STAN__AGRAD__FWD__FUNCTIONS__LOG_DIFF_EXP_HPP
3
4
#include <
stan/agrad/fwd/fvar.hpp
>
5
#include <
stan/meta/traits.hpp
>
6
#include <
stan/math/functions/log_diff_exp.hpp
>
7
#include <
stan/math/constants.hpp
>
8
9
namespace
stan{
10
11
namespace
agrad{
12
13
template
<
typename
T>
inline
fvar<T>
14
log_diff_exp
(
const
fvar<T>
& x1,
const
fvar<T>
& x2) {
15
using
stan::math::log_diff_exp
;
16
using
stan::math::NOT_A_NUMBER
;
17
using
std::exp
;
18
if
(x1.
val_
<= x2.
val_
)
19
return
fvar<T>
(
NOT_A_NUMBER
,
NOT_A_NUMBER
);
20
return
fvar<T>
(
log_diff_exp
(x1.
val_
, x2.
val_
),
21
x1.
d_
/ (1 -
exp
(x2.
val_
- x1.
val_
) ) + x2.
d_
/ (1 -
exp
(x1.
val_
- x2.
val_
) ) );
22
}
23
24
template
<
typename
T1,
typename
T2>
inline
fvar<T2>
25
log_diff_exp
(
const
T1& x1,
const
fvar<T2>
& x2) {
26
using
stan::math::log_diff_exp
;
27
using
stan::math::NOT_A_NUMBER
;
28
using
std::exp
;
29
if
(x1 <= x2.
val_
)
30
return
fvar<T2>
(
NOT_A_NUMBER
,
NOT_A_NUMBER
);
31
return
fvar<T2>
(
log_diff_exp
(x1, x2.
val_
),
32
x2.
d_
/ (1 -
exp
(x1 - x2.
val_
)));
33
}
34
35
template
<
typename
T1,
typename
T2>
inline
fvar<T1>
36
log_diff_exp
(
const
fvar<T1>
& x1,
const
T2& x2) {
37
using
stan::math::log_diff_exp
;
38
using
stan::math::NOT_A_NUMBER
;
39
using
std::exp
;
40
if
(x1.
val_
<= x2)
41
return
fvar<T1>
(
NOT_A_NUMBER
,
NOT_A_NUMBER
);
42
return
fvar<T1>
(
log_diff_exp
(x1.
val_
, x2),
43
x1.
d_
/ (1 -
exp
(x2 - x1.
val_
)));
44
}
45
}
46
}
47
#endif
stan::math::log_diff_exp
boost::math::tools::promote_args< T1, T2 >::type log_diff_exp(const T1 x, const T2 y)
The natural logarithm of the difference of the natural exponentiation of x1 and the natural exponenti...
Definition:
log_diff_exp.hpp:49
stan::agrad::log_diff_exp
fvar< T > log_diff_exp(const fvar< T > &x1, const fvar< T > &x2)
Definition:
log_diff_exp.hpp:14
stan::math::NOT_A_NUMBER
const double NOT_A_NUMBER
(Quiet) not-a-number value.
Definition:
constants.hpp:53
stan::agrad::fvar
Definition:
fvar.hpp:13
traits.hpp
log_diff_exp.hpp
fvar.hpp
stan::agrad::fvar::d_
T d_
Definition:
fvar.hpp:16
constants.hpp
stan::agrad::exp
fvar< T > exp(const fvar< T > &x)
Definition:
exp.hpp:16
stan::agrad::fvar::val_
T val_
Definition:
fvar.hpp:15
[
Stan Home Page
]
© 2011–2014, Stan Development Team.