libcrbn/sampler/monteCarloSampler.hpp

00001 #ifndef _MONTE_CARLO_SAMPLER_HPP_
00002 #define _MONTE_CARLO_SAMPLER_HPP_
00003 
00004 #include "sampler.h"
00005 
00006 // Monte Carlo sampling
00007 // (read random sampler :)
00008 class MonterCarloSampler : public Sampler {
00009   public:
00010         // Constructor
00011         MonteCarloSampler(const int& iNSamples, const int& iNDimensions) : 
00012                 Sampler(iNSamples, iNDimensions) {}
00013 
00014         // Destructor
00015         virtual ~MonteCarloSampler() {}
00016 
00017         // Computes next sample and store it in the array
00018         // passed as argument.
00019         // Returns false if we generated the s'th sample.
00020         bool next(float* iV) {
00021                 if(_samplePos == _nSamples) {
00022                         _samplePos = 0;
00023                 }
00024                 
00025                 int i;
00026                 for(i = 0; i < _nDimensions; ++i) {
00027                         iV[i] = random() / (float)RAND_MAX;
00028                 }
00029                 
00030                 return (_samplePos < _nSamples);
00031         }
00032 };
00033 
00034 #endif

Generated on Tue Nov 14 15:40:08 2006 for libcrbn by  doxygen 1.5.0