Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

Samples Class Reference

#include <integrator.h>

Inheritance diagram for Samples:

Inheritance graph
[legend]
Collaboration diagram for Samples:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Samples ()
void newPoint (double val)
int cnt () const
double sum () const
double mean () const
double variance () const
void reset ()
int command (int argc, const char *const *argv)

Protected Attributes

int cnt_
double sum_
double sqsum_

Constructor & Destructor Documentation

Samples::Samples  )  [inline]
 

Definition at line 57 of file integrator.h.

References cnt_, sqsum_, and sum_.

00057 : cnt_(0), sum_(0.0), sqsum_(0.0) { }


Member Function Documentation

int Samples::cnt  )  const [inline]
 

Definition at line 64 of file integrator.h.

References cnt_.

Referenced by command().

00064 { return (cnt_); }

int Samples::command int  argc,
const char *const *  argv
 

Definition at line 102 of file integrator.cc.

References cnt(), cnt_, mean(), newPoint(), reset(), and variance().

00103 {
00104         if (argc == 2) {
00105                 if (strcmp(argv[1], "mean") == 0) {
00106                         if (cnt_ > 0) {
00107                                 Tcl::instance().resultf("%g", mean());
00108                                 return (TCL_OK);
00109                         }
00110                         Tcl::instance().resultf("tried to take mean with no sample points");
00111                         return (TCL_ERROR);
00112                 }
00113                 if (strcmp(argv[1], "cnt") == 0) {
00114                         Tcl::instance().resultf("%u", cnt());
00115                         return (TCL_OK);
00116                 }
00117                 if (strcmp(argv[1], "variance") == 0) {
00118                         if (cnt_ == 1) {
00119                                 Tcl::instance().resultf("0.0");
00120                                 return (TCL_OK);
00121                         }
00122                         if (cnt_ > 2) {
00123                                 Tcl::instance().resultf("%g", variance());
00124                                 return (TCL_OK);
00125                         }
00126                         return (TCL_ERROR);
00127                 }
00128                 if (strcmp(argv[1], "reset") == 0) {
00129                         reset();
00130                         return (TCL_OK);
00131                 }
00132         } else if ( argc == 3 ) {
00133                 if ( strcmp(argv[1],"newpoint") == 0 ) {
00134                         double x = atof(argv[2]);
00135                         newPoint(x);
00136                         return (TCL_OK);
00137                 }
00138         }
00139         return (TclObject::command(argc, argv));
00140 }

Here is the call graph for this function:

double Samples::mean  )  const [inline]
 

Definition at line 66 of file integrator.h.

References cnt_, and sum_.

Referenced by command(), and variance().

00066                             {
00067                 if (cnt_)
00068                         return (sum_ / cnt_);
00069                 return sum_; // yes, that is 0.0...
00070         }

void Samples::newPoint double  val  )  [inline]
 

Definition at line 58 of file integrator.h.

References cnt_, sqsum_, and sum_.

Referenced by command(), QueueMonitorCompat::out(), and QueueMonitor::out().

00058                                   {
00059                 cnt_++;
00060                 sum_ += val;
00061                 val *= val;
00062                 sqsum_ += val;
00063         }

void Samples::reset  )  [inline]
 

Definition at line 77 of file integrator.h.

References cnt_, sqsum_, and sum_.

Referenced by command().

00077 { cnt_ = 0; sum_ = sqsum_ = 0.0; }

double Samples::sum  )  const [inline]
 

Definition at line 65 of file integrator.h.

References sum_.

00065 { return (sum_); }

double Samples::variance  )  const [inline]
 

Definition at line 71 of file integrator.h.

References cnt_, mean(), sqsum_, and sum_.

Referenced by command().

00071                                 {
00072                 // use cnt_-1 degrees of freedom
00073                 if (cnt_ > 1)
00074                         return ((sqsum_ - mean() * sum_) / (cnt_ - 1));
00075                 return 0.0;
00076         }

Here is the call graph for this function:


Member Data Documentation

int Samples::cnt_ [protected]
 

Definition at line 80 of file integrator.h.

Referenced by cnt(), command(), mean(), newPoint(), reset(), Samples(), and variance().

double Samples::sqsum_ [protected]
 

Definition at line 82 of file integrator.h.

Referenced by newPoint(), reset(), Samples(), and variance().

double Samples::sum_ [protected]
 

Definition at line 81 of file integrator.h.

Referenced by mean(), newPoint(), reset(), Samples(), sum(), and variance().


The documentation for this class was generated from the following files:
Generated on Tue Apr 20 13:20:06 2004 for NS2.26SourcesOriginal by doxygen 1.3.3