#ifndef _AUTOCORRELATION_H
#define _AUTOCORRELATION_H
#include <vector>
#include "Types.h"
#include "similarity.h"


template< typename T>
class CAutoCorrelation
{
public:
   CAutoCorrelation(){}
   std::vector<double>   Calculate(const vector<T>& data, const CSimilarity<T>& similarity, const bool bNorm = true) const;
   std::vector<double>   operator()(const vector<T>& data, const CSimilarity<T>& similarity, const bool bNorm = true) const;
protected:
private:
};


template<typename T>
std::vector<double>   CAutoCorrelation<T>::Calculate(const vector<T>& data, const CSimilarity<T>& similarity, const bool bNorm) const
{
   vector<double> ret(.0);
   double sum(.0), norm(.0);
   for(uint i = 0; i<data.size(); ++i){
      sum = 0;
      for(uint j = 0; j<data.size()-i; ++j){
         sum += similarity(data[i+j], data[j]);
         //cout<<data[i+j]<<" "<<data[j]<<endl;
      }
      if(i == 0) norm = sum;
      if(norm>DBL_EPSILON && bNorm) sum/=norm;
      ret.push_back(sum);
   }

   return ret;
}
#endif _AUTOCORRELATION_H