Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sd.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__MATRIX__SD_HPP
2 #define STAN__MATH__MATRIX__SD_HPP
3 
4 #include <vector>
5 #include <boost/math/tools/promotion.hpp>
9 
10 namespace stan {
11  namespace math {
12 
19  template <typename T>
20  inline
21  typename boost::math::tools::promote_args<T>::type
22  sd(const std::vector<T>& v) {
23  stan::math::check_nonzero_size("sd(%1%)",v,"v",(double*)0);
24  if (v.size() == 1) return 0.0;
25  return sqrt(variance(v));
26  }
27 
34  template <typename T, int R, int C>
35  inline
36  typename boost::math::tools::promote_args<T>::type
37  sd(const Eigen::Matrix<T,R,C>& m) {
38  // FIXME: redundant with test in variance; second line saves sqrt
39  stan::math::check_nonzero_size("sd(%1%)",m,"m",(double*)0);
40  if (m.size() == 1) return 0.0;
41  return sqrt(variance(m));
42  }
43 
44  }
45 }
46 #endif
boost::math::tools::promote_args< T >::type sd(const std::vector< T > &v)
Returns the unbiased sample standard deviation of the coefficients in the specified column vector...
Definition: sd.hpp:22
boost::math::tools::promote_args< T >::type variance(const std::vector< T > &v)
Returns the sample variance (divide by length - 1) of the coefficients in the specified standard vect...
Definition: variance.hpp:24
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:15
bool check_nonzero_size(const char *function, const T_y &y, const char *name, T_result *result)
Return true if the specified matrix/vector is of non-zero size.

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