MeanWalker

goodmanwearewalkers.h

Go to the documentation of this file.
00001 /*
00002 
00003   This file is a part of MeanWalker, a library which provides utilities to
00004   sample from probability distributions using methods like the 
00005   Metropilis-Hastings algorithm and Goodman-Weare algorithm.
00006 
00007   Copyright (C) 2012 Jori Liesenborgs
00008 
00009   Contact: jori.liesenborgs@gmail.com
00010   
00011   This program is free software; you can redistribute it and/or modify
00012   it under the terms of the GNU General Public License as published by
00013   the Free Software Foundation; either version 2 of the License, or
00014   (at your option) any later version.
00015   
00016   This program is distributed in the hope that it will be useful,
00017   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019   GNU General Public License for more details.
00020   
00021   You should have received a copy of the GNU General Public License
00022   along with this program; if not, write to the Free Software
00023   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00024   
00025 */
00026 
00031 #ifndef MEANWALKER_GOODMANWEAREWALKERS_H
00032 
00033 #define MEANWALKER_GOODMANWEAREWALKERS_H
00034 
00035 #include "meanwalkerconfig.h"
00036 #include "walker.h"
00037 #include <errut/errorbase.h>
00038 #include <vector>
00039 
00040 namespace meanwalker
00041 {
00042 
00043 class RandomNumberGenerator;
00044 
00058 class MEANWALKER_IMPORTEXPORT GoodmanWeareWalkers : public Walker
00059 {
00060 public:
00062         GoodmanWeareWalkers(RandomNumberGenerator *pRndGen);
00063         ~GoodmanWeareWalkers();
00064 
00081         bool init(Function *pProbFunction, const double *pStartCoordCenter, double startCoordRadius,
00082                   double a = 2.0, int Nwalkers = 0);
00083 
00102         bool init(Function *pProbFunction, const double *pStartCoordCenter, const double *pStartCoordRadii,
00103                   double a = 2.0, int Nwalkers = 0);
00104 
00105         void walk(size_t numSteps);
00106         const double *getBestCoordinates() const                                                        { return &(m_bestCoords[0]); }
00107 
00109         size_t getNumberOfWalkers() const                                                               { return m_walkers.size(); }
00110 private:
00111         struct InternalWalker
00112         {
00113                 std::vector<double> m_coords;
00114                 double m_prob;
00115         };
00116 
00117         std::vector<double> m_bestCoords;
00118         std::vector<double> m_tmp;
00119         std::vector<InternalWalker> m_walkers;
00120         double m_a, m_aScale, m_aOffset;
00121         size_t m_nextStartPos;
00122 };
00123 
00124 } // end namespace   
00125 
00126 #endif // MEANWALKER_GOODMANWEAREWALKERS_H
00127