Provides a functionality of a fitness proportional roulette sampling of any objects that implement a GetFitness() method.
In particular it is used by an evolutionary algorithm (EA).
Because the implementation is optimized for usage in EA, the sampled elements are removed unless the method ends with 'WithReturn'.
More...
#include <RouletteSampler.hh>
|
| RouletteSampler () |
| RouletteSampler - Constructor. Note that if you use a parameterless constructor, call Initialize() to provide elements for sampling.
They must implement a public double GetFitness() method. More...
|
|
| RouletteSampler (const std::vector< std::unique_ptr< T >> &fitnessHavingElements) |
| RouletteSampler - Constructor. More...
|
|
void | Initialize (const std::vector< std::unique_ptr< T >> &fitnessHavingElements) |
| Sets the elements that can be sampled using this RouletteSampler. They must implement a public "double GetFitness()" method. More...
|
|
T * | Sample (std::mt19937_64 &randGen) |
| Samples one element and removes it. More...
|
|
T * | SampleWithReturn (std::mt19937_64 &randGen) |
| Samples one element without removing it. More...
|
|
std::vector< T * > | SampleMany (size_t count, std::mt19937_64 &randGen) |
| Samples a given number of elements and removes them. More...
|
|
std::vector< T * > | SampleManyWithReturn (size_t count, std::mt19937_64 &randGen) |
| Samples a given number of elements without removing them. More...
|
|
std::vector< size_t > | SampleManyIndices (size_t count, std::mt19937_64 &randGen) |
| SampleManyIndices - samples a given number of indices of elements and removes them. More...
|
|
template<class T>
class grail::evolution::RouletteSampler< T >
Provides a functionality of a fitness proportional roulette sampling of any objects that implement a GetFitness() method.
In particular it is used by an evolutionary algorithm (EA).
Because the implementation is optimized for usage in EA, the sampled elements are removed unless the method ends with 'WithReturn'.
- Parameters
-
T | - the type T must have a public method ef "double GetFitness()" |
◆ RouletteSampler() [1/2]
RouletteSampler - Constructor. Note that if you use a parameterless constructor, call Initialize() to provide elements for sampling.
They must implement a public double GetFitness() method.
◆ RouletteSampler() [2/2]
RouletteSampler - Constructor.
- Parameters
-
fitnessHavingElements | - a vector of elements which will be sampled. |
◆ Initialize()
Sets the elements that can be sampled using this RouletteSampler. They must implement a public "double GetFitness()" method.
- Parameters
-
fitnessHavingElements | - a vector of elements which will be sampled. |
◆ Sample()
Samples one element and removes it.
- Parameters
-
randGen | - random numbers generator to use. |
- Returns
- the sampled element.
◆ SampleMany()
Samples a given number of elements and removes them.
- Parameters
-
count | - the number of elements to sample. |
randGen | - random numbers generator to use. |
- Returns
- the sampled elements.
◆ SampleManyIndices()
SampleManyIndices - samples a given number of indices of elements and removes them.
- Parameters
-
count | - the number of indices to sample. |
randGen | - random numbers generator to use. |
- Returns
- the sampled indices of elements.
◆ SampleManyWithReturn()
Samples a given number of elements without removing them.
- Parameters
-
count | - the number of elements to sample. |
randGen | - random numbers generator to use. |
- Returns
- the sampled elements.
◆ SampleWithReturn()
Samples one element without removing it.
- Parameters
-
randGen | - random numbers generator to use. |
- Returns
- the sampled element.
The documentation for this class was generated from the following file: