| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
sd.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_SD_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_SD_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/mat/fun/variance.hpp>
6 #include <stan/math/prim/scal/err/check_nonzero_size.hpp>
7 #include <boost/math/tools/promotion.hpp>
8 #include <vector>
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", "v", v);
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", "m", m);
40 if (m.size() == 1) return 0.0;
41 return sqrt(variance(m));
42 }
43
44 }
45 }
46 #endif
stan::math::sqrt
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:15
variance.hpp
stan::math::check_nonzero_size
bool check_nonzero_size(const char *function, const char *name, const T_y &y)
Return true if the specified matrix/vector is of non-zero size.
Definition: check_nonzero_size.hpp:31
stan::math::sd
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
stan::math::variance
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
Eigen.hpp
check_nonzero_size.hpp

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