Stan Math Library  2.10.0
reverse mode automatic differentiation
inverse_softmax.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_INVERSE_SOFTMAX_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_INVERSE_SOFTMAX_HPP
3 
4 #include <boost/math/tools/promotion.hpp>
5 #include <boost/throw_exception.hpp>
6 #include <stdexcept>
7 
8 namespace stan {
9  namespace math {
10 
33  template <typename Vector>
34  void inverse_softmax(const Vector& simplex, Vector& y) {
35  using std::log;
36  if (simplex.size() != y.size())
37  BOOST_THROW_EXCEPTION(std::invalid_argument
38  ("simplex.size() != y.size()"));
39  for (size_t i = 0; i < simplex.size(); ++i)
40  y[i] = log(simplex[i]);
41  }
42 
43  }
44 }
45 
46 #endif
void inverse_softmax(const Vector &simplex, Vector &y)
Writes the inverse softmax of the simplex argument into the second argument.
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
void invalid_argument(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw an invalid_argument exception with a consistently formatted message.

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