ae2f_docs
Mlp.core.h
1#ifndef ae2f_Ann_Mlp_core_h
2#define ae2f_Ann_Mlp_core_h
3
4#include <ae2f/Call.h>
5#include <ae2f/Cast.h>
6
7#include <ae2f/Pack/Beg.h>
8#include "./Act.h"
9
10ae2f_structdef(struct, ae2f_AnnMlp);
11
12/**
13 * @brief
14 * # Multi Layered Perceptron
15 *
16 * This is a data-only structure, used for type-punning.
17 */
18ae2f_structdef(struct, ae2f_AnnMlp_t)
19{
20 /**
21 * @brief
22 * Depth of the network, including input and output layers.
23 */
24 size_t m_depth;
25
26 /**
27 * @brief
28 * Possible greatest output size.
29 */
30 size_t m_outc;
31
32 /** @brief possible greatest weight page size */
33 size_t m_weightc;
34};
35
36/**
37 * @brief
38 * Structure used for MLP prediction.
39 */
40ae2f_structdef_n(struct, ae2f_AnnMlpPredict_t, ae2f_AnnMlpPredictStream_t) {
41 /**
42 * @brief
43 * Input, output, and loop counters.
44 */
45 size_t m_inc, m_outc, m_i, m_j, m_k, m_depth, m_outc_max;
46
47 /**
48 * @brief
49 * Return value.
50 */
51 ae2f_float_t m_ret;
52};
53
54/**
55 * @brief
56 * A union for type-punning pointers during MLP initialization.
57 * This allows treating a block of memory as different pointer types.
58 */
59ae2f_structdef(union, ae2f_AnnMlpInitMkPtr_t) {
60 /**
61 * @brief
62 * Pointer to an MLP structure.
63 */
64 ae2f_AnnMlp* ae2f_restrict m_mlp;
65 /**
66 * @brief
67 * Pointer to a size_t array.
68 */
69 size_t* ae2f_restrict m_sz;
70 /**
71 * @brief
72 * Pointer to a float array.
73 */
74 ae2f_float_t* ae2f_restrict m_f;
75 /**
76 * @brief
77 * Generic void pointer.
78 */
79 void* ae2f_restrict m_void;
80 /**
81 * @brief
82 * Generic pointer to a pointer.
83 */
84 void** ae2f_restrict m_ptr;
85 /**
86 * @brief
87 * Pointer to an array of activation functions.
88 */
89 ae2f_AnnActFFN_t** ae2f_restrict m_Act;
90 /**
91 * @brief
92 * Pointer to an array of loss functions.
93 */
94 ae2f_AnnLossFFN_t** ae2f_restrict m_Loss;
95
96 /** for 1-byte padding */
97 char* ae2f_restrict m_byte;
98};
99
100/**
101 * @brief
102 * Structure for MLP initialization data.
103 */
104ae2f_structdef(struct, ae2f_AnnMlpInit_t) {
105 /**
106 * @brief
107 * Maximum output count among all layers.
108 */
109 size_t m_outc;
110 size_t m_weightc;
111
112 /**
113 * @brief
114 * Loop counter.
115 */
116 size_t m_i;
117};
118
119/**
120 * @brief
121 * Structure for MLP creation data.
122 */
123ae2f_structdef(struct, ae2f_AnnMlpMk_t) {
124 /**
125 * @brief
126 * Maximum output count among all layers.
127 */
128 size_t m_outc;
129
130 /** @brief Maximum weight page size */
131 size_t m_weightc;
132
133 /**
134 * @brief
135 * Loop counter.
136 */
137 size_t m_i;
138 /**
139 * @brief
140 * Union for pointer manipulation during creation.
141 */
142 ae2f_AnnMlpInitMkPtr_t m_mkptr;
143 /**
144 * @brief
145 * Base pointer to the created MLP.
146 */
147 ae2f_AnnMlp* ae2f_restrict m_mkbase;
148};
149
150/**
151 * @brief
152 * Structure for calculating a single hidden delta value.
153 */
154ae2f_structdef(struct, ae2f_AnnMlpHidDeltaSingle_t) {
155 /**
156 * @brief delta seed, not delta.
157 * Use __ae2f_AnnBwd to make delta.
158 * */
159 ae2f_float_t m_ret;
160 /**
161 * @brief
162 * Output count of the layer.
163 */
164 size_t m_outc;
165 /**
166 * @brief
167 * Loop counter.
168 */
169 size_t m_i;
170};
171
172/**
173 * @brief
174 * Stack data for backpropagation.
175 * @deprecated This is deprecated.
176 */
177ae2f_structdef_n(union, ae2f_AnnMlpBwdAllStack_t, ae2f_AnnMlpFollowStack_t) {
178 size_t m_send;
179};
180
181/**
182 * @brief
183 * Structure for backpropagation through all layers.
184 * @deprecated This is deprecated.
185 */
186ae2f_structdef_n(struct, ae2f_AnnMlpBwdAll_t, ae2f_AnnMlpFollow_t) {
187 /**
188 * @brief
189 * Loop counters and layer sizes.
190 */
191 size_t m_i, m_j, m_inc, m_outc;
192 /**
193 * @brief
194 * Layer index.
195 */
196 size_t m_k;
197 /**
198 * @brief
199 * Page size for weights.
200 */
201 size_t m_pg_weight;
202 /**
203 * @brief
204 * Page size for outputs.
205 */
206 size_t m_pg_out;
207 /**
208 * @brief
209 * Stack for propagation.
210 */
211 ae2f_AnnMlpBwdAllStack_t m_stack;
212 /**
213 * @brief
214 * Return value.
215 */
216 ae2f_float_t m_ret;
217};
218
219/**
220 * @brief
221 * Structure for MLP training data.
222 */
223ae2f_structdef(struct, ae2f_AnnMlpTrain_t) {
224 /**
225 * @brief
226 * Loop counters and layer sizes.
227 */
228 size_t m_i, m_j, m_inc, m_outc;
229 /**
230 * @brief
231 * Layer index.
232 */
233 size_t m_k;
234 /**
235 * @brief
236 * Page size for weights.
237 */
238 size_t m_pg_weight;
239 /**
240 * @brief
241 * Page size for outputs.
242 */
243 size_t m_pg_out;
244 /**
245 * @brief
246 * Maximum output size.
247 */
248 size_t m_outc_max;
249 /**
250 * @brief
251 * Network depth.
252 */
253 size_t m_depth;
254
255 /**
256 * @brief
257 * Stack for propagation.
258 */
259 ae2f_AnnMlpBwdAllStack_t m_stack;
260 /**
261 * @brief
262 * Return value.
263 */
264 ae2f_float_t m_ret, m_tmp, m_tmp1;
265};
266
267#include <ae2f/Pack/End.h>
268
269#endif
#define ae2f_AnnActDerivFFN_PASS(r, o, i, c)
Definition Act.h:28
#define ae2f_AnnActFFN_PASS(r, o, i, c)
Definition Act.h:27
#define ae2f_structdef(key, name)
Definition Cast.h:110
#define ae2f_reinterpret_cast(t, v)
Definition Cast.h:52
#define unless(...)
Invokes when condition is false.
Definition Cast.h:103
#define ae2f_extern
Suggests the existence of external variable or function, in naming of C. [non-mangling].
Definition Cast.h:88
#define ae2f_structdef_n(key, name,...)
Definition Cast.h:109
#define ae2f_reg
Register keyword.
Definition Reg.h:12
#define ae2f_WhenCXX(...)
Appears when the current language is C.
Definition Cxx.h:37
#define ae2f_NONE
Literally nothing.
Definition Cxx.h:16
#define ae2f_LP(...)
Definition Guide.h:23
#define ae2f_FREE(...)
Definition Guide.h:33
#define ae2f_opt
Definition Guide.h:26
#define ae2f_errGlob_ALLOC_FAILED
stdlib allocating functions (malloc, calloc, realloc) has been failed.
Definition errGlob.h:40
uint8_t ae2f_err_t
Informs that this number represents the error.
Definition errGlob.h:19
#define ae2f_errGlob_PTR_IS_NULL
Failed to refer the pointer either l-value inside the function.
Definition errGlob.h:32
#define ae2f_errGlob_IMP_NOT_FOUND
Failed to find the function on preprocessor which is callable for some reason No operation has beed d...
Definition errGlob.h:28
#define __ae2f_MACRO_GENERATED
Definition Conv.auto.h:2
#define ae2f_MAC_BUILD
Definition Util.h:5
#define ae2f_NEED_CLASS
Definition Mlp.cl.c:8
#define OPER_NONE
Definition Mlp.def.c:21
#define OPER_NEG
Definition Mlp.def.c:20
#define __ae2f_AnnMlpSz_imp(ret_sz, outc, weightc, depth, szswap, act, actderiv, deltastream, outcache, weight, bias)
Definition Mlp.auto.h:272
#define __ae2f_AnnMlpMk_C(reterr, retmk, depth, szvector, szswap_opt, act, actderiv, lossderiv, deltastream, outcache, weight, bias, learningrate, learningrate_bias, offset, extra)
Definition Mlp.auto.h:40
#define __ae2f_AnnMlpBwd_imp(v_tmp, v_send, slp_then, retdelta_then, deltaseed, actderiv_then, inp)
delta to delta
Definition Mlp.auto.h:588
#define __ae2f_AnnMlpHidDeltaSingle_imp(v_single, slp, weight, delta, iidx)
Definition Mlp.auto.h:566
#define __ae2f_AnnMlpPredictStream_imp(v_predict, mlp, inp, out, sz, weight, bias, outcache, act_opt)
Definition Mlp.auto.h:554
#define __ae2f_AnnMlpMk_imp(reg_mk, prm_depth, pprm_szvector, propptr_szswap_opt, lppfn_act_opt, lppfn_actderiv_opt, pfn_lossderiv, propptr_deltastream_opt, propptr_outcache_opt, propptr_weight_opt, propptr_bias_opt, prm_learningrate, prm_learningrate_bias, prm_offset_opt, prm_extra_opt)
Automatically allocates ae2f_AnnMlp and store its pointer at (reg_mk).m_mkbase.
Definition Mlp.auto.h:163
#define __ae2f_AnnMlpInitWithOutSz_imp(v_mlp, v_init, depth, outsz, weightsz, szvector, szswap_opt, act, actderiv, lossderiv, deltastream, outcache, weight, bias, learningrate, learningrate_bias)
Definition Mlp.auto.h:303
#define __ae2f_AnnMlpPredictStream_C(reterr, mlp, inp, out)
Definition Mlp.auto.h:557
#define __ae2f_AnnMlpPredict_C(reterr, mlp, inp, delta)
Definition Mlp.auto.h:563
#define __ae2f_AnnMlpTrainPrimal(OPER_NEG, OPER_NONE, reterr, mlp, inp, out, out_desired)
Definition Mlp.auto.h:884
#define __ae2f_AnnMlpFollowPrimal_imp(OPER_NEG, OPER_NONE, v_follow, mlp, inp, delta, lenv, outstream, deltacache, weight, bias, learningrate, learningrate_bias, actderiv)
Definition Mlp.auto.h:615
#define __ae2f_AnnMlpPredictPrimal_imp(OPER_NEG, OPER_NONE, v_predict, mlp, inp, out, sz, weight, bias, outcache, act_opt)
layer must be more than 2
Definition Mlp.auto.h:397
#define __ae2f_AnnMlpTrainAuto_C(reterr, mlp, inp, out_desired)
Definition Mlp.auto.h:961
#define __ae2f_AnnMlpTrainAutoPrimal(OPER_NEG, OPER_NONE, reterr, mlp, inp, out_desired)
Definition Mlp.auto.h:915
#define __ae2f_AnnMlpTrain_C(reterr, mlp, inp, out, out_desired)
Definition Mlp.auto.h:947
#define __ae2f_AnnMlpTrainAutoStream_C(reterr, mlp, inp, out_desired)
Definition Mlp.auto.h:965
#define __ae2f_AnnMlpDel_C(a)
Definition Mlp.auto.h:38
#define __ae2f_AnnMlpPredictPrimal(OPER_NEG, OPER_NONE, reterr, mlp, inp, out)
Definition Mlp.auto.h:524
#define __ae2f_AnnMlpTrainStream_C(reterr, mlp, inp, out, out_desired)
Definition Mlp.auto.h:950
#define __ae2f_AnnMlpFollowPrimal(OPER_NEG, OPER_NONE, reterr, mlp, inp, delta)
Definition Mlp.auto.h:785
#define __ae2f_AnnMlpTrainPrimal_imp(OPER_NEG, OPER_NONE, v_train, mlp, inp, out, out_desired, lenv, outstream, deltacache, weight, bias, learningrate, learningrate_bias, act, actderiv, lossderiv)
Definition Mlp.auto.h:822
#define __ae2f_AnnMlpFollowStream_C(reterr, mlp, inp, delta)
Definition Mlp.auto.h:819
#define __ae2f_AnnMlpFollow_C(reterr, mlp, inp, delta)
Definition Mlp.auto.h:816
#define ae2f_AnnMlpTrain
Definition Mlp.h:295
#define ae2f_AnnMlpTrainAutoStream
Definition Mlp.h:298
#define ae2f_AnnMlpFollow
Definition Mlp.h:293
#define ae2f_AnnMlpPredict
Definition Mlp.h:291
#define ae2f_AnnMlpTrainStream
Definition Mlp.h:296
#define ae2f_AnnMlpFollowStream
Definition Mlp.h:294
#define ae2f_AnnMlpPredictStream
Definition Mlp.h:292
#define ae2f_AnnMlpTrainAuto
Definition Mlp.h:297
#define __ae2f_AnnSlpFollow_imp(reg_follow, prm_slp, pprm_in, pprm_delta, ptr_weight, ptr_bias, prm_learningrate, prm_learningrate_bias)
Definition Slp.auto.h:435
#define __ae2f_AnnSlpInit_imp(...)
Definition Slp.auto.h:129
#define __ae2f_AnnSlpFit_C(...)
Definition Slp.auto.h:870
#define __ae2f_AnnSlpFollow_C(...)
Definition Slp.auto.h:524
#define __ae2f_AnnSlpFollowOne_imp(reg_follow, pprm_in, pprm_delta, ptr_weight, prm_learningrate, prm_learningrate_bias, prm_isz, prm_oidx, rret_bias)
Definition Slp.auto.h:410
#define __ae2f_AnnSlpMk_imp(...)
Definition Slp.auto.h:267
#define __ae2f_AnnSlpFetchDelta_imp(tmp_delta, prm_slp, pprm_out, pprm_out_desired, fn_actderiv, fn_lossderiv, pret_delta)
Definition Slp.auto.h:586
#define __ae2f_AnnSlpTrainVerbose_imp(ram_train, reg_train, prm_slp, pprm_inp, pret_out, ptr_out_cache, pprm_out_desired, ptr_weights, ptr_bias, ptr_cachedelta, fn_act, fn_actderiv, fn_lossderiv, prm_learningrate, prm_learningrate_bias)
Definition Slp.auto.h:874
#define __ae2f_AnnSlpPredict(err_opt, _this, prm_in, out, out_cache, weight, bias, act_opt)
Definition Slp.auto.h:311
#define __ae2f_AnnSlpFitVerbose_imp(ram_fit, reg_fit, prm_slp, pprm_inp, pprm_out, pprm_out_desired, ptr_weights, ptr_bias, ptr_cachedelta, fn_actderiv, fn_lossderiv, prm_learningrate, prm_learningrate_bias)
Definition Slp.auto.h:706
#define __ae2f_AnnSlpInit(...)
Definition Slp.auto.h:133
#define __ae2f_AnnSlpFit(reterr_opt, _this, prm_inp, prm_out, prm_out_desired, weights, bias, cachedelta, actderiv_opt, lossderiv, learningrate, learningrate_bias)
Definition Slp.auto.h:769
#define __ae2f_AnnSlpFetchDelta_C(...)
Definition Slp.auto.h:701
#define __ae2f_AnnSlpDel_C
Definition Slp.auto.h:20
#define __ae2f_AnnSlpTrain_C
Definition Slp.auto.h:984
#define __ae2f_AnnSlpInit_C
Definition Slp.auto.h:139
#define __ae2f_AnnSlpFetchDeltaVerbose_imp(ram_delta, reg_delta, prm_slp, pprm_out, pprm_out_desired, fn_actderiv, fn_lossderiv, pret_delta)
Definition Slp.auto.h:550
#define __ae2f_AnnSlpFollow(reterr_opt, _this, prm_in, delta, weight, bias, learningrate, learningrate_bias)
Definition Slp.auto.h:464
#define __ae2f_AnnSlpPredict_imp(reg_predict, prmreg_slp, pprm_in, ret, ptr_outcache, pprm_weight, pprm_bias, fn_act)
Definition Slp.auto.h:278
#define __ae2f_AnnSlpTrain(err, slp, inp, out_cache, out_desired, weights, bias, cachedelta, act, actderiv, lossderiv, learningrate, learningrate_bias)
Definition Slp.auto.h:989
#define __ae2f_AnnSlpInitInpSz_imp(...)
Definition Slp.auto.h:125
#define __ae2f_AnnSlpMk(...)
Definition Slp.auto.h:271
#define __ae2f_AnnSlpMk_C
Definition Slp.auto.h:275
#define __ae2f_AnnSlpPredict_C(...)
Definition Slp.auto.h:376
#define ae2f_AnnSlpMk
Definition Slp.h:263
#define ae2f_AnnSlpDel
Definition Slp.h:264
#define ae2f_AnnSlpTrain
Definition Slp.h:268
#define ae2f_AnnSlpPredict
Definition Slp.h:265
#define ae2f_AnnSlpFollow
Definition Slp.h:266
#define ae2f_AnnSlpFit
Definition Slp.h:267
#define ae2f_MAC(...)
Definition mac.h:28