Experimental alternative neural network modeled after equation system instead of linear algebra and derivatives.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

109 行
2.6KB

  1. /*
  2. Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic
  3. Xeuron is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation.
  4. And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version.
  5. It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3.
  6. */
  7. #ifndef XEURON_SOURCE
  8. #define XEURON_SOURCE
  9. #include <xolatile/xeuron.h>
  10. int neuron_array = 0;
  11. int neuron_count = 0;
  12. int * neuron_input = NULL;
  13. int * neuron_output = NULL;
  14. int * neuron_system = NULL;
  15. static int neuron_system_expect (int element) {
  16. int i, j;
  17. int offset = 0;
  18. for (i = 0; i != 1 << neuron_array; ++i) {
  19. int square = 1;
  20. for (j = 0; j != neuron_array; ++j) {
  21. square *= ((i & (1 << j)) ? neuron_input [j * neuron_count + element] : 1);
  22. }
  23. offset += (neuron_system [i]) * square;
  24. }
  25. return (offset);
  26. }
  27. static int neuron_system_factor (int factor) {
  28. int i;
  29. int offset = 0;
  30. for (i = 0; i != neuron_count; ++i) {
  31. offset += (i + 1) * (neuron_output [i + factor] - neuron_system_expect (i));
  32. }
  33. return (offset);
  34. }
  35. void neuron_initialize (int array, int count, int * input_data, int * output_data) {
  36. neuron_array = array;
  37. neuron_count = count;
  38. neuron_input = allocate (neuron_array * neuron_count * (int) sizeof (* neuron_input));
  39. neuron_output = allocate ( neuron_count * (int) sizeof (* neuron_output));
  40. memory_copy (neuron_input, input_data, neuron_array * neuron_count * (int) sizeof (* neuron_input));
  41. memory_copy (neuron_output, output_data, neuron_count * (int) sizeof (* neuron_output));
  42. neuron_system = allocate ((1 << neuron_array) * (int) sizeof (* neuron_system));
  43. }
  44. void neuron_configure (void) { /* Unimplemented. */
  45. int i, j;
  46. for (j = 0; j != 3; ++j) {
  47. for (i = 0; i != 1 << neuron_array; ++i) {
  48. neuron_system [i] += j;
  49. }
  50. neuron_print ();
  51. for (i = 0; i != 1 << neuron_array; ++i) {
  52. neuron_system [i] -= 2 * j;
  53. }
  54. neuron_print ();
  55. for (i = 0; i != 1 << neuron_array; ++i) {
  56. neuron_system [i] += j;
  57. }
  58. }
  59. }
  60. void neuron_deinitialize (void) {
  61. neuron_input = deallocate (neuron_input);
  62. neuron_output = deallocate (neuron_output);
  63. neuron_system = deallocate (neuron_system);
  64. }
  65. void neuron_print (void) {
  66. int i;
  67. terminal_colour (COLOUR_BLUE, EFFECT_BOLD);
  68. echo (number_to_string (neuron_system_factor (0)));
  69. terminal_cancel ();
  70. echo (" [ ");
  71. for (i = 0; i != 1 << neuron_array; ++i) {
  72. echo (number_to_string (neuron_system [i]));
  73. echo (" ");
  74. }
  75. echo ("]\n");
  76. }
  77. #endif