-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffnn.h
78 lines (54 loc) · 1.81 KB
/
ffnn.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* ffnn.h
*
* Copyright (c) 2018 Disi A
*
* Author: Disi A
* Email: [email protected]
* https://www.mathworks.com/matlabcentral/profile/authors/3734620-disi-a
*/
#ifndef _ffnn_h
#define _ffnn_h
#ifdef __cplusplus
extern "C" {
#endif
#define MAXIMUM_JSON_TOKEN_SIZE 8192 // Assume about 8000 elements are allowed for the json network
typedef double (*ActivationFunc)(double z);
#define ACTIVATION_TYPE_SIGMOID 0
#define ACTIVATION_TYPE_LINEAR 1
#define ACTIVATION_TYPE_RELU 2
#define ACTIVATION_TYPE_THRESHOLD 3
#define ACTIVATION_TYPE_SOFTMAX 4
typedef struct {
int activation_type;
ActivationFunc activation_func;
int number_of_nodes;
int input_length;
double *weights; // (numberOfNodes * inputLength) A grid, row1, row2, row3 ... to represent a matrix
double *biases; // (NumberOfNodes) A Vector, bias1, bias2, bias3 ... to represent a vector
double *output; // (NumberOfNodes) A Vector, bias1, bias2, bias3 ... to represent a vector
} NetworkLayer;
typedef struct {
// Stores layer sizes and length
int number_of_layers;
int * layer_sizes;
// Stores input and output length summary
int output_length;
int input_length;
// Stores network output
double * output;
NetworkLayer ** layers;
} Network;
// Layer functions
NetworkLayer* create_layer(int numberOfNodes, int inputLength, double* weights, double * biases, const char* activation);
void free_layer(NetworkLayer* network_layer);
double * run_layer(NetworkLayer* network_layer, double* input);
// Network functions
Network* create_network_from_json(char * json_network);
Network* create_network_from_protobuf(void * proto_network_data, int data_size);
void free_network(Network* network);
double * run_network (Network* network, double * input);
#ifdef __cplusplus
}
#endif
#endif /* _ffnn_h */