|
Boost : |
From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-04-11 06:20:03
I have used the stats example with an interval<double> type AND with TW's cyclic
buffer (I have trying the updated yclic buffer on my TODO list!)
For example:
Count = 5, mean = [5.99999,6]
sd = [1.58113,1.58114], variance = [2.49999,2.5], Xsqrbar = [38,38]
This has enormous potential if the input interval values are the uncertainty of
the measurement because it allows effortless propagation of the uncertainty
through the calculations.
Code snippet:
typedef boost::numeric::interval<double> I;
cyclic_array<I, max_buffer_size> cb;// Container to hold interval values.
Stat<I, size_t> D;
for (int i = 1; i < 9; i++)
{ // Simulate new measurements coming in.
cb.push_back(I(i)); // New measurements: 1., 2. .. 8.
show_cbi(cb, cout); // Current state of cyclic buffer.
D.Reset();
D.Compute(cb.begin(), cb.end()); // Iterate over cyclic buffer.
// Triggers calculation of mean, sd etc.
cout << "Count = " << D.Count()<< ", mean = " << D.Mean()
<< ", sd = " << D.StdDev() << ", variance = " << D.Var()
<< ", Xsqrbar = " << D.XsqrBar() << endl;
} // for i
BUT
I had some trouble with the abs function, but eventually found that simply
adding
using namespace boost::numeric;
BEFORE
#include "stats.hpp"
works as (I should have) expected.
I also had to change several statements dividing intervals by integers because
there are no automatic conversion to interval from integer (though there is from
double etc). So "T mean/count" must become "mean/T(count)"
Paul
Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
Mobile mailto:pabristow_at_[hidden]
mailto:pbristow_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk