aboutsummaryrefslogtreecommitdiff
path: root/src/jtutil
diff options
context:
space:
mode:
authorjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2002-09-03 15:04:28 +0000
committerjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2002-09-03 15:04:28 +0000
commitb7784ccbe8d277877397d342aa5d96d79b8a13d3 (patch)
tree3e94106a54aaefb091767f7eff138d29bb4150ab /src/jtutil
parentb3482ef3124448972e548a02a28274253ca86060 (diff)
add the ability to compute the mean value in my norm class
git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinAnalysis/AHFinderDirect/trunk@699 f88db872-0e4f-0410-b76b-b9085cfa78c5
Diffstat (limited to 'src/jtutil')
-rw-r--r--src/jtutil/norm.cc5
-rw-r--r--src/jtutil/util.hh8
2 files changed, 9 insertions, 4 deletions
diff --git a/src/jtutil/norm.cc b/src/jtutil/norm.cc
index 118225d..2e20327 100644
--- a/src/jtutil/norm.cc
+++ b/src/jtutil/norm.cc
@@ -20,6 +20,7 @@ template <typename fp>
void norm<fp>::data(fp x)
{
++N_;
+sum_ += x;
sum2_ += x*x;
infinity_norm_ = std::max(infinity_norm_, jtutil::abs<fp>(x));
}
@@ -27,10 +28,12 @@ infinity_norm_ = std::max(infinity_norm_, jtutil::abs<fp>(x));
//******************************************************************************
-// get norms
+// get norms etc
namespace jtutil
{
template<typename fp>
+ fp norm<fp>::mean() const { return sum_/fp(N_); }
+template<typename fp>
fp norm<fp>::two_norm() const { return std::sqrt(sum2_); }
template<typename fp>
fp norm<fp>::rms_norm() const
diff --git a/src/jtutil/util.hh b/src/jtutil/util.hh
index 9273ebe..3d91422 100644
--- a/src/jtutil/util.hh
+++ b/src/jtutil/util.hh
@@ -75,13 +75,14 @@ double modulo_reduce(double x, double xmod, double xmin, double xmax);
//******************************************************************************
//
-// this template class computes 2-norms, rms-norms, and/or infinity-norms
+// This template class computes means, 2-norms, rms-norms, and infinity-norms.
//
template <typename fp>
class norm
{
public:
- // get norms
+ // get norms etc
+ fp mean() const;
fp two_norm() const; // sqrt(sum x_i^2)
fp rms_norm() const; // sqrt(average of x_i^2)
fp infinity_norm() const; // max(|x_i|)
@@ -99,7 +100,7 @@ public:
// constructor, destructor
// ... compiler-generated no-op destructor is ok
norm()
- : N_(0), sum2_(0.0), infinity_norm_(0.0)
+ : N_(0), sum_(0.0), sum2_(0.0), infinity_norm_(0.0)
{ }
private:
@@ -111,6 +112,7 @@ private:
private:
int N_; // # of data points
+ fp sum_; // sum(data)
fp sum2_; // sum(data^2)
fp infinity_norm_; // max |data|
};