1 #ifndef STAN_MATH_REV_MAT_FUN_VARIANCE_HPP 2 #define STAN_MATH_REV_MAT_FUN_VARIANCE_HPP 17 for (
size_t i = 0; i <
size; ++i)
18 varis[i] = dtrs[i].vi_;
20 for (
size_t i = 0; i <
size; ++i)
21 sum += dtrs[i].vi_->
val_;
22 double mean = sum / size;
23 double sum_of_squares = 0;
24 double reciprocal_size_m1 = 1.0 / (size - 1);
25 double two_over_size_m1 = 2.0 * reciprocal_size_m1;
28 for (
size_t i = 0; i <
size; ++i) {
30 sum_of_squares += diff * diff;
31 partials[i] = two_over_size_m1 * diff;
33 double variance = sum_of_squares * reciprocal_size_m1;
63 template <
int R,
int C>
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
The variable implementation base class.
static STAN_THREADS_DEF AutodiffStackStorage * instance_
Independent (input) and dependent (output) variables for gradients.
A var implementation that stores the daughter variable implementation pointers and the partial deriva...
const double val_
The value of this variable.
var calc_variance(size_t size, const var *dtrs)
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...
vari * vi_
Pointer to the implementation of this variable.
boost::math::tools::promote_args< T >::type mean(const std::vector< T > &v)
Returns the sample mean (i.e., average) of the coefficients in the specified standard vector...
T * alloc_array(size_t n)
Allocate an array on the arena of the specified size to hold values of the specified template paramet...
int size(const std::vector< T > &x)
Return the size of the specified standard vector.