-
Notifications
You must be signed in to change notification settings - Fork 7
/
createFann.c
62 lines (46 loc) · 1.46 KB
/
createFann.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
/*
* Mex interface for the FANN library
*/
#include "helperFann.h"
#include <stdio.h>
//--------------------------------------------------------------------------------------------------------
//Calling syntax: [ann] = createFann(layers,connectivity);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
//Declarations
const mxArray *xData;
double *xValues;
int j;
int numLayers, lRowLen, lColLen;
if(nrhs == 2){
//do nothing
}else{
mexErrMsgTxt("createFann usage: 'ann = createFann(layers,connectivity''");
return;
}
//Get the layers
xData = prhs[0];
xValues = mxGetPr(xData);
lRowLen = mxGetN(xData);
lColLen = mxGetM(xData);
if(lColLen != 1){
mexErrMsgTxt("Layers must be a vector!");
return;
}
numLayers = lRowLen;
unsigned int *layers = mxCalloc(numLayers, sizeof(unsigned int));
for(j=0;j<numLayers;j++) {
layers[j] = (unsigned int) xValues[j];
}
//Get the connectivity
float connectivity = (float)(mxGetScalar(prhs[1]));
//Create the network
struct fann *ann = createNetwork(numLayers,layers,connectivity);
mxArray *layersCopy = mxDuplicateArray(prhs[0]);
//Create the struct representing this ann in matlab
plhs[0] = createMatlabStruct(ann, layersCopy, connectivity);
//printf("The created network is\n");
//fann_print_connections(ann);
//destroy the ann its no longer needed
fann_destroy(ann);
}
//--------------------------------------------------------------------------------------------------------