User Manual, Developers Guide and API Documentation

Pareto.cpp

Go to the documentation of this file.
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. 16, 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/Pareto.hpp>
00029 
00030 #include <limits>
00031 
00032 
00033 using namespace wns::distribution;
00034 
00035 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00036     Pareto,
00037     Distribution,
00038     "Pareto",
00039     wns::PyConfigViewCreator);
00040 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00041     Pareto,
00042     Distribution,
00043     "Pareto",
00044     wns::distribution::RNGConfigCreator);
00045 
00046 Pareto::Pareto(double shapeA, double scaleB, wns::rng::RNGen* rng) :
00047     Distribution(rng),
00048     shapeParamA_(shapeA),
00049     scaleParamB_(scaleB),
00050     dis_(getRNG())
00051 {
00052     assert(shapeParamA_ > 0.0);
00053     assert(scaleParamB_ >= 0.0);
00054 }
00055 
00056 Pareto::Pareto(const pyconfig::View& config) :
00057     Distribution(),
00058     shapeParamA_(config.get<double>("shapeA")),
00059     scaleParamB_(config.get<double>("scaleB")),
00060     dis_(getRNG())
00061 {
00062     assert(shapeParamA_ > 0.0);
00063     assert(scaleParamB_ >= 0.0);
00064 }
00065 
00066 Pareto::Pareto(wns::rng::RNGen* rng, const pyconfig::View& config) :
00067     Distribution(rng),
00068     shapeParamA_(config.get<double>("shapeA")),
00069     scaleParamB_(config.get<double>("scaleB")),
00070     dis_(getRNG())
00071 {
00072     assert(shapeParamA_ > 0.0);
00073     assert(scaleParamB_ >= 0.0);
00074 }
00075 
00076 
00077 Pareto::~Pareto()
00078 {
00079 }
00080 
00081 
00082 double
00083 Pareto::operator()()
00084 {
00085     double f = 0.0;
00086     double x = scaleParamB_;
00087     // Avoid endless loops
00088     unsigned long int max_num_loops = 1000; 
00089     
00090     while (max_num_loops--)
00091     {
00092         f = dis_();
00093         assert(0.0 <= f && f <= 1.0);
00094         if (f == 1.0)
00095         {
00096             continue;
00097         }
00098         x = scaleParamB_ / pow(1.0 - f, 1.0 / shapeParamA_);
00099         return x;
00100     }
00101     assure(false, "Something very unlikely happened.");
00102     return x;
00103 }
00104 
00105 double
00106 Pareto::getMean() const
00107 {
00108     if (shapeParamA_ <= 1.0)
00109     {
00110         return std::numeric_limits<double>::max();
00111     }
00112 
00113     return shapeParamA_ * scaleParamB_ / (shapeParamA_ - 1.0);
00114 }
00115 
00116 std::string
00117 Pareto::paramString() const
00118 {
00119     std::ostringstream tmp;
00120     tmp << "Pareto(A=" << shapeParamA_ << ",B=" << scaleParamB_ << ")";
00121     return tmp.str();
00122 }
00123 
00124 /*
00125   Local Variables:
00126   mode: c++
00127   fill-column: 80
00128   c-basic-offset: 8
00129   c-comment-only-line-offset: 0
00130   c-tab-always-indent: t
00131   indent-tabs-mode: t
00132   tab-width: 8
00133   End:
00134 */
00135 

Generated on Fri May 25 03:31:38 2012 for openWNS by  doxygen 1.5.5