![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include <WNS/distribution/LogNorm.hpp> 00029 00030 using namespace wns::distribution; 00031 00032 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00033 LogNorm, 00034 Distribution, 00035 "LogNorm", 00036 wns::PyConfigViewCreator); 00037 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00038 LogNorm, 00039 Distribution, 00040 "LogNorm", 00041 wns::distribution::RNGConfigCreator); 00042 00043 /* mean(mu) and standard deviation(sigma) of the underlying normal distribution 00044 are calculated as follows: 00045 mu = log(pow(mean_, 2)/sqrt(pow(std_, 2) + pow(mean_, 2))) 00046 sigma = sqrt(log(1 + pow(std_, 2)/pow(mean_, 2))) 00047 However, mu and sigma are not needed here. The boost lognormal distribution 00048 takes mean and std of the lognormal distribution as parameters 00049 and NOT mu and sigma of the underlying normal distribution as it is done usually. 00050 -Sources: 00051 1. http://www.boost.org/doc/libs/1_39_0/libs/random/random-distributions.html 00052 2. http://www.boost.org/doc/libs/1_39_0/boost/random/lognormal_distribution.hpp 00053 */ 00054 LogNorm::LogNorm(double mean, double std, wns::rng::RNGen* rng) : 00055 Distribution(rng), 00056 mean_(mean), 00057 std_(std), 00058 variance_(pow(std_, 2)), 00059 dis_(getRNG(), LogNormalDist::distribution_type(mean_, std_)) 00060 { 00061 if (mean_ == 0.0) 00062 { 00063 assure(false, "LogNorm: Mean must not be zero!"); 00064 } 00065 00066 if (variance_ < 0.0) 00067 { 00068 assure(false, "LogNorm: Variance must not be negative!"); 00069 } 00070 } 00071 00072 LogNorm::LogNorm(const pyconfig::View& config) : 00073 Distribution(), 00074 mean_(config.get<double>("mean")), 00075 std_(config.get<double>("std")), 00076 variance_(pow(std_, 2)), 00077 dis_(getRNG(), LogNormalDist::distribution_type(mean_, std_)) 00078 { 00079 } 00080 00081 LogNorm::LogNorm(wns::rng::RNGen* rng, const pyconfig::View& config) : 00082 Distribution(rng), 00083 mean_(config.get<double>("mean")), 00084 std_(config.get<double>("std")), 00085 variance_(pow(std_, 2)), 00086 dis_(getRNG(), LogNormalDist::distribution_type(mean_, std_)) 00087 { 00088 } 00089 00090 LogNorm::~LogNorm() 00091 { 00092 } 00093 00094 00095 double 00096 LogNorm::operator()() 00097 { 00098 return dis_(); 00099 } 00100 00101 double 00102 LogNorm::getMean() const 00103 { 00104 return mean_; 00105 } 00106 00107 00108 std::string 00109 LogNorm::paramString() const 00110 { 00111 std::ostringstream tmp; 00112 tmp << "LogNorm(mean = " << mean_ << ", variance = " << variance_ << ")"; 00113 return tmp.str(); 00114 }
1.5.5