All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
sd.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_FUN_SD_HPP
#define STAN_MATH_PRIM_MAT_FUN_SD_HPP
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/fun/variance.hpp>
#include <stan/math/prim/scal/err/check_nonzero_size.hpp>
#include <boost/math/tools/promotion.hpp>
#include <vector>
namespace stan {
namespace math {
template <typename T>
inline
typename boost::math::tools::promote_args<T>::type
sd(const std::vector<T>& v) {
stan::math::check_nonzero_size("sd", "v", v);
if (v.size() == 1) return 0.0;
return sqrt(variance(v));
}
template <typename T, int R, int C>
inline
typename boost::math::tools::promote_args<T>::type
sd(const Eigen::Matrix<T, R, C>& m) {
// FIXME: redundant with test in variance; second line saves sqrt
stan::math::check_nonzero_size("sd", "m", m);
if (m.size() == 1) return 0.0;
return sqrt(variance(m));
}
}
}
#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.