This repository has been archived on 2026-03-28. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
eodev/src/doSamplerUniform.h
2010-08-18 13:37:17 +02:00

64 lines
1.5 KiB
C++

// (c) Thales group, 2010
/*
Authors:
Johann Dreo <johann.dreo@thalesgroup.com>
Caner Candan <caner.candan@thalesgroup.com>
*/
#ifndef _doSamplerUniform_h
#define _doSamplerUniform_h
#include <utils/eoRNG.h>
#include "doSampler.h"
#include "doUniform.h"
/**
* doSamplerUniform
* This class uses the Uniform distribution parameters (bounds) to return
* a random position used for population sampling.
*/
template < typename EOT >
class doSamplerUniform : public doSampler< doUniform< EOT > >
{
public:
EOT sample( doUniform< EOT >& distrib )
{
unsigned int size = distrib.size();
assert(size > 0);
//-------------------------------------------------------------
// Point we want to sample to get higher a set of points
// (coordinates in n dimension)
// x = {x1, x2, ..., xn}
//-------------------------------------------------------------
EOT solution;
//-------------------------------------------------------------
//-------------------------------------------------------------
// Sampling all dimensions
//-------------------------------------------------------------
for (unsigned int i = 0; i < size; ++i)
{
double min = distrib.min()[i];
double max = distrib.max()[i];
double random = rng.uniform(min, max);
assert(min <= random && random <= max);
solution.push_back(random);
}
//-------------------------------------------------------------
return solution;
}
};
#endif // !_doSamplerUniform_h