-
Notifications
You must be signed in to change notification settings - Fork 4
/
mlp.h
135 lines (103 loc) · 4.35 KB
/
mlp.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef AIFI__MLP
#define AIFI__MLP
/* <INCLUDE> *************/
#include "popc.h"
#include "cell.h"
#include "layer.h"
#include "activation.h"
#include "loss.h"
#include "optimization.h"
#include "mlpLayer.h"
#include "training.h"
/* </INCLUDE> ************/
// <DELEGATION> //
delegation bool (fnPtr onMlpTrainEpochBeginDelegate) (mlp ptr nw, double ptr1d inputTable1d, int inputRowMax, int inputColumnMax, double ptr1d targetTable1d, int targetRowMax, int targetColumnMax, int epochCurrent);
delegation bool (fnPtr onMlpTrainEpochEndDelegate) (mlp ptr nw, double ptr1d inputTable1d, int inputRowMax, int inputColumnMax, double ptr1d targetTable1d, int targetRowMax, int targetColumnMax, int epochCurrent);
delegation bool (fnPtr onMlpTrainTupleBeginDelegate) (mlp ptr nw, double ptr inputTuple1d, int inputColumnMax, double ptr targetTuple1d, int targetColumnMax);
delegation bool (fnPtr onMlpTrainTupleEndDelegate) (mlp ptr nw, double ptr inputTuple1d, int inputColumnMax, double ptr targetTuple1d, int targetColumnMax);
// </DELEGATION> //
/* <DEFINE> *************/
//#define REQUIRED STUFFS HERE
/* </DEFINE> ************/
/* <CONST> *************/
//#define REQUIRED STUFFS HERE
/* </CONST> ************/
/* <ENUMERATION> *************/
/* </ENUMERATION> *************/
/* <SUBJECT> *************/
subject mlp {
// <header>
annType annt;
int totalLayerCount;
int inputLayerCount;
int hiddenLayerCount;
int outputLayerCount;
double error;
double deltaErrorGradient;
// </header>
// <body>
mlpLayer ptr2d layer2d;
//mlpLayerSingleton ptr2d layerProto2d;
// </body>
// <footer>
int epochMax;
int epochTally;
int epochCurrent;
int tupleMax;
int tupleTally;
int tupleCurrent;
double ptr2d refInput2d; //ref only
double ptr2d refTarget2d; //ref only
double ptr2d refOutput2d; //ref only
onMlpTrainEpochBeginDelegate onTrainEpochBegin;
onMlpTrainEpochEndDelegate onTrainEpochEnd;
onMlpTrainTupleBeginDelegate onTrainTupleBegin;
onMlpTrainTupleEndDelegate onTrainTupleEnd;
// </footer>
} mlp;
/* </SUBJECT> *************/
/* <PROTOTYPE> *************/
pattern mlpSingleton {
mlp ptr (fnPtr mlpNew) ();
void (fnPtr mlpDel) (mlp ptr nn);
void (fnPtr addLayer) (mlp ptr nw, int cellCount, layerType lt, cellType ct, activationFunctionType aft, lossFunctionType lft, optimizationFunctionType oft);
void (fnPtr train) (mlp ptr nn, double ptr1d inputTable1d, int inputTupleMax, int inputColumnMax, double ptr1d targetTable1d, int targetTupleMax, int targetColumnMax, trainingType tt, int epochMax, int batchSize, double learningRate, double learningMomentumRate);
void (fnPtr trainTuple) (mlp ptr nn, trainingType tt, double ptr input1d, double ptr target1d, double learningRate, double learningMomentumRate);
void (fnPtr predict) (mlp ptr nn, double ptr2d input2d);
void (fnPtr predictTuple) (mlp ptr nn, double ptr input1d);
void (fnPtr setInput) (mlp ptr nn, double ptr input1d);
void (fnPtr setTarget) (mlp ptr nn, double ptr target1d);
void (fnPtr propagateForward) (mlp ptr nn);
void (fnPtr propagateBackward) (mlp ptr nn, double learningRate, double learningMomentumRate);
} mlpSingleton;
/* </PROTOTYPE> ************/
/* <VARIABLE> *************/
/* </VARIABLE> ************/
/* <DECLARATION> *************/
#ifdef Cplusplus
extern "C" {
#endif
//
mlpSingleton ptr mlpSingletonNew ();
// /
//
mlp ptr mlpNew ();
void mlpDel (mlp ptr nn);
void mlpAddInputLayer ();
void mlpAddHiddenLayer ();
void mlpAddOutputLayer ();
void mlpAddLayer (mlp ptr nn, int cellCount, layerType lt, cellType ct, activationFunctionType aft, lossFunctionType lft, optimizationFunctionType oft);
void mlpTrain (mlp ptr nn, double ptr1d inputTable1d, int inputTupleMax, int inputColumnMax, double ptr1d targetTable1d, int targetTupleMax, int targetColumnMax, trainingType tt, int epochMax, int batchSize, double learningRate, double learningMomentumRate);
void mlpTrainTuple (mlp ptr nn, trainingType tt, double ptr input1d, double ptr target1d, double learningRate, double learningMomentumRate);
void mlpPredict (mlp ptr nn, double ptr2d input2d);
void mlpPredictTuple (mlp ptr nn, double ptr input1d);
void mlpSetInput (mlp ptr nn, double ptr input1d);
void mlpSetTarget (mlp ptr nn, double ptr target1d);
void mlpPropagateForward (mlp ptr nn);
void mlpPropagateBackward (mlp ptr nn, double learningRate, double learningMomentumRate);
// /
#ifdef Cplusplus
}
#endif
/* </DECLARATION> ************/
#endif