mirror of
https://github.com/codeplea/genann
synced 2024-11-21 22:11:34 +03:00
add function to randomly tweak the weights
This commit is contained in:
parent
4f72209510
commit
9b187604fc
9
genann.c
9
genann.c
@ -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. */
|
||||
|
3
genann.h
3
genann.h
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user