-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestProblemToolbox.cu
204 lines (186 loc) · 4.45 KB
/
testProblemToolbox.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include "vegasconst.h"
#define CUDART_PI_F 3.141592654f
__device__
float sum(float* rx, int dim)
{
float value = 0.f;
for (int i = 0; i < dim; i++){
value += rx[i];
}
value = 1.f / sqrt((float)dim/12.f) * (value - (float)dim / 2.f);
return value;
}
__device__
float sqsum(float* rx, int dim)
{
float value = 0.f;
for (int i = 0; i < dim; i++){
value += rx[i] * rx[i];
}
value = sqrtf(45.f / (4.f * (float)dim)) * (value - (float)dim / 3);
return value;
}
__device__
float sumsqroot(float* rx, int dim)
{
float value = 0.f;
for (int i = 0; i < dim; i++){
value += sqrtf(rx[i]);
}
value = sqrtf(18.f / (float)dim) * (value - 2.f/3.f * (float)dim);
return value;
}
__device__
float prodones(float* rx, int dim)
{
float value = 1.f;
for (int i = 0; i < dim; i++){
value *= copysignf(1.f, rx[i]-0.5f);
}
return value;
}
__device__
float prodexp(float* rx, int dim)
{
float e = sqrtf((15.f * expf(15.f) + 15.f) / (13.f * expf(15.f) + 17.f));
e = powf(e, float(dim) * 0.5f);
float value = 1.f;
for (int i = 0; i < dim; i++){
value *= ((expf(30.f * rx[i] - 15.f)) - 1.f) / (expf(30.f * rx[i] - 15.f) + 1.f);
}
value *= e;
return value;
}
__device__
float prodcub(float* rx, int dim)
{
float value = 1.f;
for (int i = 0; i < dim; i++){
value *= (-2.4f*sqrtf(7.f)*(rx[i]-0.5f)+8.f*sqrtf(7.f)*(rx[i]-0.5f)*(rx[i]-0.5f)*(rx[i]-0.5f));
}
return value;
}
__device__
//PRODX has a lot of extremes when dimensions are big, it's expected to not do well
float prodx(float* rx, int dim)
{
float value = 1.f;
for (int i = 0; i < dim; i++){
value *= (rx[i] - 0.5f);
}
value *= powf(2.f*sqrtf(3.f), (float) dim);
return value;
}
__device__
float sumfifj(float* rx, int dim)
{
float value = 0.f;
for (int i = 0; i < dim; i++){
float aux = 0.f;
for (int j = 0; j < i; j++){
aux += copysignf(1.f,(1.f/6.f-rx[j])*(rx[j]-4.f/6.f));
}
value += copysignf(1.f,(1.f/6.f-rx[i])*(rx[i]-4.f/6.f))*aux;
}
value *= sqrtf(2.f/(float)(dim*(dim-1)));
return value;
}
__device__
float sumfonefj(float* rx, int dim)
{
float value = 0.f;
for (int i = 1; i < dim; i++){
value += 27.20917094*rx[i]*rx[i]*rx[i]-36.1925085*rx[i]*rx[i]+8.983337562*rx[i]+0.7702079855;
}
value *= (27.20917094*rx[0]*rx[0]*rx[0]-36.1925085*rx[0]*rx[0]+8.983337562*rx[0]+0.7702079855)/sqrtf((float)dim-1.f);
return value;
}
__device__
float hellekalek(float* rx, int dim)
{
float value = 1.f;
for (int i = 0; i < dim; i++){
value *= ((rx[i] - 0.5f)/sqrtf(12.f));
}
return value;
}
__device__
float roosarnoldone(float* rx, int dim)
{
float value = 1.f/(float)dim;
float aux = 0.f;
for (int i = 0; i < dim; i++){
aux += fabsf(4.f*rx[i]-2.f)-1.f;
}
value *= aux;
return value;
}
__device__
//Can give huge error
float roosarnoldtwo(float* rx, int dim)
{
float value = sqrtf(1.f/(powf(4.f/3.f, (float)dim)-1.f));
for (int i = 0; i < dim; i++){
value *= (fabsf(4.f*rx[i]-2.f) - 1.f);
}
return value;
}
__device__
float roosarnoldthree(float* rx, int dim)
{
float value = 1.f/sqrtf(powf(CUDART_PI_F*CUDART_PI_F/8.f, (float)dim)-1.f);
for (int i = 0; i < dim; i++){
value *= (CUDART_PI_F/2.f*sinf(CUDART_PI_F*rx[i])-1.f);
}
return value;
}
__device__
//Choosing only RST1, since it's the most difficult.
float rst(float* rx, int dim)
{
float value = 1.f/sqrtf(powf(1.f+1.f/12.f,(float)dim)-1.f);
for (int i = 0; i < dim; i++){
value *= ((fabsf(4.f*rx[i]-2.f)+1.f)/2.f-1.f);
}
return value;
}
__device__
float sobolprod(float* rx, int dim)
{
float value = 1.f;
for (int i = 0; i < dim; i++){
value *= (1.f+1.f/((float)(3*(i+2)*(i+2))));
}
value = sqrtf(1.f/(value-1.f));
for (int i = 0; i < dim; i++){
value *= ((float)(i+1)+2.f*rx[i])/(float)(i + 2)-1.f;
}
return value;
}
__device__
//Choosing beta = 1 and alpha_i = 1 for every i.
float oscill(float* rx, int dim)
{
float value = 2.f*CUDART_PI_F;
float p = 1.f;
for (int i = 0; i < dim; i++){
value += rx[i];
p *= sinf(0.5f);
}
value = cosf(value)-powf(2.f, (float)dim)*cosf(2.f*CUDART_PI_F+0.5f*(float)dim)*p;
return value;
}
__device__
//Choosing beta_i = 0.5 and alpha_i = 1 for every i.
float prpeak(float* rx, int dim)
{
float value = 1.f;
float e = 1.f;
for (int i = 0; i < dim; i++){
value *= 1.f/(1+(rx[i]-0.5f)*(rx[i]-0.5f));
e *= (atanf(0.5f)-atanf(-0.5f));
}
value += -e;
return value;
}
//There are 4 functions missing from the document (CORPEAK, GAUSSIAN, C0 and DISCONT), but it gets really hard from here on to estimate numbers and I prefer stopping here. 17 is a good enough number of test functions.