mirror of
https://github.com/codeplea/genann
synced 2024-11-24 23:40:02 +03:00
Merge pull request #5 from Dickby/master
simplify most inner loops of genann_run
This commit is contained in:
commit
88c9d3513b
20
genann.c
20
genann.c
@ -184,13 +184,9 @@ double const *genann_run(genann const *ann, double const *inputs) {
|
|||||||
/* Figure hidden layers, if any. */
|
/* Figure hidden layers, if any. */
|
||||||
for (h = 0; h < ann->hidden_layers; ++h) {
|
for (h = 0; h < ann->hidden_layers; ++h) {
|
||||||
for (j = 0; j < ann->hidden; ++j) {
|
for (j = 0; j < ann->hidden; ++j) {
|
||||||
double sum = 0;
|
double sum = *w++ * -1.0;
|
||||||
for (k = 0; k < (h == 0 ? ann->inputs : ann->hidden) + 1; ++k) {
|
for (k = 0; k < (h == 0 ? ann->inputs : ann->hidden); ++k) {
|
||||||
if (k == 0) {
|
sum += *w++ * i[k];
|
||||||
sum += *w++ * -1.0;
|
|
||||||
} else {
|
|
||||||
sum += *w++ * i[k-1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*o++ = act(sum);
|
*o++ = act(sum);
|
||||||
}
|
}
|
||||||
@ -203,13 +199,9 @@ double const *genann_run(genann const *ann, double const *inputs) {
|
|||||||
|
|
||||||
/* Figure output layer. */
|
/* Figure output layer. */
|
||||||
for (j = 0; j < ann->outputs; ++j) {
|
for (j = 0; j < ann->outputs; ++j) {
|
||||||
double sum = 0;
|
double sum = *w++ * -1.0;
|
||||||
for (k = 0; k < (ann->hidden_layers ? ann->hidden : ann->inputs) + 1; ++k) {
|
for (k = 0; k < (ann->hidden_layers ? ann->hidden : ann->inputs); ++k) {
|
||||||
if (k == 0) {
|
sum += *w++ * i[k];
|
||||||
sum += *w++ * -1.0;
|
|
||||||
} else {
|
|
||||||
sum += *w++ * i[k-1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*o++ = acto(sum);
|
*o++ = acto(sum);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user