2#include "ae2f/errGlob.h"
3#include <ae2f/Ann/Slp.h>
8Act(ae2f_float_t* r,
const ae2f_float_t* x, size_t i, size_t c) {
9 *r = 1.0 / (1.0 + exp(-x[i]));
13ActDeriv(ae2f_float_t* r,
const ae2f_float_t* _output, size_t i, size_t c) {
14 const ae2f_float_t output = _output[i] - 1e-7;
15 *r = output * (1.0 - output);
20LossDeriv(ae2f_float_t* r,
const ae2f_float_t* output,
const ae2f_float_t* target, size_t i, size_t c) {
21 ae2f_float_t epsilon = 1e-7;
22 ae2f_float_t o_i = output[i];
24 o_i = o_i < epsilon ? epsilon : (o_i > 1.0 - epsilon ? 1.0 - epsilon : o_i);
25 *r = (o_i - target[i]) / (c * o_i * (1.0 - o_i));
28const ae2f_float_t inp[4][2] = { 1, 1, 0, 0, 0, 1, 1, 0 };
29const ae2f_float_t goal_and[4] = {1, 0, 0, 0 };
30const ae2f_float_t goal_or[4] = {1, 0, 1, 1 };
32ae2f_float_t output[1] = {0, };
41#define DIFF_GOOD(a, b) (((a) - (b)) * ((a) - (b))) < THRESHOLD
44 puts(
"Trial: tryand");
53 , Act, ActDeriv, LossDeriv
58 printf(
"Learningrate dump: %f, %f\n", slp->m_learningrate, slp->m_learningrate_bias);
59 printf(
"function points: %p %p %p\n", slp->m_act, slp->m_actderiv, slp->m_lossderiv);
63 for(i = 0 ; i < 2 * 1 + 1; ++i) {
64 slp->m_weight[i] = 0.2;
68 for(i = 0; i < 1000; ++i) {
69 for(j = 0; j <
sizeof(inp) /
sizeof(inp[0]); ++j) {
70 slp->Train(&err, inp[j], &goal_and[j]);
75 for(j = 0; j <
sizeof(inp) /
sizeof(inp[0]); ++j) {
76 slp->Predict(&err, inp[j], output);
79 printf(
"Got %f\n", *output);
81 printf(
"Match. Expected %f\n.", goal_and[j]);
83 printf(
"Expected %f. Unexpected.\n", goal_and[j]);
94 else puts(
"slp is null");
95 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.