-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.c
42 lines (39 loc) · 1019 Bytes
/
utils.c
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
#include "utils.h"
void get_gauss(float mean, float stddev, float *u, float *v) {
float x = 0, y = 0, s = 0.0f;
while (s >= 1.0f || s == 0.0f) {
x = ((float)rand() / ((float)RAND_MAX)) * 2.0f - 1.0f;
y = ((float)rand() / ((float)RAND_MAX)) * 2.0f - 1.0f;
s = x * x + y * y;
}
s = sqrtf(-2.0f * logf(s) / s);
*u = mean + stddev * x * s;
*v = mean + stddev * y * s;
}
int dec_activation(const char* name) {
if (strcmp(name, "none") == 0) {
return NONE;
}
else if (strcmp(name, "relu") == 0) {
return RELU;
}
return -1;
}
int dec_layer_type(const char* name) {
if (strcmp(name, "fc") == 0) {
return FC;
}
else if (strcmp(name, "conv") == 0) {
return CONV;
}
else if (strcmp(name, "max_pool") == 0) {
return MAX_POOL;
}
else if (strcmp(name, "activate") == 0) {
return ACTIVATION;
}
else if (strcmp(name, "batch_norm") == 0) {
return BN;
}
return -1;
}