Shark machine learning library
About Shark
News!
Contribute
Credits and copyright
Downloads
Getting Started
Installation
Using the docs
Documentation
Tutorials
Quick references
Class list
Global functions
FAQ
Showroom
include
shark
Algorithms
DirectSearch
Operators
Selection
UniformRanking.h
Go to the documentation of this file.
1
/*!
2
*
3
*
4
* \brief Roulette-Wheel-Selection using uniform selection probability assignment.
5
*
6
*
7
*
8
* \author T.Voss
9
* \date 2010-2011
10
*
11
*
12
* \par Copyright 1995-2017 Shark Development Team
13
*
14
* <BR><HR>
15
* This file is part of Shark.
16
* <http://shark-ml.org/>
17
*
18
* Shark is free software: you can redistribute it and/or modify
19
* it under the terms of the GNU Lesser General Public License as published
20
* by the Free Software Foundation, either version 3 of the License, or
21
* (at your option) any later version.
22
*
23
* Shark is distributed in the hope that it will be useful,
24
* but WITHOUT ANY WARRANTY; without even the implied warranty of
25
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
* GNU Lesser General Public License for more details.
27
*
28
* You should have received a copy of the GNU Lesser General Public License
29
* along with Shark. If not, see <http://www.gnu.org/licenses/>.
30
*
31
*/
32
#ifndef SHARK_ALGORITHMS_DIRECTSEARCH_OPERATORS_SELECTION_UNIFORMRANKING_H
33
#define SHARK_ALGORITHMS_DIRECTSEARCH_OPERATORS_SELECTION_UNIFORMRANKING_H
34
35
#include <
shark/Algorithms/DirectSearch/Operators/Selection/RouletteWheelSelection.h
>
36
37
namespace
shark
{
38
/// \brief Selects individuals from the range of individual and offspring individuals.
39
struct
UniformRankingSelection
{
40
41
/// \brief Selects individuals from the range of individual and offspring individuals.
42
///
43
/// The operator carries out the following steps:
44
/// - Assign uniform selection probabilities to all individuals.
45
/// - Carry out roulette wheel selection on the range of individual and
46
/// offspring individuals until the output range is filled.
47
///
48
/// \param [in] individuals Iterator pointing to the first valid individual.
49
/// \param [in] individualsE Iterator pointing to the first invalid individual.
50
/// \param [in] out Iterator pointing to the first valid element of the output range.
51
/// \param [in] outE Iterator pointing to the first invalid element of the output range.
52
template
<
typename
RngType,
typename
InIterator,
typename
OutIterator>
53
void
operator()
(
54
RngType& rng,
55
InIterator individuals,
56
InIterator individualsE,
57
OutIterator out,
58
OutIterator outE
59
){
60
std::size_t size = std::distance( individuals, individualsE );
61
62
RealVector selectionProbability(size,1.0/size);
63
RouletteWheelSelection
rws;
64
for
( ; out != outE; ++out ){
65
*out = *rws(rng, individuals, individualsE, selectionProbability);
66
}
67
}
68
69
};
70
71
}
72
73
#endif