32 #ifndef SHARK_ALGORITHMS_DIRECT_SEARCH_OPERATORS_SELECTION_REFERENCE_VECTOR_GUIDED_SELECTION_H 33 #define SHARK_ALGORITHMS_DIRECT_SEARCH_OPERATORS_SELECTION_REFERENCE_VECTOR_GUIDED_SELECTION_H 52 template <
typename Indiv
idualType>
55 typedef std::set<std::size_t>
bag_t;
65 std::vector<IndividualType> & population,
66 RealMatrix
const & referenceVectors,
67 RealVector
const & gammas,
68 std::size_t
const curIteration)
70 if(population.empty())
75 SIZE_CHECK(fitness.size2() == referenceVectors.size2());
76 const std::size_t groupCount = referenceVectors.size1();
79 const RealVector minFitness =
minCol(fitness);
81 fitness -= repeat(minFitness, fitness.size1());
85 const RealMatrix cosA =
cosAngles(fitness, referenceVectors);
86 const RealMatrix angles = acos(cosA);
91 for(
auto & p : population)
95 const double theta = fitness.size2()
96 * std::pow(static_cast<double>(curIteration) /
99 for(std::size_t j = 0; j < groupCount; ++j)
101 if(subGroups[j].size() == 0)
105 std::size_t selected_idx = 0;
107 for(std::size_t i : subGroups[j])
110 double apd = 1 + theta * angles(i, j) / gammas[j];
111 apd *= norm_2(row(fitness, i));
118 population[selected_idx].selected() =
true;
132 std::vector<std::set<std::size_t>> subGroups(cosAngles.size2());
133 for(std::size_t i = 0; i < cosAngles.size1(); ++i)
135 const std::size_t k = std::distance(
136 row(cosAngles, i).begin(),
137 std::max_element(row(cosAngles, i).begin(),
138 row(cosAngles, i).end()));
139 subGroups[k].insert(i);
145 std::vector<IndividualType>
const & population)
147 RealMatrix fitness(population.size(),
148 population[0].unpenalizedFitness().size());
149 for(std::size_t i = 0; i < population.size(); ++i)
151 row(fitness, i) = population[i].unpenalizedFitness();
156 static RealVector
minCol(RealMatrix
const & m)
158 RealVector minColumns(m.size2());
159 for(std::size_t i = 0; i < m.size2(); ++i)
161 minColumns[i] = min(column(m, i));
169 static RealMatrix
cosAngles(RealMatrix
const & m1, RealMatrix
const & m2)
171 RealMatrix c = prod(m1, trans(m2));
172 for(std::size_t i = 0; i < c.size1(); ++i)
174 row(c, i) /= norm_2(row(m1, i));
179 template <
typename Archive>
182 archive & BOOST_SERIALIZATION_NVP(
m_alpha);
183 archive & BOOST_SERIALIZATION_NVP(
m_maxIters);
192 #endif // SHARK_ALGORITHMS_DIRECT_SEARCH_OPERATORS_SELECTION_REFERENCE_VECTOR_GUIDED_SELECTION_H