1#define ae2f_MAC_BUILD 0
4#include <ae2f/Ann/Mlp.h>
8static void Act(ae2f_float_t* r,
const ae2f_float_t* x, size_t i, size_t c) {
9 *r = 1.0 / (1.0 + exp(-x[i]));
12static void ActDeriv(ae2f_float_t* r,
const ae2f_float_t* output, size_t i, size_t c) {
13 *r = output[i] * (1.0 - output[i]);
16static void LossDeriv(ae2f_float_t* r,
const ae2f_float_t* output,
const ae2f_float_t* target, size_t i, size_t c) {
17 *r = ((output[i] - target[i]) / c);
22LossDerivCROSS(ae2f_float_t* r,
const ae2f_float_t* output,
const ae2f_float_t* target, size_t i, size_t c) {
23 const ae2f_float_t epsilon = 1e-7;
24 ae2f_float_t o_i = output[i];
26 o_i = o_i < epsilon ? epsilon : (o_i > 1.0 - epsilon ? 1.0 - epsilon : o_i);
27 r[0] = (o_i - target[i]) / (c * o_i * (1.0 - o_i));
30const ae2f_float_t prm_inp[4][2] = {
37const ae2f_float_t goal_xor[4] = {0, 1, 1, 0};
39ae2f_float_t output[1] = { 0.5 };
42size_t lenv[] = {2, 3, 1};
57 assert(mlp->m_learningrate != 0);
58 assert(mlp->m_learningrate_bias != 0);
60 for(i = 0; i < 2; i++) {
61 mlp->m_bias[i] = ((
double)rand() / RAND_MAX) - 0.5;
63 mlp->m_actderiv[i] = ActDeriv;
64 for(j = 0; j < 9; j++) {
65 mlp->m_weight[j + i * 9] = ((
double)rand() / RAND_MAX) - 0.5;
70 printf(
"[Error]: %d\n", err[0]);
71 assert(0 &&
"errval has occurred.");
74 for(j = 0; j < 4; j++) {
76 assert(!err[0] &&
"err from predict");
77 printf(
"%f %f -> %f\n", prm_inp[j][0], prm_inp[j][1], output[0]);
80 for(i = 0; i < 9000; i++) {
81 for(j = 0; j < 4; j++) {
86 assert(!err[0] &&
"err from TrainAutoStream");
90 for(j = 0; j < 4; j++) {
92 assert(!err[0] &&
"err from predict");
93 printf(
"%f %f -> %f\n", prm_inp[j][0], prm_inp[j][1], output[0]);
uint8_t ae2f_err_t
Informs that this number represents the error.
#define ae2f_AnnMlpPredict
#define ae2f_AnnMlpTrainAuto