1#define ae2f_NEED_CLASS 0
4#include <ae2f/Ann/Act.h>
6#include <ae2f/Ann/Mlp.h>
7#include <ae2f/Ann/Slp.h>
14 *(r) = 1.0 / (1.0 + exp(-x));
18 *r = output * (1.0 - output);
22 *r = ((output[i] - target[i]) / c);
73 puts(
"MlpTrainXOR-Primal start");
75 puts(
"Configuring mlp");
79 puts(
"Configuring last slp");
85 puts(
"Initializing weights randomly with correct memory layout");
93 mlp_bias[bias_base_l0 +
i] = ((
double)rand() / RAND_MAX) - 0.5;
103 mlp_bias[bias_base_l1 +
i] = ((
double)rand() / RAND_MAX) - 0.5;
106 puts(
"See first output (before training)");
107 for(
i = 0;
i < 4; ++
i) {
112 printf(
"Initial Output for [%d, %d]: %f (goal: %d)\n"
117 for(
j = 0;
j < 99000; ++
j) {
118 for(
i = 0;
i < 4; ++
i) {
120 __ae2f_AnnMlpPredictStream_imp(
121 __test_stack.m_predictsteam, mlp, inp[i], output, mlp_szv,
122 mlp_weights, mlp_bias, mlp_outstream, mlp_acts
125 __ae2f_AnnSlpFetchDelta_imp(
126 __test_stack.m_fetch, slplast, output, &goal_xor[i],
127 ActDeriv, LossDeriv, &mlp_deltastream[MLP_OUT_GREATEST]
130 __ae2f_AnnMlpFollow_imp(
131 __test_stack.m_propagate, mlp, inp[i]
132 , &mlp_deltastream[MLP_OUT_GREATEST],
133 mlp_szv, mlp_outstream, mlp_deltastream,
134 mlp_weights, mlp_bias,
151 puts(
"Training complete.");
153 puts(
"See last output after training");
154 for(
i = 0;
i < 4; ++
i) {
159 printf(
"Final Output for [%d, %d]: %f (goal: %d)\n"
void ae2f_AnnAct_t(ae2f_float_t *ret, ae2f_float_t x)
Customisable activasion function type.
#define ae2f_NONE
Literally nothing.
#define MLP_WEIGHT_STRIDE
const ae2f_float_t goal_xor[4]
ae2f_float_t mlp_weights[(MLP_DEPTH - 1) *MLP_WEIGHT_STRIDE]
ae2f_float_t mlp_bias[(MLP_DEPTH - 1) *MLP_BIAS_STRIDE]
ae2f_float_t mlp_outstream[(MLP_DEPTH - 1) *MLP_OUT_GREATEST]
const ae2f_float_t inp[4][2]
ae2f_AnnAct_t * mlp_acts[MLP_DEPTH - 1]
ae2f_float_t mlp_deltastream[(MLP_DEPTH - 1) *MLP_OUT_GREATEST]
ae2f_AnnAct_t * mlp_actderivs[MLP_DEPTH - 1]
#define __ae2f_AnnMlpPredictStream_imp(...)
#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)
ae2f_AnnMlpFollow_t m_propagate
ae2f_AnnMlpPredictStream_t m_predictsteam
ae2f_AnnSlpFetchDelta_t m_fetch
ae2f_AnnMlpTrain_t m_train