-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivation_layer.h
55 lines (48 loc) · 1.4 KB
/
activation_layer.h
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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0]))
double *arrtanh(double arr[], int n){
double *ret = (double *)malloc(sizeof(double *) * n);
for(int i=0; i<n; i++){
ret[i] = tanh(arr[i]);
}
return ret;
}
double *arrtanh_prime(double arr[], int n){
double *ret = (double *)malloc(sizeof(double *) *n);
for(int i=0; i<n; i++){
ret[i] = 1-pow(tanh(arr[i]), 2);
}
return ret;
}
struct ActivationLayer{
char *activation;
char *activation_prime;
double input[1000];
double output[1000];
};
void init_ActivationLayer(struct ActivationLayer* AL, char* activation, char* activation_prime){
return;
}
double *act_forward_propogation(struct ActivationLayer* AL, double input_data[], int n){
for(int i=0;i<n; i++){
AL->input[i] = input_data[i];
}
double *ret = (double *)malloc(sizeof(double *) * n);
double *temp = arrtanh(AL->input, n);
for(int i=0;i<n;i++){
AL->output[i] = temp[i];
ret[i] = AL->output[i];
}
return ret;
}
double *act_backward_propogation(struct ActivationLayer* AL, double output_error[], int n, double learning_rate){
double *temp = arrtanh_prime(AL->input, n);
double *ret = (double *)malloc(sizeof(double *) * n);
for(int i=0;i<n; i++){
ret[i] = temp[i] * output_error[i];
}
return ret;
}