Skip to content

Commit

Permalink
added srand to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
codeplea committed Sep 5, 2018
1 parent 30da4eb commit 23f2a94
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions example1.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "genann.h"

int main(int argc, char *argv[])
{
printf("GENANN example 1.\n");
printf("Train a small ANN to the XOR function using backpropagation.\n");

/* This will make the neural network initialize differently each run. */
/* If you don't get a good result, try again for a different result. */
srand(time(0));

/* Input and expected out data for the XOR function. */
const double input[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
const double output[4] = {0, 1, 1, 0};
Expand Down
4 changes: 4 additions & 0 deletions example2.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "genann.h"

Expand All @@ -8,6 +9,8 @@ int main(int argc, char *argv[])
printf("GENANN example 2.\n");
printf("Train a small ANN to the XOR function using random search.\n");

srand(time(0));

/* Input and expected out data for the XOR function. */
const double input[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
const double output[4] = {0, 1, 1, 0};
Expand All @@ -27,6 +30,7 @@ int main(int argc, char *argv[])
if (count % 1000 == 0) {
/* We're stuck, start over. */
genann_randomize(ann);
last_err = 1000;
}

genann *save = genann_copy(ann);
Expand Down
3 changes: 3 additions & 0 deletions example4.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>
#include "genann.h"
Expand Down Expand Up @@ -74,6 +75,8 @@ int main(int argc, char *argv[])
printf("GENANN example 4.\n");
printf("Train an ANN on the IRIS dataset using backpropagation.\n");

srand(time(0));

/* Load the data from file. */
load_data();

Expand Down
2 changes: 1 addition & 1 deletion test.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ int main(int argc, char *argv[])
{
printf("GENANN TEST SUITE\n");

srand(100);
srand(100); //Repeatable test results.

lrun("basic", basic);
lrun("xor", xor);
Expand Down

0 comments on commit 23f2a94

Please sign in to comment.