fn_stddev.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // 
00007 // This file is part of the Armadillo C++ library.
00008 // It is provided without any warranty of fitness
00009 // for any purpose. You can redistribute this file
00010 // and/or modify it under the terms of the GNU
00011 // Lesser General Public License (LGPL) as published
00012 // by the Free Software Foundation, either version 3
00013 // of the License or (at your option) any later version.
00014 // (see http://www.opensource.org/licenses for more info)
00015 
00016 
00017 //! \addtogroup fn_stddev
00018 //! @{
00019 
00020 
00021 
00022 template<typename T1>
00023 inline
00024 Mat<typename T1::pod_type>
00025 stddev(const Base<typename T1::elem_type,T1>& X, const u32 norm_type = 0, const u32 dim = 0)
00026   {
00027   arma_extra_debug_sigprint();
00028   
00029   typedef typename T1::elem_type  in_eT;
00030   typedef typename T1::pod_type  out_eT;
00031 
00032   const unwrap<T1>      tmp(X.get_ref());
00033   const Mat<in_eT>& A = tmp.M;
00034   
00035   Mat<out_eT> out;
00036   
00037   op_stddev::apply(out, A, norm_type, dim);
00038   
00039   return out;
00040   }
00041 
00042 
00043 
00044 //! Immediate 'find the standard deviation of a row vector' operation
00045 template<typename eT>
00046 inline
00047 arma_warn_unused
00048 typename get_pod_type<eT>::result
00049 stddev(const Row<eT>& A, const u32 norm_type = 0)
00050   {
00051   arma_extra_debug_sigprint();
00052   
00053   arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no elements" );
00054   
00055   return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) );
00056   }
00057 
00058 
00059 
00060 //! Immediate 'find the standard deviation of a column vector' operation
00061 template<typename eT>
00062 inline
00063 arma_warn_unused
00064 typename get_pod_type<eT>::result
00065 stddev(const Col<eT>& A, const u32 norm_type = 0)
00066   {
00067   arma_extra_debug_sigprint();
00068   
00069   arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no elements" );
00070   
00071   return std::sqrt( op_var::direct_var(A.mem, A.n_elem, norm_type) );
00072   }
00073 
00074 
00075 
00076 //! find the standard deviation of a subview_row
00077 template<typename eT>
00078 inline
00079 arma_warn_unused
00080 typename get_pod_type<eT>::result
00081 stddev(const subview_row<eT>& A, const u32 norm_type = 0)
00082   {
00083   arma_extra_debug_sigprint();
00084   
00085   arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no elements" );
00086   
00087   return std::sqrt( op_var::direct_var(A, norm_type) );
00088   }
00089 
00090 
00091 
00092 //! find the standard deviation of a subview_col
00093 template<typename eT>
00094 inline
00095 arma_warn_unused
00096 typename get_pod_type<eT>::result
00097 stddev(const subview_col<eT>& A, const u32 norm_type = 0)
00098   {
00099   arma_extra_debug_sigprint();
00100   
00101   arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no elements" );
00102   
00103   return std::sqrt( op_var::direct_var(A, norm_type) );
00104   }
00105 
00106 
00107 
00108 //! find the standard deviation of a diagview
00109 template<typename eT>
00110 inline
00111 arma_warn_unused
00112 typename get_pod_type<eT>::result
00113 stddev(const diagview<eT>& A, const u32 norm_type = 0)
00114   {
00115   arma_extra_debug_sigprint();
00116   
00117   arma_debug_check( (A.n_elem == 0), "stddev(): given vector has no elements" );
00118   
00119   return std::sqrt( op_var::direct_var(A, norm_type) );
00120   }
00121 
00122 
00123 
00124 //! @}