31 template <
class MatType = mat,
class VecType = vec>
33 return arma::abs(arma::repmat(arma::sum(x % x,0), Y.n_cols,1) + arma::sum(Y % Y,0).t() - 2*Y.t()*x);
47 template <
class MatType = mat>
49 MatType dists = - 2*(X.t()*Y);
50 dists.each_row() += arma::sum(Y % Y, 0);
51 dists.each_col() += arma::sum(X % X, 0).t();
52 dists = arma::abs(dists);
67 return (x - xLow)/(xUp - xLow);
81 return (X - arma::repmat(xLow, 1, X.n_cols))/arma::repmat(xUp - xLow, 1, X.n_cols);
95 return xLow + (xUp - xLow) % x;
109 return arma::repmat(xLow, 1, X.n_cols) + arma::repmat(xUp - xLow, 1, X.n_cols) % X;
120 double xMin = arma::min(x);
121 double xMax = arma::max(x);
123 return arma::ones(x.n_elem);
125 return (x - xMin)/(xMax - xMin);
154 mMaxEvals = maxEvals;
157 mfX = std::numeric_limits<double>::max() * arma::ones<vec>(
mMaxEvals);
158 mfBest = std::numeric_limits<double>::max();
159 mX = std::numeric_limits<double>::max() * arma::ones<mat>(
dim, maxEvals);
160 mxBest = std::numeric_limits<double>::max() * arma::ones<mat>(
dim);
184 throw std::logic_error(
"No evaluations have been added!");
186 return mfX.rows(0, mNumEvals-1);
195 throw std::logic_error(
"No evaluations have been added!");
197 return mX.cols(0, mNumEvals-1);
206 throw std::logic_error(
"No evaluations have been added!");
217 throw std::logic_error(
"No evaluations have been added!");
228 if(mNumEvals >= mMaxEvals) {
229 throw std::logic_error(
"Capacity exceeded");
232 mX.col(mNumEvals) = x;
233 mfX(mNumEvals) = funVal;
234 if (funVal < mfBest) {
246 for(
int i=0; i < X.n_cols; i++) {
255 mX = std::numeric_limits<double>::max() * arma::ones<mat>(
mDim,
mMaxEvals);
256 mxBest = std::numeric_limits<double>::max() * arma::ones<mat>(
mDim);
257 mfX = std::numeric_limits<double>::max() * arma::ones<vec>(
mMaxEvals);
258 mfBest = std::numeric_limits<double>::max();
273 if(x.n_rows != y.n_rows) {
274 throw std::logic_error(
"paretoFront: x and y need to have the same length");
276 uvec isort = sort_index(x);
279 uvec indvec = arma::ones<uvec>(x.n_rows);
280 indvec(0) = isort(0);
284 for(
int i=1; i < x.n_rows; i++) {
286 indvec(indcur) = isort(i);
291 indvec = indvec.head(indcur);
305 for(
int i=1; i < x.n_elem; i++) {
306 out(i) = std::min(x(i), out(i-1));
322 std::chrono::time_point<std::chrono::system_clock> mStartTime;
323 std::chrono::time_point<std::chrono::system_clock> mEndTime;
338 if(mStarted) {
throw std::logic_error(
"StopWatch: The StopWatch is already running, so can't start!"); }
339 mStartTime = std::chrono::system_clock::now();
348 if(not mStarted) {
throw std::logic_error(
"StopWatch: The StopWatch is not running, so can't stop!"); }
349 mEndTime = std::chrono::system_clock::now();
351 std::chrono::duration<double> elapsedSeconds = mEndTime - mStartTime;
352 return elapsedSeconds.count();
365 std::uniform_int_distribution<int>
randi(0, i);
376 std::normal_distribution<double>
randn(0.0, 1.0);
387 std::uniform_real_distribution<double>
rand(0, 1);
400 arma::arma_rng::set_seed_random();
403 typedef std::chrono::high_resolution_clock myClock;
404 myClock::time_point beginning = myClock::now();
405 myClock::duration d = myClock::now() - beginning;
406 unsigned newSeed = d.count();
418 arma::arma_rng::set_seed(seed);
Optimization result class.
Definition: utils.h:138
vec fX() const
Method for getting the values of the finished evaluations.
Definition: utils.h:182
Stop watch class.
Definition: utils.h:320
double fBest() const
Method for getting the value of the best solution found so far.
Definition: utils.h:215
arma::vec vec
Default (column) vector class.
Definition: common.h:17
void setSeedRandom()
Set the seed to a random seed.
Definition: utils.h:398
vec xBest() const
Method for getting the best solution found so far.
Definition: utils.h:204
void addEvals(const mat &X, const vec &funVals)
Method for adding a finished evaluations.
Definition: utils.h:245
double stop()
Stops the watch and returns the time elapsed.
Definition: utils.h:347
arma::uvec uvec
Default unsigned (column) vector class.
Definition: common.h:22
int mMaxEvals
Definition: utils.h:142
int mNumEvals
Definition: utils.h:140
vec cumMin(const vec &x)
Computes the cumulative minimum.
Definition: utils.h:302
double rand()
Generate a U[0,1] realization.
Definition: utils.h:386
double randi(int i)
Generate a random integer.
Definition: utils.h:364
vec mxBest
Definition: utils.h:146
int mDim
Definition: utils.h:141
int dim() const
Method for getting the number of dimensions.
Definition: utils.h:166
MatType squaredPairwiseDistance(const MatType &X, const MatType &Y)
Fast level-3 distance computation between two sets of points.
Definition: utils.h:48
vec toUnitBox(const vec &x, const vec &xLow, const vec &xUp)
Map one point to the unit box.
Definition: utils.h:66
Result(int maxEvals, int dim)
Constructor.
Definition: utils.h:153
vec unitRescale(const vec &x)
Map a vector of values to the range [0, 1].
Definition: utils.h:119
VecType squaredPointSetDistance(const VecType &x, const MatType &Y)
Fast level-2 distance computation between one point and a set of points.
Definition: utils.h:32
StopWatch()
Constructor.
Definition: utils.h:330
uvec paretoFront(const vec &x, const vec &y)
Computes the Pareto front.
Definition: utils.h:272
double mfBest
Definition: utils.h:145
vec fromUnitBox(const vec &x, const vec &xLow, const vec &xUp)
Map one point from the unit box to another hypercube.
Definition: utils.h:94
double randn()
Generate a N(0,1) realization.
Definition: utils.h:375
mat X() const
Method for getting the evaluated points.
Definition: utils.h:193
void addEval(const vec &x, double funVal)
Method for adding a finished evaluation.
Definition: utils.h:227
SOT namespace.
Definition: sot.h:27
std::mt19937 mt(0)
The global random number generator.
arma::mat mat
Default matrix class.
Definition: common.h:16
void reset()
Method for resetting the object.
Definition: utils.h:253
int numEvals() const
Method for getting the number of finished evaluations.
Definition: utils.h:174
mat mX
Definition: utils.h:144
vec mfX
Definition: utils.h:143
void setSeed(unsigned seed)
Set the seed to a given seed.
Definition: utils.h:417
void start()
Starts the watch.
Definition: utils.h:337