00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef ETIRM_DISCRETENORMALDIST_H_
00020 #define ETIRM_DISCRETENORMALDIST_H_
00021
00022 #ifdef ETIRM_NO_DIR_PREFIX
00023 #include "etirmtypes.h"
00024 #else
00025 #include "etirm/etirmtypes.h"
00026 #endif
00027
00028 #include <cmath>
00029
00030
00031 #ifdef BOOST_NO_STDC_NAMESPACE
00032 namespace std {using ::exp;}
00033 #endif
00034
00035 namespace etirm
00036 {
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 template<class PI, class WI>
00056 void DiscreteNormalDist(int nQuad, double minPoint, double maxPoint, PI ipoints,
00057 WI iweights, double mean = 0.0, double sd = 1.0)
00058 {
00059 int i;
00060
00061 if ((maxPoint-minPoint) <= 0.0 || minPoint > mean || maxPoint < mean)
00062 throw InvalidArgument("Invalid minimum and maximum points", "DiscreteNormalDist");
00063
00064 double incr = (maxPoint-minPoint) / (nQuad-1.0);
00065
00066 PI points = ipoints;
00067 WI weights = iweights;
00068 double theta = minPoint;
00069 double sum = 0.0;
00070 for (i=nQuad; i--; ++points, ++weights)
00071 {
00072 *points = (theta - mean) / sd;
00073 *weights = std::exp(-0.5 * theta * theta);
00074 sum += *weights;
00075 theta += incr;
00076 }
00077
00078
00079 weights = iweights;
00080 for (i=nQuad; i--; ++weights)
00081 {
00082 *weights /= sum;
00083 }
00084
00085 }
00086
00087 }
00088
00089 #endif // ETIRM_DISCRETENORMALDIST_H_