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

pdf.cpp

Go to the documentation of this file.
00001 
00002 #include <stdio.h>
00003 #include "pdf.h"
00004 
00005 
00006 void pdf::normalize( double *norm, const double *v, const size_t N )
00007 {
00008   double sum = 0;
00009   size_t i;
00010   for (i = 0; i < N; i++) {
00011     sum = sum + v[i];
00012   }
00013   double mean = 0;
00014   if (sum != 0) {
00015     double mean = sum / N;
00016   }
00017   for (i = 0; i < N; i++)
00018     norm[i] = v[i] - mean;
00019 } // normalize
00020 
00021 
00022 
00023 double pdf::pdf_stddev( const double *v, const size_t N )
00024 {
00025   double pdf_sigma = 0.0;
00026   if (v != 0 && N != 0) {
00027     // On average, 4 elements per bin
00028     // const size_t num_bins = N >> 2;
00029     const size_t num_bins = 64;
00030     histogram::bin_vec binz( num_bins );
00031     histogram histo;
00032 
00033     histo.calculate( v, N, binz );
00034     double *freq = new double[ num_bins ];
00035 
00036     // calculate the PDF from the integer frequency counts
00037     for (size_t i = 0; i < num_bins; i++) {
00038       freq[i] = 0.0;
00039       size_t count = static_cast<size_t>( binz[i] );
00040       double val = 0.0;
00041       if (count > 0) {
00042         freq[i] = static_cast<double>(count)/static_cast<double>(N);
00043         val = freq[i];
00044       }
00045       // printf("%2d %9.6f\n", i, val );
00046     }
00047     // printf("\n\n");
00048 
00049     double *norm = new double[ num_bins ];
00050 
00051     normalize(norm, freq, num_bins);
00052 
00053     stddev sd;
00054     pdf_sigma = sd.sd( norm, num_bins );
00055 
00056     delete [] norm;
00057     delete [] freq;
00058   }
00059   return pdf_sigma;
00060 } // pdf

Generated at Tue May 27 21:56:16 2003 for Wavelet compression, determinism and time series forecasting by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001