Classes | |
class | op_stddev |
Class for finding the standard deviation. More... | |
Functions | |
template<typename eT > | |
static void | op_stddev::apply (Mat< typename get_pod_type< eT >::result > &out, const Mat< eT > &X, const u32 norm_type, const u32 dim) |
For each row or for each column, find the standard deviation. The result is stored in a dense matrix that has either one column or one row. The dimension for which the standard deviations are found is set via the stddev() function. |
void op_stddev::apply | ( | Mat< typename get_pod_type< eT >::result > & | out, | |
const Mat< eT > & | X, | |||
const u32 | norm_type, | |||
const u32 | dim | |||
) | [inline, static, inherited] |
For each row or for each column, find the standard deviation. The result is stored in a dense matrix that has either one column or one row. The dimension for which the standard deviations are found is set via the stddev() function.
Definition at line 28 of file op_stddev_meat.hpp.
References Mat< eT >::at(), Mat< eT >::colptr(), op_var::direct_var(), podarray< eT >::memptr(), Mat< eT >::n_cols, Mat< eT >::n_elem, Mat< eT >::n_rows, and sqrt().
Referenced by stddev().
00029 { 00030 arma_extra_debug_sigprint(); 00031 00032 arma_debug_check( (X.n_elem == 0), "stddev(): given matrix has no elements" ); 00033 00034 arma_debug_check( (norm_type > 1), "stddev(): incorrect usage. norm_type must be 0 or 1"); 00035 arma_debug_check( (dim > 1), "stddev(): incorrect usage. dim must be 0 or 1" ); 00036 00037 if(dim == 0) 00038 { 00039 arma_extra_debug_print("op_stddev::apply(), dim = 0"); 00040 00041 out.set_size(1, X.n_cols); 00042 00043 for(u32 col=0; col<X.n_cols; ++col) 00044 { 00045 out[col] = std::sqrt( op_var::direct_var( X.colptr(col), X.n_rows, norm_type ) ); 00046 } 00047 } 00048 else 00049 if(dim == 1) 00050 { 00051 arma_extra_debug_print("op_stddev::apply(), dim = 1"); 00052 00053 const u32 n_rows = X.n_rows; 00054 const u32 n_cols = X.n_cols; 00055 00056 out.set_size(n_rows, 1); 00057 00058 podarray<eT> tmp(n_cols); 00059 00060 eT* tmp_mem = tmp.memptr(); 00061 00062 for(u32 row=0; row<n_rows; ++row) 00063 { 00064 for(u32 col=0; col<n_cols; ++col) 00065 { 00066 tmp_mem[col] = X.at(row,col); 00067 } 00068 00069 out[row] = std::sqrt( op_var::direct_var(tmp_mem, n_cols, norm_type) ); 00070 } 00071 00072 } 00073 00074 }