From bfdd84122c6d16501698ed6a2cb44ed3388f8a87 Mon Sep 17 00:00:00 2001 From: Lewis Van Winkle Date: Wed, 5 Aug 2026 07:23:03 -0500 Subject: [PATCH] Remove the genann_act compile-time activation override --- genann.c | 27 +++++---------------------- test.c | 4 ---- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/genann.c b/genann.c index b7cc3a6..8233fd7 100644 --- a/genann.c +++ b/genann.c @@ -33,27 +33,11 @@ #include #include -#ifndef genann_act -#define genann_act_hidden genann_act_hidden_indirect -#define genann_act_output genann_act_output_indirect -#else -#define genann_act_hidden genann_act -#define genann_act_output genann_act -#endif - #define LOOKUP_SIZE 4096 /* Bounds the size calculations in genann_init so they cannot overflow. */ #define GENANN_MAX_DIMENSION (1 << 20) -double genann_act_hidden_indirect(const struct genann *ann, double a) { - return ann->activation_hidden(ann, a); -} - -double genann_act_output_indirect(const struct genann *ann, double a) { - return ann->activation_output(ann, a); -} - const double sigmoid_dom_min = -15.0; const double sigmoid_dom_max = 15.0; double interval; @@ -244,7 +228,7 @@ double const *genann_run(genann const *ann, double const *inputs) { for (k = 0; k < ann->inputs; ++k) { sum += *w++ * i[k]; } - *o++ = genann_act_output(ann, sum); + *o++ = ann->activation_output(ann, sum); } return ret; @@ -256,7 +240,7 @@ double const *genann_run(genann const *ann, double const *inputs) { for (k = 0; k < ann->inputs; ++k) { sum += *w++ * i[k]; } - *o++ = genann_act_hidden(ann, sum); + *o++ = ann->activation_hidden(ann, sum); } i += ann->inputs; @@ -268,7 +252,7 @@ double const *genann_run(genann const *ann, double const *inputs) { for (k = 0; k < ann->hidden; ++k) { sum += *w++ * i[k]; } - *o++ = genann_act_hidden(ann, sum); + *o++ = ann->activation_hidden(ann, sum); } i += ann->hidden; @@ -282,7 +266,7 @@ double const *genann_run(genann const *ann, double const *inputs) { for (k = 0; k < ann->hidden; ++k) { sum += *w++ * i[k]; } - *o++ = genann_act_output(ann, sum); + *o++ = ann->activation_output(ann, sum); } /* Sanity check that we used all weights and wrote all outputs. */ @@ -318,8 +302,7 @@ void genann_train(genann const *ann, double const *inputs, double const *desired /* Set output layer deltas. */ - if (genann_act_output == genann_act_linear || - ann->activation_output == genann_act_linear) { + if (ann->activation_output == genann_act_linear) { for (j = 0; j < ann->outputs; ++j) { *d++ = *t++ - *o++; } diff --git a/test.c b/test.c index 619030c..b633089 100644 --- a/test.c +++ b/test.c @@ -193,7 +193,6 @@ void train_xor() { -#ifndef genann_act void train_xor_act(genann_actfun act) { double input[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}}; double output[4] = {0, 1, 1, 0}; @@ -292,7 +291,6 @@ void gradient_tanh() { void gradient_relu() { gradient_act(genann_act_relu, genann_act_sigmoid); } -#endif void persist() { @@ -368,12 +366,10 @@ int main(int argc, char *argv[]) lrun("train and", train_and); lrun("train or", train_or); lrun("train xor", train_xor); -#ifndef genann_act lrun("train tanh", train_xor_tanh); lrun("train relu", train_xor_relu); lrun("gradient tanh", gradient_tanh); lrun("gradient relu", gradient_relu); -#endif lrun("persist", persist); lrun("copy", copy); lrun("sigmoid", sigmoid);