sampledFunctions.h

Go to the documentation of this file.
00001 
00016 #ifndef _DLRNUMERIC_SAMPLEDFUNCTIONS_H_
00017 #define _DLRNUMERIC_SAMPLEDFUNCTIONS_H_
00018 
00019 #include <dlrNumeric/array1D.h>
00020 
00021 namespace dlr {
00022 
00023   namespace numeric {
00024 
00045     template <class TYPE>
00046     Array1D<TYPE>
00047     getGaussian1D(size_t size,
00048                   double sigma = 0.0,
00049                   bool normalize = false);
00050 
00051   } // namespace numeric
00052   
00053 } // namespace dlr
00054 
00055 
00056 /* =============================================================== */
00057 /* Implementation follows.                                         */
00058 /* =============================================================== */
00059 
00060 
00061 #include <cmath>
00062 
00063 namespace dlr {
00064 
00065   namespace numeric {
00066 
00067     // This function returns an array in which the elements are
00068     // sampled from a 1D Gaussian.
00069     Array1D<TYPE>
00070     getGaussian1D(size_t size, double sigma, bool normalize)
00071     {
00072       Array1D<TYPE> result(size);
00073       Gaussian1DFunctor functor(sigma);
00074       double x = (1.0 - static_cast<double>(size))/2.0;
00075       for(size_t index0 = 0; index0 < size; ++index0) {
00076         result[index0] = functor(x);
00077         x += 1.0;
00078       }
00079       if(normalize) {
00080         result /= sum(result);
00081       }
00082       return result;
00083     }
00084     
00085   } // namespace numeric
00086   
00087 } // namespace dlr
00088 
00089 #endif /* #ifndef _DLRNUMERIC_SAMPLEDFUNCTIONS_H_ */

Generated on Mon Jul 9 20:34:03 2007 for dlrLibs Utility Libraries by  doxygen 1.5.2