add function to randomly tweak the weights

This commit is contained in:
AJGQ 2021-05-30 14:57:40 +01:00
parent 4f72209510
commit 9b187604fc
2 changed files with 12 additions and 0 deletions

View File

@ -201,6 +201,15 @@ void genann_randomize(genann *ann) {
}
}
void genann_random_tweak(genann *ann, double max) {
int i;
for (i = 0; i < ann->total_weights; ++i) {
/* -max <= r <= max */
double r = (GENANN_RANDOM() - 0.5) * 2 * max;
ann->weight[i] += r;
}
}
void genann_free(genann *ann) {
/* The weight, output, and delta pointers go to the same buffer. */

View File

@ -79,6 +79,9 @@ genann *genann_read(FILE *in);
/* Sets weights randomly. Called by init. */
void genann_randomize(genann *ann);
/* Modifies the weights randomly, with max as a threshold */
void genann_random_tweak(genann *ann, double max);
/* Returns a new copy of ann. */
genann *genann_copy(genann const *ann);