You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example3.c 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "genann.h"
  4. const char *save_name = "example/xor.ann";
  5. int main(int argc, char *argv[])
  6. {
  7. printf("GENANN example 3.\n");
  8. printf("Load a saved ANN to solve the XOR function.\n");
  9. FILE *saved = fopen(save_name, "r");
  10. if (!saved) {
  11. printf("Couldn't open file: %s\n", save_name);
  12. exit(1);
  13. }
  14. genann *ann = genann_read(saved);
  15. fclose(saved);
  16. if (!ann) {
  17. printf("Error loading ANN from file: %s.", save_name);
  18. exit(1);
  19. }
  20. /* Input data for the XOR function. */
  21. const double input[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
  22. /* Run the network and see what it predicts. */
  23. printf("Output for [%1.f, %1.f] is %1.f.\n", input[0][0], input[0][1], *genann_run(ann, input[0]));
  24. printf("Output for [%1.f, %1.f] is %1.f.\n", input[1][0], input[1][1], *genann_run(ann, input[1]));
  25. printf("Output for [%1.f, %1.f] is %1.f.\n", input[2][0], input[2][1], *genann_run(ann, input[2]));
  26. printf("Output for [%1.f, %1.f] is %1.f.\n", input[3][0], input[3][1], *genann_run(ann, input[3]));
  27. genann_free(ann);
  28. return 0;
  29. }