2#include "ae2f/errGlob.h"
3#include <ae2f/Ann/Slp.h>
7static ae2f_AnnActFFN_t Act, ActDeriv;
10Act(ae2f_float_t* r,
const ae2f_float_t* x, size_t i, size_t c) {
11 r[0] = 1.0 / (1.0 + exp(-x[i]));
15ActDeriv(ae2f_float_t* r,
const ae2f_float_t* _output, size_t i, size_t c) {
16 const ae2f_float_t output = _output[i] + 1e-7;
17 r[0] = output * (1.0 - output);
20static ae2f_AnnLossFFN_t LossDeriv;
24LossDeriv(ae2f_float_t* r,
const ae2f_float_t* output,
const ae2f_float_t* target, size_t i, size_t c) {
25 printf(
"output: %f, goal: %f\n", output[i], target[i]);
27 const ae2f_float_t epsilon = 1e-7;
28 ae2f_float_t o_i = output[i];
30 o_i = o_i < epsilon ? epsilon : (o_i > 1.0 - epsilon ? 1.0 - epsilon : o_i);
31 r[0] = (o_i - target[i]) / (c * o_i * (1.0 - o_i));
34const ae2f_float_t prm_inp[4][2] = { 1, 1, 0, 0, 0, 1, 1, 0 };
35const ae2f_float_t goal_andor[4][2] = {
42ae2f_float_t output[2] = {0, };
51#define DIFF_GOOD(a, b) (((a) - (b)) * ((a) - (b))) < THRESHOLD
54 puts(
"Trial: tryand");
63 , Act, ActDeriv, LossDeriv
68 printf(
"Learningrate dump: %f, %f\n", slp->m_learningrate, slp->m_learningrate_bias);
69 printf(
"function points: %p %p %p\n", slp->m_act, slp->m_actderiv, slp->m_lossderiv);
73 for(i = 0 ; i < 2 * 1 + 1; ++i) {
74 slp->m_weight[i << 1] = 0.2;
75 slp->m_weight[(i << 1) + 1] = 0.2;
78 for(i = 0; i < 3000; ++i) {
79 for(j = 0; j <
sizeof(prm_inp) /
sizeof(prm_inp[0]); ++j) {
85 for(j = 0; j <
sizeof(prm_inp) /
sizeof(prm_inp[0]); ++j) {
89 printf(
"Got %f, %f\n", *output, output[1]);
90 if(
DIFF_GOOD(output[0], goal_andor[j][0])) {
91 printf(
"Match. Expected %f\n.", goal_andor[j][0]);
93 printf(
"Expected %f. Unexpected.\n", goal_andor[j][0]);
104 printf(
"Code from tryand: %d\n", err);
#define ae2f_errGlob_NFOUND
Found some errors, but not by parameters. The operation has failed.
uint8_t ae2f_err_t
Informs that this number represents the error.
#define ae2f_AnnSlpPredict