-
Notifications
You must be signed in to change notification settings - Fork 2
/
neural_net.h
61 lines (53 loc) · 1.08 KB
/
neural_net.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
56
57
58
59
60
61
#ifndef NEURAL_NET_H
#define NEURAL_NET_H
/*
// calculate inner product of x[n_in] and W[n_in][n_out]
// resulting array in form of a[n_out]
void dot_xw(int n_in, int n_out, double x[n_in], double W[n_in][n_out], double a[n_out])
{
int i;
for (i=0; i<n_out; i++) {
double a_tmp = 0;
int j;
for (j=0; j<n_in; j++) {
a_tmp += x[j] * W[j][i];
}
a[i] = a_tmp;
}
return;
}
*/
// calculate inner product of x[n_in] and W[n_in][n_out]
// resulting array in form of a[n_out]
void dot_xw(int n_in, int n_out, double x[n_in], double **W, double a[n_out])
{
int i;
for (i=0; i<n_out; i++) {
double a_tmp = 0;
int j;
for (j=0; j<n_in; j++) {
a_tmp += x[j] * W[j][i];
}
a[i] = a_tmp;
}
return;
}
// n: length of array
// a: input array
// b: array of bias
void add_bias(int n, double a[n], double b[n])
{
int i;
for (i=0; i<n; i++) a[i] += b[i];
return;
}
// n: length of array
// a: input array
// z: output array
void call_activation(int n, double a[n], double z[n], double (*activation)(double))
{
int i;
for (i=0; i<n; i++) z[i] = activation(a[i]);
return;
}
#endif