ref: e20feacc2e81c47958683946d2ed81c669559047
parent: da2988746c54f8d0559c4d1ff3ed027bf849fd0e
author: eli <eli@singularity>
date: Sat Dec 28 02:50:51 EST 2024
back to sigmoid output
--- a/ann.c
+++ b/ann.c
@@ -125,17 +125,19 @@
double
activation_piece(Neuron *in)
{
- if (in->sum < 0.0)
+ if (in->sum < -0.5)
return 0.0;
- else if (in->sum > 1.0)
+ else if (in->sum > 0.5)
return 1.0;
- return in->sum;
+ return (in->sum + 0.5);
}
double
-gradient_piece(Neuron*)
+gradient_piece(Neuron *in)
{
- return 1.0;
+ if (in->sum > -0.5 && in->sum < 0.5)
+ return 1.0;
+ return 0.01;
}
Weights*
@@ -281,7 +283,7 @@
if (i < (num_layers-1))
ret->layers[i] = layercreate(arg, ACTIVATION, GRADIENT);
else
- ret->layers[i] = layercreate(arg, activation_piece, gradient_piece);
+ ret->layers[i] = layercreate(arg, activation_sigmoid, gradient_sigmoid);
if (i > 0) {
ret->weights[i-1] = weightscreate(ret->layers[i-1]->n, ret->layers[i]->n, 1);
ret->deltas[i-1] = weightscreate(ret->layers[i-1]->n, ret->layers[i]->n, 0);
@@ -847,11 +849,11 @@
if (trainline == 0) {
runoutput = annrun(ann, input);
for (i = 0; i < noutput; i++)
- if (runoutput[i] == 0.0)
+/* if (runoutput[i] == 0.0)
print("0%c", (i == (noutput-1))? '\n': ' ');
else if (runoutput[i] == 1.0)
print("1%c", (i == (noutput-1))? '\n': ' ');
- else
+ else */
print("%f%c", runoutput[i], (i == (noutput-1))? '\n': ' ');
free(runoutput);
}