diff options
Diffstat (limited to 'src/jtutil/norm.cc')
-rw-r--r-- | src/jtutil/norm.cc | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/jtutil/norm.cc b/src/jtutil/norm.cc index 5c9b699..5ff72a9 100644 --- a/src/jtutil/norm.cc +++ b/src/jtutil/norm.cc @@ -16,12 +16,6 @@ #include "util.hh" -// everything in this file is inside these namespaces -namespace AHFinderDirect - { -namespace jtutil - { - //***************************************************************************** //***************************************************************************** //***************************************************************************** @@ -29,6 +23,8 @@ namespace jtutil // // This function constructs a norm object. // +namespace jtutil + { template <typename fp_t> norm<fp_t>::norm() : N_(0L), @@ -36,12 +32,15 @@ template <typename fp_t> max_abs_value_(0.0), min_abs_value_(0.0), max_value_(0.0), min_value_(0.0) { } + } //***************************************************************************** // // This function resets a norm object to its initial state // +namespace jtutil + { template <typename fp_t> void norm<fp_t>::reset() { @@ -53,12 +52,15 @@ min_abs_value_ = 0.0; max_value_ = 0.0; min_value_ = 0.0; } + } //***************************************************************************** // // This function updates the norms with a new data point x . // +namespace jtutil + { template <typename fp_t> void norm<fp_t>::data(fp_t x) { @@ -74,19 +76,29 @@ max_value_ = (N_ == 0) ? x : jtutil::max(max_value_, x); ++N_; } + } // namespace jtutil:: //****************************************************************************** // // these functions compute the corresponding norms // +namespace jtutil + { template<typename fp_t> fp_t norm<fp_t>::mean() const { return sum_/fp_t(N_); } template<typename fp_t> + fp_t norm<fp_t>::std_dev() const + { + if (is_empty()) return fp_t(0); + return sqrt(jtutil::max(fp_t(0),fp_t(N_)*sum2_-sum_*sum_))/fp_t(N_); + } +template<typename fp_t> fp_t norm<fp_t>::two_norm() const { return sqrt(sum2_); } template<typename fp_t> fp_t norm<fp_t>::rms_norm() const { assert(is_nonempty()); return sqrt(sum2_/fp_t(N_)); } + } // namespace jtutil:: //****************************************************************************** //****************************************************************************** @@ -98,10 +110,3 @@ template<typename fp_t> template class jtutil::norm<float>; template class jtutil::norm<double>; - -//****************************************************************************** -//****************************************************************************** -//****************************************************************************** - - } // namespace jtutil - } // namespace AHFinderDirect |