-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.c
77 lines (54 loc) · 1.91 KB
/
example.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
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
#include <stdio.h>
#include <layers.h>
#include <estimator.h>
int main(int argc, char *argv[])
{
/*Load data*/
int num_features = 4, num_samples = 150;
int batch_size = 10;
float* X = malloc(num_samples*num_features*sizeof(float));
int* Y = malloc(num_samples*sizeof(float));
float f1, f2, f3, f4;
int c;
FILE *file;
file = fopen("iris.txt", "r");
for (int i=0;i<num_samples/batch_size;i++){
for (int j=0; j<batch_size; j++){
fscanf(file, "%f,%f,%f,%f,%d", &f1, &f2, &f3, &f4, &c);
X[i*num_features*batch_size + j+0] = f1;
X[i*num_features*batch_size + j+batch_size] = f2;
X[i*num_features*batch_size + j+2*batch_size] = f3;
X[i*num_features*batch_size + j+3*batch_size] = f4;
Y[i*batch_size + j] = c;
}
}
/*Model*/
struct model model;
int num_layers = 4; /*input layer not counted*/
struct layer input, dense1, dense2, dense3, output;
/*Configure the model*/
model.layers = (struct layer*) malloc((num_layers+1) * sizeof(struct layer));
model.num_layers = num_layers;
/*Configure input layer*/
input.num_nodes = num_features;
input.A = (float*) malloc(sizeof(X));
input.A = X;
model.num_features = num_features;
model.input = input.A;
/*Add layers to the model*/
dense1 = Dense(input, 5);
model.layers[0] = dense1;
dense2 = Dense(dense1, 6);
model.layers[1] = dense2;
dense3 = Dense(dense2, 6);
model.layers[2] = dense3;
output = Dense(dense3, 3);
model.layers[3] = output;
/*Train the model*/
int epochs = 8;
float learning_rate = 0.1;
char *v = argv[1];
int verbose = atoi(v);
model = DDClassifier(model, Y, num_samples, batch_size, epochs, learning_rate, verbose);
return 0;
}