153int main(
int argc,
char* argv[])
161#define EIGEN_USE_LAPACKE
162#include "Vector/vector_dist.hpp"
163#include "DMatrix/EMatrix.hpp"
164#include <Eigen/Eigenvalues>
165#include <Eigen/Jacobi>
167#include "Vector/vector_dist.hpp"
168#include <f15_cec_fun.hpp>
169#include <boost/math/special_functions/sign.hpp>
176constexpr int dim = 10;
178constexpr int lambda = 7;
179constexpr int mu = lambda/2;
180double psoWeight = 0.7;
183double stopTolX = 2e-11;
184double stopTolUpX = 2000.0;
186size_t max_fun_eval = 30000000;
187constexpr int hist_size = 21;
196double stop_fitness = 1.0;
207constexpr int sigma = 0;
208constexpr int Cov_m = 1;
211constexpr int Zeta = 4;
212constexpr int path_s = 5;
213constexpr int path_c = 6;
214constexpr int ord = 7;
215constexpr int stop = 8;
216constexpr int fithist = 9;
217constexpr int weight = 10;
218constexpr int validfit = 11;
219constexpr int xold = 12;
220constexpr int last_restart = 13;
221constexpr int iniphase = 14;
222constexpr int xmean_st = 15;
223constexpr int meanz_st = 16;
228 Eigen::DiagonalMatrix<double,Eigen::Dynamic>,
241 EVectorXd> > particle_type;
261double generateGaussianNoise(
double mu,
double sigma)
263 static const double epsilon = std::numeric_limits<double>::min();
264 static const double two_pi = 2.0*3.14159265358979323846;
266 thread_local double z1;
267 thread_local double generate;
268 generate = !generate;
271 {
return z1 * sigma + mu;}
276 u1 = rand() * (1.0 / RAND_MAX);
277 u2 = rand() * (1.0 / RAND_MAX);
279 while ( u1 <= epsilon );
282 z0 = sqrt(-2.0 * log(u2)) * cos(two_pi * u1);
283 z1 = sqrt(-2.0 * log(u2)) * sin(two_pi * u1);
284 return z0 * sigma + mu;
287template<
unsigned int dim>
288EVectorXd generateGaussianVector()
293 for (
size_t i = 0 ; i < dim ; i++)
295 tmp(i) = generateGaussianNoise(0,1);
303template<
unsigned int dim>
304void fill_vector(
double (& f)[dim], EVectorXd & ev)
306 for (
size_t i = 0 ; i < dim ; i++)
310void fill_vector(
const double * f, EVectorXd & ev)
312 for (
size_t i = 0 ; i < ev.size() ; i++)
321 bool operator<(
const fun_index & tmp)
const
331 for (
size_t i = 0 ; i < mu ; i++)
332 {wm[i] = log(
double(mu)+1.0) - log(
double(i)+1.0);}
336 for (
size_t i = 0 ; i < mu ; i++)
342 for (
size_t i = 0 ; i < mu ; i++)
354double weight_sample(
int i)
373void create_rotmat(EVectorXd & S,EVectorXd & T, EMatrixXd & R)
375 EVectorXd S_work(dim);
376 EVectorXd T_work(dim);
377 EVectorXd S_sup(dim);
378 EVectorXd T_sup(dim);
380 EMatrixXd R_tar(dim,dim);
381 EMatrixXd R_tmp(dim,dim);
382 EMatrixXd R_sup(dim,dim);
384 EMatrixXd S_tmp(2,2);
385 EMatrixXd T_tmp(2,2);
395 for (p = dim - 2; p >= 0 ; p -= 1)
398 for (q = dim - 1 ; q >= p+1 ; q-= 1)
400 T_tmp(0) = T_work(p);
401 T_tmp(1) = T_work(q);
402 S_tmp(0) = S_work(p);
403 S_tmp(1) = S_work(q);
407 Eigen::JacobiRotation<double> G;
409 G.makeGivens(S_tmp(0), S_tmp(1),&z);
418 R_tmp(p,p) = sign*G.c();
419 R_tmp(q,q) = sign*G.c();
420 R_tmp(p,q) = sign*-G.s();
421 R_tmp(q,p) = sign*G.s();
426 S_work = R_tmp*S_work;
432 G.makeGivens(T_tmp(0), T_tmp(1),&z);
439 R_tmp(p,p) = sign*G.c();
440 R_tmp(q,q) = sign*G.c();
441 R_tmp(p,q) = sign*-G.s();
442 R_tmp(q,p) = sign*G.s();
446 T_work = R_tmp*T_work;
451 R = R_tar.transpose()*R;
455 EVectorXd Check(dim);
482 Eigen::DiagonalMatrix<double,Eigen::Dynamic> &
D,
485 EVectorXd best_sol_ei(dim);
487 double bias_weight = psoWeight;
488 fill_vector(&best_sol.get(0),best_sol_ei);
489 EVectorXd gb_vec = best_sol_ei-xmean;
490 double gb_vec_length = sqrt(gb_vec.transpose() * gb_vec);
491 EVectorXd b_main = B.col(dim-1);
496 EMatrixXd R(dim,dim);
498 if (gb_vec_length > 0.0)
500 if(sigma < gb_vec_length)
502 if(sigma/gb_vec_length <= t_c*gb_vec_length)
505 {bias = sigma*gb_vec/gb_vec_length;}
511 xmean = xmean + bias;
515 EMatrixXd B_rot(dim,dim);
516 Eigen::DiagonalMatrix<double,Eigen::Dynamic> D_square(dim);
518 EVectorXd gb_vec_old = best_sol_ei - xold;
519 create_rotmat(b_main,gb_vec_old,R);
520 for (
size_t i = 0 ; i < dim ; i++)
521 {B_rot.col(i) = R*B.col(i);}
523 for (
size_t i = 0 ; i < dim ; i++)
524 {D_square.diagonal()[i] =
D.diagonal()[i] *
D.diagonal()[i];}
525 C_pso = B_rot * D_square * B_rot.transpose();
527 EMatrixXd trUp = C_pso.triangularView<Eigen::Upper>();
528 EMatrixXd trDw = C_pso.triangularView<Eigen::StrictlyUpper>();
529 C_pso = trUp + trDw.transpose();
553void broadcast_best_solution(particle_type & vd,
559 best_sol.resize(dim);
560 auto & v_cl = create_vcluster();
562 double best_old = best_sample;
563 v_cl.min(best_sample);
567 if (best < best_sample)
573 if (best_old == best_sample)
575 rank = v_cl.getProcessUnitID();
581 if (rank == v_cl.getProcessUnitID())
583 for (
size_t i = 0 ; i < dim ; i++)
584 {best_sol.get(i) = best_sample_sol.get(i);}
589 rank = std::numeric_limits<size_t>::max();
598 v_cl.Bcast(best_sol,rank);
628 double availablepercentiles[lambda];
632 for (
size_t i = 0 ; i < lambda ; i++)
634 availablepercentiles[i] = 0.0;
635 sar[i] = f_obj.get(i).f;
637 std::sort(&sar[0],&sar[lambda]);
639 for (
size_t i = 0 ; i < 2 ; i++)
641 if (perc[i] <= (100.0*0.5/lambda))
643 else if (perc[i] >= (100.0*(lambda-0.5)/lambda) )
644 {res[i] = sar[lambda-1];}
647 for (
size_t j = 0 ; j < lambda ; j++)
648 {availablepercentiles[j] = 100.0 * ((double(j)+1.0)-0.5) / lambda;}
650 for (k = 0 ; k < lambda ; k++)
651 {
if(availablepercentiles[k] >= perc[i]) {
break;}}
654 res[i] = sar[k] + (sar[k+1]-sar[k]) * (perc[i]
655 -availablepercentiles[k]) / (availablepercentiles[k+1] - availablepercentiles[k]);
662double maxval(
double (& buf)[hist_size],
bool (& mask)[hist_size])
665 for (
size_t i = 0 ; i < hist_size ; i++)
667 if (buf[i] > max && mask[i] ==
true)
674double minval(
double (& buf)[hist_size],
bool (& mask)[hist_size])
676 double min = std::numeric_limits<double>::max();
677 for (
size_t i = 0 ; i < hist_size ; i++)
679 if (buf[i] < min && mask[i] ==
true)
688void cmaes_intobounds(EVectorXd & x, EVectorXd & xout,
bool (& idx)[dim],
bool & idx_any)
691 for (
size_t i = 0; i < dim ; i++)
720 EVectorXd (& arxvalid)[lambda],
721 EVectorXd (& arx)[lambda],
725 double (& weight)[dim],
726 double (& fithist)[hist_size],
728 double & validfitval,
738 bool mask[hist_size];
741 int dfitidx[hist_size];
742 double dfitsort[hist_size];
743 double prct[2] = {25.0,75.0};
746 for (
size_t i = 0 ; i < hist_size ; i++)
751 if (fithist[i] > 0.0)
757 for (
size_t i = 0 ; i < dim ; i++)
762 meandiag = C.trace()/dim;
764 cmaes_myprctile(f_obj, prct, val);
765 value = (val[1] - val[0]) / dim / meandiag / (sigma*sigma);
767 if (value >= std::numeric_limits<double>::max())
769 auto & v_cl = create_vcluster();
770 std::cout <<
"Process " << v_cl.rank() <<
" warning: Non-finite fitness range" << std::endl;
771 value = maxval(fithist,mask);
773 else if(value == 0.0)
775 value = minval(fithist,mask);
777 else if (validfit == 0.0)
779 for (
size_t i = 0 ; i < hist_size ; i++)
784 for (
size_t i = 0; i < hist_size ; i++)
792 else if(i == hist_size-1)
794 for (
size_t k = 0 ; k < hist_size-1 ; k++)
795 {fithist[k] = fithist[k+1];}
801 cmaes_intobounds(xmean,tx,idx,idx_any);
808 {value = fithist[0];}
812 for (
size_t i = 0 ; i <= maxI; i++)
814 fitsort.get(i).f = fithist[i];
815 fitsort.get(i).id = i;
819 for (
size_t k = 0; k <= maxI ; k++)
820 {fitsort.get(k).f = fithist[fitsort.get(k).id];}
822 if ((maxI+1) % 2 == 0)
823 {value = (fitsort.get(maxI/2).f+fitsort.get(maxI/2+1).f)/2.0;}
825 {value = fitsort.get(maxI/2).f;}
827 for (
size_t i = 0 ; i < dim ; i++)
829 diag[i] = diag[i]/meandiag;
830 weight[i] = 2.0002 * value / diag[i];
832 if (validfitval == 1.0 && step-last_restart > 2)
842 for(
size_t i = 0 ; i < dim ; i++)
844 idx[i] = (idx[i] && (fabs(tx(i)) > 3.0*std::max(1.0,sqrt(dim)/mu_eff) * sigma * sqrt(diag[i])));
845 idx[i] = (idx[i] && (std::copysign(1.0,tx(i)) == std::copysign(1.0,(xmean(i)-xold(i)))) );
847 for (
size_t i = 0 ; i < dim ; i++)
851 weight[i] = pow(1.2,(std::max(1.0,mu_eff/10.0/dim)))*weight[i];
855 double arpenalty[lambda];
856 for (
size_t i = 0 ; i < lambda ; i++)
859 for (
size_t j = 0 ; j < dim ; j++)
861 arpenalty[i] += weight[j] * (arxvalid[i](j) - arx[i](j))*(arxvalid[i](j) - arx[i](j));
863 f_obj.get(i).f += arpenalty[i];
870double adjust_sigma(
double sigma, EMatrixXd & C)
872 for (
size_t i = 0 ; i < dim ; i++)
874 if (sigma*sqrt(C(i,i)) > 5.0)
875 {sigma = 5.0/sqrt(C(i,i));}
900void cma_step(particle_type & vd,
int step,
double & best,
905 EVectorXd xmean(dim);
906 EVectorXd mean_z(dim);
907 EVectorXd arxvalid[lambda];
908 EVectorXd arx[lambda];
910 for (
size_t i = 0 ; i < lambda ; i++)
913 arxvalid[i].resize(dim);
916 double best_sample = std::numeric_limits<double>::max();
921 int counteval = step*lambda;
923 auto it = vd.getDomainIterator();
928 if (vd.getProp<stop>(p) ==
true)
931 EVectorXd (& arz)[lambda] = vd.getProp<Zeta>(p);
935 fill_vector(vd.getPos(p),xmean);
937 for (
size_t j = 0 ; j < lambda ; j++)
939 vd.getProp<Zeta>(p)[j] = generateGaussianVector<dim>();
940 arx[j] = xmean + vd.getProp<sigma>(p)*vd.getProp<B>(p)*vd.getProp<
D>(p)*vd.getProp<Zeta>(p)[j];
943 for (
size_t i = 0 ; i < dim ; i++)
945 if (arx[j](i) < -5.0)
946 {arxvalid[j](i) = -5.0;}
947 else if (arx[j](i) > 5.0)
948 {arxvalid[j](i) = 5.0;}
950 {arxvalid[j](i) = arx[j](i);}
953 f_obj.get(j).f = hybrid_composition<dim>(arxvalid[j]);
958 if (f_obj.get(j).f < best_sample)
960 best_sample = f_obj.get(j).f;
963 for (
size_t i = 0 ; i < dim ; i++)
964 {best_sample_sol.get(i) = arxvalid[j](i);}
969 cmaes_handlebounds(f_obj,vd.getProp<sigma>(p),
970 vd.getProp<validfit>(p),arxvalid,
971 arx,vd.getProp<Cov_m>(p),
972 xmean,vd.getProp<xold>(p),vd.getProp<weight>(p),
973 vd.getProp<fithist>(p),vd.getProp<iniphase>(p),
974 vd.getProp<validfit>(p),mu_eff,
975 step,vd.getProp<last_restart>(p));
979 for (
size_t j = 0 ; j < lambda ; j++)
980 {vd.getProp<ord>(p)[j] = f_obj.get(j).id;}
982 vd.getProp<xold>(p) = xmean;
988 for (
size_t j = 0 ; j < mu ; j++)
990 xmean += weight_sample(j)*arx[vd.getProp<ord>(p)[j]];
991 mean_z += weight_sample(j)*vd.getProp<Zeta>(p)[vd.getProp<ord>(p)[j]];
994 vd.getProp<xmean_st>(p) = xmean;
995 vd.getProp<meanz_st>(p) = mean_z;
1001 broadcast_best_solution(vd,best_sol,best,best_sample,best_sample_sol);
1004 bool calc_bd = counteval - eigeneval > lambda/(ccov)/dim/10;
1005 if (calc_bd ==
true)
1006 {eigeneval = counteval;}
1008 auto it2 = vd.getDomainIterator();
1009 while (it2.isNext())
1013 if (vd.getProp<stop>(p) ==
true)
1016 xmean = vd.getProp<xmean_st>(p);
1017 mean_z = vd.getProp<meanz_st>(p);
1019 vd.getProp<path_s>(p) = vd.getProp<path_s>(p)*(1.0 - cs) + sqrt(cs*(2.0-cs)*mu_eff)*vd.getProp<B>(p)*mean_z;
1021 double hsig = vd.getProp<path_s>(p).norm()/sqrt(1.0-pow((1.0-cs),(2.0*
double((step-vd.getProp<last_restart>(p))))))/chiN < 1.4 + 2.0/(dim+1);
1023 vd.getProp<path_c>(p) = (1-cc)*vd.getProp<path_c>(p) + hsig * sqrt(cc*(2-cc)*mu_eff)*(vd.getProp<B>(p)*vd.getProp<
D>(p)*mean_z);
1025 if (step % N_pso == 0)
1027 EMatrixXd C_pso(dim,dim);
1028 updatePso(best_sol,vd.getProp<sigma>(p),xmean,vd.getProp<xold>(p),vd.getProp<B>(p),vd.getProp<
D>(p),C_pso);
1031 vd.getProp<Cov_m>(p) = (1.0-ccov+(1.0-hsig)*ccov*cc*(2.0-cc)/mu_eff)*vd.getProp<Cov_m>(p) +
1032 ccov*(1.0/mu_eff)*(vd.getProp<path_c>(p)*vd.getProp<path_c>(p).transpose());
1034 for (
size_t i = 0 ; i < mu ; i++)
1035 {vd.getProp<Cov_m>(p) += ccov*(1.0-1.0/mu_eff)*(vd.getProp<B>(p)*vd.getProp<
D>(p)*vd.getProp<Zeta>(p)[vd.getProp<ord>(p)[i]])*weight_sample(i)*
1036 (vd.getProp<B>(p)*vd.getProp<
D>(p)*vd.getProp<Zeta>(p)[vd.getProp<ord>(p)[i]]).transpose();
1039 vd.getProp<Cov_m>(p) = psoWeight*vd.getProp<Cov_m>(p) + (1.0 - psoWeight)*C_pso;
1044 vd.getProp<Cov_m>(p) = (1.0-ccov+(1.0-hsig)*ccov*cc*(2.0-cc)/mu_eff)*vd.getProp<Cov_m>(p) +
1045 ccov*(1.0/mu_eff)*(vd.getProp<path_c>(p)*vd.getProp<path_c>(p).transpose());
1047 for (
size_t i = 0 ; i < mu ; i++)
1048 {vd.getProp<Cov_m>(p) += ccov*(1.0-1.0/mu_eff)*(vd.getProp<B>(p)*vd.getProp<
D>(p)*vd.getProp<Zeta>(p)[vd.getProp<ord>(p)[i]])*weight_sample(i)*
1049 (vd.getProp<B>(p)*vd.getProp<
D>(p)*vd.getProp<Zeta>(p)[vd.getProp<ord>(p)[i]]).transpose();
1055 double smaller = std::numeric_limits<double>::max();
1056 for (
size_t i = 0 ; i < dim ; i++)
1058 if (vd.getProp<sigma>(p)*sqrt(vd.getProp<
D>(p).diagonal()[i]) > 5.0)
1060 if (smaller > 5.0/sqrt(vd.getProp<
D>(p).diagonal()[i]))
1061 {smaller = 5.0/sqrt(vd.getProp<
D>(p).diagonal()[i]);}
1064 if (smaller != std::numeric_limits<double>::max())
1065 {vd.getProp<sigma>(p) = smaller;}
1068 vd.getProp<sigma>(p) = vd.getProp<sigma>(p)*exp((cs/d_amps)*(vd.getProp<path_s>(p).norm()/chiN - 1));
1074 EMatrixXd trUp = vd.getProp<Cov_m>(p).triangularView<Eigen::Upper>();
1075 EMatrixXd trDw = vd.getProp<Cov_m>(p).triangularView<Eigen::StrictlyUpper>();
1076 vd.getProp<Cov_m>(p) = trUp + trDw.transpose();
1079 Eigen::SelfAdjointEigenSolver<EMatrixXd> eig_solver;
1081 eig_solver.compute(vd.getProp<Cov_m>(p));
1083 for (
size_t i = 0 ; i < eig_solver.eigenvalues().size() ; i++)
1084 {vd.getProp<
D>(p).diagonal()[i] = sqrt(eig_solver.eigenvalues()[i]);}
1085 vd.getProp<B>(p) = eig_solver.eigenvectors();
1088 for (
size_t i = 0 ; i < dim ; i++)
1090 if (vd.getProp<B>(p)(0,i) < 0)
1091 {vd.getProp<B>(p).col(i) = - vd.getProp<B>(p).col(i);}
1094 EMatrixXd tmp = vd.getProp<B>(p).transpose();
1098 for (
size_t i = 0 ; i < dim ; i++)
1099 {vd.getPos(p)[i] = xmean(i);}
1101 vd.getProp<sigma>(p) = adjust_sigma(vd.getProp<sigma>(p),vd.getProp<Cov_m>(p));
1104 bool stop_tol =
true;
1105 bool stop_tolX =
true;
1106 for (
size_t i = 0 ; i < dim ; i++)
1108 stop_tol &= (vd.getProp<sigma>(p)*std::max(fabs(vd.getProp<path_c>(p)(i)),sqrt(vd.getProp<Cov_m>(p)(i,i)))) < stopTolX;
1109 stop_tolX &= vd.getProp<sigma>(p)*sqrt(vd.getProp<
D>(p).diagonal()[i]) > stopTolUpX;
1112 vd.getProp<stop>(p) = stop_tol | stop_tolX;
1115 if (f_obj.get(0).f == f_obj.get(std::ceil(0.7*lambda)).f )
1117 vd.getProp<sigma>(p) = vd.getProp<sigma>(p)*exp(0.2+cs/d_amps);
1118 std::cout <<
"warning: flat fitness, consider reformulating the objective";
1121 vd.getProp<stop>(p) =
true;
1124 if (vd.getProp<stop>(p) ==
true)
1125 {std::cout <<
"Stopped" << std::endl;}
1127 if (restart_cma && vd.getProp<stop>(p) ==
true)
1129 std::cout <<
"------- Restart #" << std::endl;
1131 std::cout <<
"---------------------------------" << std::endl;
1132 std::cout <<
"Best: " << best <<
" " << fun_eval << std::endl;
1133 std::cout <<
"---------------------------------" << std::endl;
1135 vd.getProp<last_restart>(p) = step;
1136 vd.getProp<xold>(p).setZero();
1138 for (
size_t i = 0 ; i < vd.getProp<
D>(p).diagonal().size() ; i++)
1139 {vd.getProp<
D>(p).diagonal()[i] = 1.0;}
1140 vd.getProp<B>(p).resize(dim,dim);
1141 vd.getProp<B>(p).setIdentity();
1142 vd.getProp<Cov_m>(p) = vd.getProp<B>(p)*vd.getProp<
D>(p)*vd.getProp<
D>(p)*vd.getProp<B>(p);
1143 vd.getProp<path_s>(p).resize(dim);
1144 vd.getProp<path_s>(p).setZero(dim);
1145 vd.getProp<path_c>(p).resize(dim);
1146 vd.getProp<path_c>(p).setZero(dim);
1147 vd.getProp<stop>(p) =
false;
1148 vd.getProp<iniphase>(p) =
true;
1149 vd.getProp<last_restart>(p) = 0;
1150 vd.getProp<sigma>(p) = 2.0;
1153 for (
size_t i = 0 ; i < dim ; i++)
1156 vd.getPos(p)[i] = 10.0*(double)rand() / RAND_MAX - 5.0;
1161 for (
size_t i = 0 ; i < hist_size ; i++)
1162 {vd.getProp<fithist>(p)[i] = -1.0;}
1163 vd.getProp<fithist>(p)[0] = 1.0;
1164 vd.getProp<validfit>(p) = 0.0;
1170 auto & v_cl = create_vcluster();
1192int main(
int argc,
char* argv[])
1195 openfpm_init(&argc,&argv);
1197 auto & v_cl = create_vcluster();
1202 for (
size_t i = 0 ; i < dim ; i++)
1204 domain.setLow(i,0.0);
1205 domain.setHigh(i,1.0);
1210 for (
size_t i = 0 ; i < dim ; i++)
1211 {bc[i] = NON_PERIODIC;};
1218 particle_type vd(16,domain,bc,g);
1222 stop_fitness = 1e-10;
1223 size_t stopeval = 1e3*dim*dim;
1229 cc = 4.0 / (dim+4.0);
1230 cs = (mu_eff+2.0) / (
double(dim)+mu_eff+3.0);
1231 ccov = (1.0/mu_eff) * 2.0/((dim+1.41)*(dim+1.41)) +
1232 (1.0 - 1.0/mu_eff)* std::min(1.0,(2.0*mu_eff-1.0)/((dim+2.0)*(dim+2.0) + mu_eff));
1233 d_amps = 1 + 2*std::max(0.0, sqrt((mu_eff-1.0)/(dim+1))-1) + cs;
1235 chiN = sqrt(dim)*(1.0-1.0/(4.0*dim)+1.0/(21.0*dim*dim));
1241 int seed = 24756*v_cl.rank()*v_cl.rank() + time(NULL);
1244 auto it = vd.getDomainIterator();
1250 for (
size_t i = 0 ; i < dim ; i++)
1253 vd.getPos(p)[i] = 10.0*(double)rand() / RAND_MAX - 5.0;
1256 vd.getProp<sigma>(p) = 2.0;
1260 vd.getProp<
D>(p).resize(dim);
1261 for (
size_t i = 0 ; i < vd.getProp<
D>(p).diagonal().size() ; i++)
1262 {vd.getProp<
D>(p).diagonal()[i] = 1.0;}
1263 vd.getProp<B>(p).resize(dim,dim);
1264 vd.getProp<B>(p).setIdentity();
1265 vd.getProp<Cov_m>(p) = vd.getProp<B>(p)*vd.getProp<
D>(p)*vd.getProp<
D>(p)*vd.getProp<B>(p);
1266 vd.getProp<path_s>(p).resize(dim);
1267 vd.getProp<path_s>(p).setZero(dim);
1268 vd.getProp<path_c>(p).resize(dim);
1269 vd.getProp<path_c>(p).setZero(dim);
1270 vd.getProp<stop>(p) =
false;
1271 vd.getProp<iniphase>(p) =
true;
1272 vd.getProp<last_restart>(p) = 0;
1276 for (
size_t i = 0 ; i < hist_size ; i++)
1277 {vd.getProp<fithist>(p)[i] = -1.0;}
1278 vd.getProp<fithist>(p)[0] = 1.0;
1279 vd.getProp<validfit>(p) = 0.0;
1285 if (v_cl.rank() == 0)
1286 {std::cout <<
"Starting PS-CMA-ES" << std::endl;}
1291 best = std::numeric_limits<double>::max();
1296 size_t fun_eval = 0;
1298 while (fun_eval < max_fun_eval && best > 120.000001)
1301 cma_step(vd,i+1,best,best_i,best_sol,fun_eval);
1306 if (v_cl.rank() == 0)
1308 std::cout <<
"Best solution: " << best <<
" with " << fun_eval << std::endl;
1309 std::cout <<
"at: " << std::endl;
1311 for (
size_t i = 0 ; i < best_sol.
size() ; i++)
1313 std::cout << best_sol.get(i) <<
" ";
This class represent an N-dimensional box.
Derivative second order on h (spacing)
Implementation of 1-D std::vector like structure.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
It model an expression expr1 + ... exprn.