NormalDistribution::NormalDistribution(const Mean& m, const StdDeviation& sigma) : DistributionBase(), mean_(m.value()), stdDev_(sigma.value()) { if(stdDev_ < 0.0) throw runtime_error("NormalDistribution : in ctor, sigma must be positive."); lower_ = mean_ - stdDev_*2; upper_ = mean_ + stdDev_*2; pLower_ = getUntruncatedCDF(lower_); pUpper_ = getUntruncatedCDF(upper_); }
NormalDistribution::NormalDistribution(const Mean& m, const StdDeviation& sigma, double numDeviations) : DistributionBase(), mean_(m.value()), stdDev_(sigma.value()) { if(stdDev_ < 0.0) throw std::runtime_error("NormalDistribution : in ctor, sigma must be positive."); if(numDeviations < 0.0) throw runtime_error("NormalDistribution : in ctor, numDevations must be positive."); lower_ = mean_ - numDeviations*stdDev_; upper_ = mean_ + numDeviations*stdDev_; pLower_ = getUntruncatedCDF(lower_); pUpper_ = getUntruncatedCDF(upper_); }
int main(void) { int array[] = { 10, 2, 3, 34, 3, 4, 45, 99 }; int array_size = sizeof( array ) / sizeof( array[0] ); Mean< int > mean; for ( unsigned int i = 0; i < array_size; ++i ) { mean( array[i] ); } std::cout << "mean: " << mean.value() << std::endl; return 0; }