1#define ae2f_MAC_BUILD OFF
3#include "ae2f/Float.auto.h"
5#include <ae2f/Ann/Mlp.h>
9static void Act(
ae2f_float* r,
const ae2f_float_t* x, size_t i, size_t c) {
10 *r = 1.0 / (1.0 + exp(-x[i]));
13static void ActDeriv(ae2f_float_t* r,
const ae2f_float_t* output, size_t i, size_t c) {
14 *r = output[i] * (1.0 - output[i]);
17static void LossDeriv(ae2f_float_t* r,
const ae2f_float_t* output,
const ae2f_float_t* target, size_t i, size_t c) {
18 *r = ((output[i] - target[i]) / c);
21const ae2f_float_t inp[4][2] = {
28const ae2f_float_t goal_xor[4] = {0, 1, 1, 0};
30ae2f_float_t output[1] = { 0.5 };
33size_t lenv[] = {2, 3, 3, 1};
47 assert(mlp->m_learningrate != 0);
48 assert(mlp->m_learningrate_bias != 0);
50 for(i = 0; i < 3; i++) {
52 mlp->m_actderiv[i] = ActDeriv;
53 for(j = 0; j < 9; j++) {
54 mlp->m_weight[j + i * 9] = ((
double)rand() / RAND_MAX) - 0.5;
57 for(j = 0; j < 3; j++) {
58 mlp->m_bias[j] = ((
double)rand() / RAND_MAX) - 0.5;
63 printf(
"[Error]: %d\n", err[0]);
64 assert(0 &&
"errval has occurred.");
67 for(j = 0; j < 4; j++) {
69 assert(!err[0] &&
"err from predict");
70 printf(
"%f %f -> %f\n", inp[j][0], inp[j][1], output[0]);
73 for(i = 0; i < 99000; i++) {
74 for(j = 0; j < 4; j++) {
79 assert(!err[0] &&
"err from TrainAutoStream");
83 for(j = 0; j < 4; j++) {
85 assert(!err[0] &&
"err from predict");
86 printf(
"%f %f -> %f\n", inp[j][0], inp[j][1], output[0]);
uint8_t ae2f_err_t
Informs that this number represents the error.
#define ae2f_AnnMlpTrainAutoStream
#define ae2f_AnnMlpPredict