Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add function to randomly tweak the weights #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions genann.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
3 changes: 3 additions & 0 deletions genann.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down