44 this->search = search;
46 this->minEstimatedFit = minEstimatedFit;
48 autoRelaxation =
true;
52 autoRelaxation =
false;
63 ISearch::~ISearch() {}
70 double r = (autoRelaxation ? 0.99 : R);
73 r = (autoRelaxation ? max(r*r, R) : r);
77 pS = adjustLog(r, pT);
78 }
while(
getNEvals() < M && (r > R || pS == -1));
81 int CSMOn::adjustExp(
double r) {
84 if(s-sPrev < 2)
return -1;
86 double alpha1, alpha2;
88 if(decayE() < r && decayL() < r){
91 alpha2 = alphaE(pB, s);
95 alpha2 = alphaE(pB, s);
96 if(alpha2 < alpha1)
return s;
105 int CSMOn::adjustLog(
double r,
int pT) {
108 if(s-sPrev < 3)
return -1;
109 double alpha1 = alphaP(pT, s-1);
110 double alpha2 = alphaP(pT, s);
111 while(alpha2 >= alpha1 &&
getNEvals() < M){
112 if(decayE() >= r || decayL() >= r)
return -1;
115 alpha2 = alphaP(pT, s);
120 void CSMOn::getBest(
int nBest) {
121 for(
int i=0; i < nBest && search->
getNEvals() < M; i++){
128 double CSMOn::decayE() {
129 return fabs(1 - (gb[s].y-minEstimatedFit) / (gb[s-1].y-minEstimatedFit));
132 double CSMOn::decayL() {
133 return fabs(1 - (gb[s].y-gb[s-1].y) / (gb[s-1].y-gb[s-2].y));
136 double CSMOn::alphaE(
int p1,
int p2) {
137 int i, n = p2 - p1 + 1;
138 double yAvg = 0, yAvgLn, ySumLn = 0, xSum = 0, xAvg, S1 = 0, S2 = 0, aux;
139 for(i=p1; i <= p2; i++){
142 ySumLn += log(gb[i].y);
147 for(i=p1; i <= p2; i++){
148 aux = (gb[i].x - xAvg);
149 S1 += aux * (gb[i].y - yAvgLn);
152 return (ySumLn - (S1 / S2) * xSum) / n;
155 double CSMOn::alphaP(
int p1,
int p2) {
156 int i, n = p2 - p1 + 1;
157 double yAvgLog, ySumLog = 0, xAvgLog, xSumLog = 0, S1 = 0, S2 = 0, aux;
158 for(i=p1; i <= p2; i++){
159 xSumLog += log10(gb[i].x);
160 ySumLog += log10(gb[i].y);
162 xAvgLog = xSumLog / n;
163 yAvgLog = ySumLog / n;
164 for(i=p1; i <= p2; i++){
165 aux = (log10(gb[i].x) - xAvgLog);
166 S1 += aux * (log10(gb[i].y) - yAvgLog);
169 return (ySumLog - (S1 / S2) * xSumLog) / n;
CSMOn(ISearch *search, int M, double R, double minEstimatedFit)
Class for CSMOn.
A point representing the number of evaluations and the respective fitness value.
virtual void startup()=0
Startup the search method.
The interface that the search methods must to implement.
int getBestPos(double *x)
Get the final optimized result (position).
virtual double getFitness()=0
Get the best fitness value found up to the moment.
void run()
Call this method to execute the search.
virtual void next(int M)=0
Obtain the next improvement.
virtual int getNEvals()=0
Get the number of fitness function evaluations performed up to the moment.
double getFitness()
Get the final fitness value.
void search(char *method, Param *inParam, Param *outParam, double *outPos, callback_t fitnessFunction)
The wrapper function for Python calls.
virtual int getBestPos(double *_x)=0
Get the best result obtained up to the moment.
int getNEvals()
Get the actual number of evaluations executed.