@@ -49,14 +49,9 @@ namespace ens {
4949 * year = {2008},
5050 * @endcode
5151 */
52- template <
53- typename InitPolicyType = Uniform,
54- typename DecompPolicyType = Tchebycheff,
55- typename MatType = arma::mat,
56- typename ColType = typename ForwardType<MatType>::bcol,
57- typename CubeType = typename ForwardType<MatType>::bcube>
58- class MOEADType
59- {
52+ template <typename InitPolicyType = Uniform,
53+ typename DecompPolicyType = Tchebycheff>
54+ class MOEAD {
6055 public:
6156 /* *
6257 * Constructor for the MOEA/D optimizer.
@@ -81,20 +76,19 @@ class MOEADType
8176 * @param upperBound The upper bound on each variable of a member
8277 * of the variable space.
8378 */
84- MOEADType (
85- const size_t populationSize = 300 ,
86- const size_t maxGenerations = 500 ,
87- const double crossoverProb = 1.0 ,
88- const double neighborProb = 0.9 ,
89- const size_t neighborSize = 20 ,
90- const double distributionIndex = 20 ,
91- const double differentialWeight = 0.5 ,
92- const size_t maxReplace = 2 ,
93- const double epsilon = 1E-10 ,
94- const ColType& lowerBound = ColType(1 , GetFillType<ColType>::zeros),
95- const ColType& upperBound = ColType(1 , GetFillType<ColType>::ones),
96- const InitPolicyType initPolicy = InitPolicyType(),
97- const DecompPolicyType decompPolicy = DecompPolicyType());
79+ MOEAD (const size_t populationSize = 300 ,
80+ const size_t maxGenerations = 500 ,
81+ const double crossoverProb = 1.0 ,
82+ const double neighborProb = 0.9 ,
83+ const size_t neighborSize = 20 ,
84+ const double distributionIndex = 20 ,
85+ const double differentialWeight = 0.5 ,
86+ const size_t maxReplace = 2 ,
87+ const double epsilon = 1E-10 ,
88+ const arma::vec& lowerBound = arma::zeros(1 , 1 ),
89+ const arma::vec& upperBound = arma::ones(1 , 1 ),
90+ const InitPolicyType initPolicy = InitPolicyType(),
91+ const DecompPolicyType decompPolicy = DecompPolicyType());
9892
9993 /* *
10094 * Constructor for the MOEA/D optimizer. This constructor is provides an
@@ -121,20 +115,19 @@ class MOEADType
121115 * @param upperBound The upper bound on each variable of a member
122116 * of the variable space.
123117 */
124- MOEADType (
125- const size_t populationSize = 300 ,
126- const size_t maxGenerations = 500 ,
127- const double crossoverProb = 1.0 ,
128- const double neighborProb = 0.9 ,
129- const size_t neighborSize = 20 ,
130- const double distributionIndex = 20 ,
131- const double differentialWeight = 0.5 ,
132- const size_t maxReplace = 2 ,
133- const double epsilon = 1E-10 ,
134- const double lowerBound = 0 ,
135- const double upperBound = 1 ,
136- const InitPolicyType initPolicy = InitPolicyType(),
137- const DecompPolicyType decompPolicy = DecompPolicyType());
118+ MOEAD (const size_t populationSize = 300 ,
119+ const size_t maxGenerations = 500 ,
120+ const double crossoverProb = 1.0 ,
121+ const double neighborProb = 0.9 ,
122+ const size_t neighborSize = 20 ,
123+ const double distributionIndex = 20 ,
124+ const double differentialWeight = 0.5 ,
125+ const size_t maxReplace = 2 ,
126+ const double epsilon = 1E-10 ,
127+ const double lowerBound = 0 ,
128+ const double upperBound = 1 ,
129+ const InitPolicyType initPolicy = InitPolicyType(),
130+ const DecompPolicyType decompPolicy = DecompPolicyType());
138131
139132 /* *
140133 * Optimize a set of objectives. The initial population is generated
@@ -147,12 +140,37 @@ class MOEADType
147140 * @param iterate The initial reference point for generating population.
148141 * @param callbacks The callback functions.
149142 */
150- template <typename InputMatType ,
143+ template <typename MatType ,
151144 typename ... ArbitraryFunctionType,
152145 typename ... CallbackTypes>
153- typename InputMatType ::elem_type Optimize (
146+ typename MatType ::elem_type Optimize (
154147 std::tuple<ArbitraryFunctionType...>& objectives,
155- InputMatType& iterate,
148+ MatType& iterate,
149+ CallbackTypes&&... callbacks);
150+
151+ /* *
152+ * Optimize a set of objectives. The initial population is generated
153+ * using the initial point. The output is the best generated front.
154+ *
155+ * @tparam MatType The type of matrix used to store coordinates.
156+ * @tparam CubeType The type of cube used to store the front and Pareto set.
157+ * @tparam ArbitraryFunctionType The type of objective function.
158+ * @tparam CallbackTypes Types of callback function.
159+ * @param objectives std::tuple of the objective functions.
160+ * @param iterate The initial reference point for generating population.
161+ * @param front The generated front.
162+ * @param paretoSet The generated Pareto set.
163+ * @param callbacks The callback functions.
164+ */
165+ template <typename MatType,
166+ typename CubeType,
167+ typename ... ArbitraryFunctionType,
168+ typename ... CallbackTypes>
169+ typename MatType::elem_type Optimize (
170+ std::tuple<ArbitraryFunctionType...>& objectives,
171+ MatType& iterate,
172+ CubeType& front,
173+ CubeType& paretoSet,
156174 CallbackTypes&&... callbacks);
157175
158176 // ! Retrieve population size.
@@ -201,22 +219,38 @@ class MOEADType
201219 double & Epsilon () { return epsilon; }
202220
203221 // ! Retrieve value of lowerBound.
204- const ColType & LowerBound () const { return lowerBound; }
222+ const arma::vec & LowerBound () const { return lowerBound; }
205223 // ! Modify value of lowerBound.
206- ColType & LowerBound () { return lowerBound; }
224+ arma::vec & LowerBound () { return lowerBound; }
207225
208226 // ! Retrieve value of upperBound.
209- const ColType & UpperBound () const { return upperBound; }
227+ const arma::vec & UpperBound () const { return upperBound; }
210228 // ! Modify value of upperBound.
211- ColType & UpperBound () { return upperBound; }
229+ arma::vec & UpperBound () { return upperBound; }
212230
213- // ! Retrieve the Pareto optimal points in variable space.
214- // ! This returns an empty cube until `Optimize()` has been called.
215- const CubeType& ParetoSet () const { return paretoSet; }
231+ /* *
232+ * Retrieve the Pareto optimal points in variable space. This returns an
233+ * empty cube until `Optimize()` has been called. Note that this function is
234+ * deprecated and will be removed in ensmallen 3.x! Use `Optimize()`
235+ * instead.
236+ */
237+ template <typename MatType = arma::cube>
238+ [[deprecated("use Optimize() instead")]] MatType ParetoSet () const
239+ {
240+ return conv_to<MatType>::from (paretoSet);
241+ }
216242
217- // ! Retrieve the best front (the Pareto frontier).
218- // ! This returns an empty cube until `Optimize()` has been called.
219- const CubeType& ParetoFront () const { return paretoFront; }
243+ /* *
244+ * Retrieve the best front (the Pareto frontier). This returns an empty cube
245+ * until `Optimize()` has been called. Note that this function is
246+ * deprecated and will be removed in ensmallen 3.x! Use `Optimize()`
247+ * instead.
248+ */
249+ template <typename MatType = arma::cube>
250+ [[deprecated("use Optimize() instead")]] MatType ParetoFront () const
251+ {
252+ return conv_to<MatType>::from (paretoFront);
253+ }
220254
221255 // ! Get the weight initialization policy.
222256 const InitPolicyType& InitPolicy () const { return initPolicy; }
@@ -236,9 +270,8 @@ class MOEADType
236270 * @param neighborSize A matrix containing indices of the neighbors.
237271 * @return std::tuple<size_t, size_t> The chosen pair of indices.
238272 */
239- template <typename IndexMatType>
240273 std::tuple<size_t , size_t > Mating (size_t subProblemIdx,
241- const IndexMatType & neighborSize,
274+ const arma::umat & neighborSize,
242275 bool sampleNeighbor);
243276
244277 /* *
@@ -252,38 +285,40 @@ class MOEADType
252285 * @param upperBound The upper bound on each variable in the matrix.
253286 * @return The mutated child.
254287 */
255- template <typename InputMatType >
256- void Mutate (InputMatType & child,
288+ template <typename MatType >
289+ void Mutate (MatType & child,
257290 double mutationRate,
258- const InputMatType & lowerBound,
259- const InputMatType & upperBound);
291+ const MatType & lowerBound,
292+ const MatType & upperBound);
260293
261294 /* *
262295 * Evaluate objectives for the elite population.
263296 *
264297 * @tparam ArbitraryFunctionType std::tuple of multiple function types.
265298 * @tparam MatType Type of matrix to optimize.
299+ * @tparam ColType Type of column vector to store objectives.
266300 * @param population The elite population.
267301 * @param objectives The set of objectives.
268302 * @param calculatedObjectives Vector to store calculated objectives.
269303 */
270304 template <std::size_t I = 0 ,
271- typename InputMatType,
305+ typename MatType,
306+ typename ColType,
272307 typename ...ArbitraryFunctionType>
273308 typename std::enable_if<I == sizeof ...(ArbitraryFunctionType), void >::type
274- EvaluateObjectives (
275- std::vector<InputMatType>&,
276- std::tuple<ArbitraryFunctionType...>&,
277- std::vector<ColType>&);
309+ EvaluateObjectives (std::vector<MatType>&,
310+ std::tuple<ArbitraryFunctionType...>&,
311+ std::vector<ColType>&);
278312
279313 template <std::size_t I = 0 ,
280- typename InputMatType,
314+ typename MatType,
315+ typename ColType,
281316 typename ...ArbitraryFunctionType>
282317 typename std::enable_if<I < sizeof ...(ArbitraryFunctionType), void >::type
283- EvaluateObjectives (
284- std::vector<InputMatType >& population ,
285- std::tuple<ArbitraryFunctionType...>& objectives,
286- std::vector<ColType>& calculatedObjectives);
318+ EvaluateObjectives (std::vector<MatType>& population,
319+ std::tuple<ArbitraryFunctionType... >& objectives ,
320+ std::vector<ColType>&
321+ calculatedObjectives);
287322
288323 // ! Size of the population.
289324 size_t populationSize;
@@ -316,18 +351,18 @@ class MOEADType
316351 double epsilon;
317352
318353 // ! Lower bound on each variable in the variable space.
319- ColType lowerBound;
354+ arma::vec lowerBound;
320355
321356 // ! Upper bound on each variable in the variable space.
322- ColType upperBound;
357+ arma::vec upperBound;
323358
324359 // ! The set of all the Pareto optimal points.
325360 // ! Stored after Optimize() is called.
326- CubeType paretoSet;
361+ arma::cube paretoSet;
327362
328363 // ! The set of all the Pareto optimal objective vectors.
329364 // ! Stored after Optimize() is called.
330- CubeType paretoFront;
365+ arma::cube paretoFront;
331366
332367 // ! Policy to initialize the reference directions (weights) matrix.
333368 InitPolicyType initPolicy;
@@ -336,24 +371,12 @@ class MOEADType
336371 DecompPolicyType decompPolicy;
337372};
338373
339- using MOEAD = MOEADType<
340- Uniform, Tchebycheff, arma::mat, arma::colvec, arma::cube>;
341- using DefaultMOEAD = MOEADType<
342- Uniform, Tchebycheff, arma::mat, arma::colvec, arma::cube>;
343- using BBSMOEAD = MOEADType<
344- BayesianBootstrap, Tchebycheff, arma::mat, arma::colvec, arma::cube>;
345-
346- template <
347- typename MatType,
348- typename ColType = typename ForwardType<MatType>::bcol,
349- typename CubeType = typename ForwardType<MatType>::bcube>
350- using DirichletMOEADType = MOEADType<
351- Dirichlet, Tchebycheff, MatType, ColType, CubeType>;
352- using DirichletMOEAD = MOEADType<
353- Dirichlet, Tchebycheff, arma::mat, arma::colvec, arma::cube>;
374+ using DefaultMOEAD = MOEAD <Uniform, Tchebycheff>;
375+ using BBSMOEAD = MOEAD <BayesianBootstrap, Tchebycheff>;
376+ using DirichletMOEAD = MOEAD <Dirichlet, Tchebycheff>;
354377} // namespace ens
355378
356379// Include implementation.
357380#include " moead_impl.hpp"
358381
359- #endif
382+ #endif
0 commit comments