[OpendTect_Developers] Statistics calculation made easier

Satyaki Maitra satyaki at opendtect.org
Tue May 24 10:37:38 CEST 2011


Hi all

Most of us now and then need to do some statistical calculations. So I 
thought it might be useful to share with you about a class which I found 
very handy when I was developing an attribute few days earlier. The 
class is Stats::RunCalc
*(include/Algo/statruncalc.h)*.

To use it you need to do the following steps:

   1. Fill the Stats::RunCalcSetup.
   2. Create the dataset using *addValue(T data,T weight=1)*.
   3. Get the required statistics using the corresponding function.

The Stats::RunCalcSetup should filled up with information about the type 
of statistics you want calculate e.g StdDev, Variance. To set required 
statistics type you need to call *require(Type)* function. The types are 
defined in include/Algo/stattype.h. You can find good example in 
src/uiTools/uihistogramdisplay.cc. You can also set multiple statistics 
type as you can find in the example code.

To create the dataset you can call *addValue(T data,T weight=1)* where 
one can set the weighing factor which is by default set to 1.

To retrieve the result you can call the respective functions ( e.g. 
*stdDev()* for standard deviation, *rms()* for root mean square ).

The  Stats::RunCalc is quite handy if the dataset is fixed. Suppose you 
have a dataset with fixed size which keeps on changing. In that case it 
would mean that either you have to call the *replaceValue(T olddata,T 
newdata,T wt=1*) to change the data set or you have to clear the dataset 
( using *clear()* ) and add Values again. To get rid of this extra step 
there is yet another class the *Stats::WindowedCalc*.

It is constructed like *WindowedCalc( const RunCalcSetup& rcs, int sz )* 
where you need to pass an additional information, the maximum size of 
the dataset. So while adding value to the dataset if  the size gets 
bigger than the maximum size it will remove the first data from the 
dataset. Or in refined words it replaces the values according to first 
in first out policy. So you don't have to remember the values in order 
to replace it. Once the window is full it would be removed 
automatically. This class can be very helpful when you are calculating 
statistics within a window of samples which keeps on changing every time 
( e.g while calculating an attribute with timegate and step-out, each 
time you move on to next sample , you don't need to replace the values 
in dataset ). This saves crucial time in statistics calculation.

Hope this class can be useful for you as well.

Happy Programming
Satyaki

-- 
- Satyaki Maitra
- OpendTect Developer
-
- dGB Earth Sciences
- 304, Gateway Plaza, Hiranandani Gardens,
- Powai, Mumbai 400 076, India
- Phone: +91 22 25704984 , Fax: +91 22 25704977
- Mobile: +91 9930856158
- mailto:satyaki.maitra at opendtect.org
- http://www.opendtect.org






More information about the Developers mailing list