OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
f15_cec_fun.hpp
1/*
2 * f15_cec_fun.hpp
3 *
4 * Created on: Jan 14, 2018
5 * Author: i-bird
6 */
7
8#ifndef EXAMPLE_NUMERICS_PS_CMA_ES_F15_CEC_FUN_HPP_
9#define EXAMPLE_NUMERICS_PS_CMA_ES_F15_CEC_FUN_HPP_
10
11#include "f15_cec_const.hpp"
12#include <limits>
13#include <math.h>
14
15template<unsigned int dim>
16void Job15(int funcnr,Eigen::VectorXd & vars,double & res)
17{
18 // local used vars
19 double sum,sum1,sum2,prod,e1,e2;
20 int i,j,k;
21 // weierstrass vars
22 int Kmax = 20;
23 const double a_c = 0.5;
24 const double b_c = 3.0;
25
26
27 if (funcnr < 2)
28 {
29 // rastrigin
30 sum = 10.0 * dim;
31 for (size_t i = 0 ; i < dim ; i++)
32 {
33 sum += vars(i)*vars(i);
34 sum -= 10.0*cos(2*M_PI*vars[i]);
35 }
36
37 res = sum;
38 }
39 else if (funcnr < 4)
40 {
41 // weierstrass
42 sum1 = 0.0;
43 sum2 = 0.0;
44 double a_k = 1.0;
45 double b_k = 1.0;
46 for (size_t i = 0 ; i < dim ; i++)
47 {
48 a_k = 1.0;
49 b_k = 1.0;
50 for (size_t j = 0 ; j <= Kmax ; j++, a_k *= a_c,b_k *= b_c)
51 {
52 sum1 = sum1 + a_k * cos((M_PI)*2.0 * b_k * (vars(i)+0.5));
53 }
54 }
55 a_k = 1.0;
56 b_k = 1.0;
57 for (size_t j = 0 ; j <= Kmax ; j++, a_k *= a_c, b_k *= b_c)
58 {
59 sum2 = sum2 + a_k * cos((M_PI)*2.0 * b_k * (0.5));
60 }
61 res = sum1 - sum2*dim;
62 }
63 else if (funcnr < 6)
64 {
65 // griewank
66 prod = 1;
67 sum = 0.0;
68 for (size_t i = 1 ; i <= dim ; i++)
69 {
70 sum= sum + (vars(i-1)*vars(i-1))/4000.0;
71 prod=prod * cos(vars(i-1)/(sqrt(double(i))));
72 }
73 res = sum-prod+1;
74 }
75 else if (funcnr < 8)
76 {
77 // ackley
78 e1 = 0.0;
79 e2 = 0.0;
80 for (size_t i = 0 ; i < dim ; i++)
81 {
82 e1 = e1 + vars(i)*vars(i);
83 e2 = e2 + cos(2.0*M_PI*vars(i));
84 }
85 res = exp(1.0) + 20.0 - 20*exp(-0.2*sqrt(e1/dim));
86 res = res - exp(e2/dim);
87 }
88 else if (funcnr <= 10)
89 {
90 // sphere
91 sum = vars.transpose() * vars;
92 res = sum;
93 }
94}
95
96template<unsigned int dim>
97double hybrid_composition(Eigen::VectorXd & vars)
98{
99 double ZBQLNOR;
100
101 //local used vars
102 double wMax,sumSqr,wSum,w1mMaxPow;
103 int i,j,k;
104 double sumF,t_res;
105 Eigen::VectorXd job_z[10];
106
107 for (size_t i = 0 ; i < 10 ; i++)
108 {job_z[i].resize(dim);}
109
110 double job_w[10];
111 double res = 0.0;
112
113 for (size_t i = 0 ; i < dim ; i++)
114 {
115 if (vars[i] < -5.0 || vars[i] > 5.0)
116 {return std::numeric_limits<double>::infinity();}
117 }
118
119 // get the raw weights
120 wMax = - std::numeric_limits<double>::max();
121 for (size_t i = 0; i < 10 ; i++)
122 {
123 sumSqr = 0.0;
124 //Shift the Input
125 job_z[i] = vars - f15_o[i];
126 sumSqr += (job_z[i].transpose() * job_z[i]);
127
128 job_w[i] = exp(-1.0 * sumSqr / (2.0 * dim));
129
130 if (wMax < job_w[i])
131 {wMax = job_w[i];}
132 }
133
134 // Modify the weights
135 wSum = 0.0;
136
137 w1mMaxPow = 1.0 - wMax*wMax*wMax*wMax*wMax*wMax*wMax*wMax*wMax*wMax;
138 for (size_t i = 0; i < 10 ; i++)
139 {
140 if (job_w[i] != wMax)
141 {job_w[i] = job_w[i]* w1mMaxPow;};
142
143 wSum = wSum + job_w[i];
144 }
145
146 // Normalize the weights
147 for (size_t i = 0; i < 10 ; i++)
148 {job_w[i] /= wSum;}
149
150 sumF = 0.0;
151
152 for (size_t i = 0; i < 10 ; i++)
153 {
154 job_z[i] = job_z[i] / job_lambda[i];
155
156 //calling the basic functions
157
158 Job15<dim>(i,job_z[i],t_res);
159
160 sumF = sumF + job_w[i] * (2000.0*t_res/f15_max[i] + bias[i]);
161 }
162
163 res = sumF + 120;
164
165 return res;
166}
167
168template<unsigned int dim>
169void prepare_f15()
170{
171 // load f15_o
172 for (size_t j = 0 ; j < 10 ; j++)
173 {
174 Eigen::VectorXd fmp(dim);
175 f15_o[j].resize(dim);
176 for (size_t i = 0 ; i < dim ; i++)
177 {
178 f15_o[j](i) = f15_const[j][i];
179 fmp(i) = 5.0 / job_lambda[j];
180 }
181
182 double result;
183 Job15<dim>(j,fmp,result);
184
185 f15_max[j] = fabs(result);
186 }
187}
188
189#endif /* EXAMPLE_NUMERICS_PS_CMA_ES_F15_CEC_FUN_HPP_ */
It model an expression expr1 + ... exprn.
Definition sum.hpp:93