Open GregoryMorse opened 1 year ago
So I am unclear if bounded input parameters of bounded periodic functions are supported.
My current idea to work around the clamping issue is:
# include <QRandomGenerator>
QRandomGenerator randGen;
void init(QJsonObject data) {
if (!init) { randGen.seed(randomSeed); init=true; }
}
void getmargins(vector<Interval> &x)
{
for(size_t i=0;i<x.size();i++)
//x[i]=Interval(0,2*M_PI);
//x[i]=Interval(-INFINITY,INFINITY);
x[i]=Interval(-1e100,1e100);
}
void getSample(vector<double> &x)
{
for(size_t i=0;i<x.size();i++)
x[i]=randGen.generateDouble()*2*M_PI;
}
//f(x)
double funmin(vector<double> &x)
{
for (size_t i = 0; i < x.size(); i++) {
if (x[i] < 0) {
x[i] = fmod(x[i], 2*M_PI) + 2*M_PI;
} else if (x[i] > 2 * M_PI) {
x[i] = fmod(x[i], 2*M_PI);
}
}
...
}
There is a function in problem called getSample() In there you may use your function for sampling that may be different from the margins!
It seems that for problems involving trigonometric functions like sine and cosine, the sampling interval should be e.g. (0, 2*PI).
But the update interval should be unbounded. And controlled by using modular arithmetic e.g. fmod(x, 2PI) or fmod(x, 2PI)+2*PI for negative values.
Currently for example, the ADAM local search is clamping the bounds, not using modular arithmetic. See: https://github.com/itsoulos/OPTIMUS/blob/master/src/Optimus/adam.cpp#L29
Should there be a new function Problem::updateparams(vector &x, vector &adjust) which adds the adjustments and custom bounding e.g. with modulo, clamping, etc?