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

autocorr Class Reference

Calculate the autocorrelation function for a vector. More...

#include <autocorr.h>

List of all members.

Public Methods

 autocorr (double lim=0.01, size_t numPts=32)
 ~autocorr ()
void ACF (const double *v, const size_t N, acorrInfo &info)
 Calculate the autocorrelation function. More...


Private Methods

 autocorr (const autocorr &rhs)
void acorrSlope (acorrInfo &info)
 Calculate the slope the the log of the autocorrelation curve. More...


Private Attributes

const double limit_
const size_t numPoints_


Detailed Description

Calculate the autocorrelation function for a vector.

Copyright and Use

You may use this source code without limitation and without fee as long as you include:

This software was written and is copyrighted by Ian Kaplan, Bear Products International, www.bearcave.com, 2001.

This software is provided "as is", without any warranty or claim as to its usefulness. Anyone who uses this source code uses it at their own risk. Nor is any support provided by Ian Kaplan and Bear Products International.

Please send any bug fixes or suggested source changes to:

     iank@bearcave.com

Definition at line 37 of file autocorr.h.


Constructor & Destructor Documentation

autocorr::autocorr ( const autocorr & rhs ) [private]
 

autocorr::autocorr ( double lim = 0.01,
size_t numPts = 32 ) [inline]
 

Definition at line 76 of file autocorr.h.

00076                                                     : limit_(lim), 
00077                                                       numPoints_(numPts) {}

autocorr::~autocorr ( ) [inline]
 

Definition at line 78 of file autocorr.h.

00078 {}


Member Function Documentation

void autocorr::ACF ( const double * v,
const size_t N,
acorrInfo & info )
 

Calculate the autocorrelation function.

Definition at line 50 of file autocorr.cpp.

00053 {
00054   if (! info.points().empty() ) {
00055     info.points().clear();
00056   }
00057 
00058   // The devMean array will contain the deviation from the mean.
00059   // That is, v[i] - mean(v).
00060   double *devMean = new double[ N ];
00061   
00062   double sum;
00063   size_t i;
00064 
00065   // Calculate the mean and copy the vector v, into devMean
00066   sum = 0;
00067   for (i = 0; i < N; i++) {
00068     sum = sum + v[i];
00069     devMean[i] = v[i];
00070   }
00071   double mean = sum / static_cast<double>(N);
00072 
00073   // Compute the values for the devMean array.  Also calculate the
00074   // denominator for the autocorrelation function.
00075   sum = 0;
00076   for (i = 0; i < N; i++) {
00077     devMean[i] = devMean[i] - mean;
00078     sum = sum + (devMean[i]*devMean[i]);
00079   }
00080   double denom = sum / static_cast<double>(N);
00081 
00082   // Calculate a std::vector of values which will make up
00083   // the autocorrelation function.
00084   double cor = 1.0;
00085   for (size_t shift = 1; shift <= numPoints_ && cor > limit_; shift++) {
00086     info.points().push_back( cor );
00087     size_t n = N - shift;
00088     sum = 0.0;
00089     for (i = 0; i < n; i++) {
00090       sum = sum + (devMean[i] * devMean[i+shift]);
00091     }
00092     double numerator = sum / static_cast<double>(n)
00093     cor = numerator / denom;
00094   }
00095 
00096   // calculate the log/log slope of the autocorrelation
00097   acorrSlope( info );
00098 
00099   delete [] m;
00100 } // ACF

void autocorr::acorrSlope ( acorrInfo & info ) [private]
 

Calculate the slope the the log of the autocorrelation curve.

Autocorrelation is one measure for long memory (long range dependence) in a data set. The idea behind implementing this function was that the slope of the log/log plot of the autocorrelation curve could be compared for various data sets.

The Hurst exponent provides another measure for long memory processes. My original idea was to use the slope of the log/log ACF as a comparision for the various Hurst values. As it turned out, the slope of the ACF was not a very useful metric since the slopes did not differ much for various Hurst exponents

Definition at line 27 of file autocorr.cpp.

Referenced by ACF().

00028 {
00029 
00030   const size_t len = info.points().size();
00031   if (len > 0) {
00032     lregress::lineInfo regressInfo;
00033     lregress lr;
00034     vector<lregress::point> regressPoints;
00035     for (size_t i = 0; i < len; i++) {
00036       double x = log(i+1);
00037       double y = log((info.points())[i]);
00038       regressPoints.push_back( lregress::point(x,y) );
00039     }
00040     lr.lr( regressPoints, regressInfo );
00041     info.slope( regressInfo.slope() );
00042     info.slopeErr( regressInfo.slopeErr() );
00043   }
00044 } // acorrSlope


Member Data Documentation

const double autocorr::limit_ [private]
 

Definition at line 42 of file autocorr.h.

const size_t autocorr::numPoints_ [private]
 

Definition at line 44 of file autocorr.h.


The documentation for this class was generated from the following files:
Generated at Tue May 27 21:56:17 2003 for Wavelet compression, determinism and time series forecasting by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001