-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnn.h
More file actions
62 lines (48 loc) · 1.86 KB
/
Copy pathnn.h
File metadata and controls
62 lines (48 loc) · 1.86 KB
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
#ifndef NN_H
#define NN_H
typedef struct {
int input_width;
int output_width;
float *weights;
float *biases;
float *weight_grads;
float *bias_grads;
float *input_cache;
float *z_cache;
float *output_cache;
float (*activation)(float);
float (*activation_prime)(float);
} Layer;
Layer *layer_create(int input_width, int output_width,
float (*activation)(float),
float (*activation_prime)(float));
void layer_free(Layer *layer);
typedef struct {
Layer **layers;
int n;
float (*loss)(const float *pred, const float *target, int size);
void (*loss_prime)(const float *pred, const float *target, int size,
float *d_out);
void (*optimizer)(Layer *layer, float learning_rate);
} Network;
Network *network_create(float (*loss)(const float *, const float *, int),
void (*loss_prime)(const float *, const float *, int,
float *),
void (*optimizer)(Layer *, float));
void network_free(Network *net);
void optimizer_sgd(Layer *layer, float learning_rate);
float activation_sigmoid(float x);
float activation_sigmoid_prime(float x);
float activation_relu(float x);
float activation_relu_prime(float x);
float loss_mse(const float *pred, const float *target, int size);
void loss_mse_prime(const float *pred, const float *target, int size,
float *d_out);
int network_save_weights(const Network *net, const char *filename);
int network_load_weights(Network *net, const char *filename);
int network_add(Network *net, Layer *layer);
int network_forward(Network *net, const float *input, float **out_output);
int network_train_step(Network *net, const float *input, const float *target,
float learning_rate);
int forward(Layer *layer, const float *input, float **out_output);
#endif