Experimental alternative neural network modeled after equation system instead of linear algebra and derivatives.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

141 rinda
3.4KB

  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. #include "xeuron.h"
  11. #include <stdio.h>
  12. int neuron_array = 0;
  13. int neuron_count = 0;
  14. int * neuron_input = NULL;
  15. int * neuron_output = NULL;
  16. int * neuron_system = NULL;
  17. /*
  18. square : right up
  19. bd abd bcd abcd
  20. d ad cd acd
  21. b ab bc abc
  22. 1 a c ac
  23. */
  24. static int neuron_system_expect (int element) {
  25. int i, j;
  26. int offset = 0;
  27. for (i = 0; i != 1 << neuron_array; ++i) {
  28. int square = 1;
  29. for (j = 0; j != neuron_array; ++j) {
  30. square *= ((i & (1 << j)) ? neuron_input [j * neuron_count + element] : 1);
  31. }
  32. offset += (neuron_system [i]) * square;
  33. }
  34. return (offset);
  35. }
  36. static int neuron_system_factor (int factor) {
  37. int i;
  38. int offset = 0;
  39. for (i = 0; i != neuron_count; ++i) {
  40. offset += (i + 1) * (neuron_output [i + factor] - neuron_system_expect (i));
  41. }
  42. return (offset);
  43. }
  44. void neuron_initialize (int array, int count, int * input_data, int * output_data) {
  45. neuron_array = array;
  46. neuron_count = count;
  47. neuron_input = allocate (neuron_array * neuron_count * (int) sizeof (* neuron_input));
  48. neuron_output = allocate ( neuron_count * (int) sizeof (* neuron_output));
  49. memory_copy (neuron_input, input_data, neuron_array * neuron_count * (int) sizeof (* neuron_input));
  50. memory_copy (neuron_output, output_data, neuron_count * (int) sizeof (* neuron_output));
  51. neuron_system = allocate ((1 << neuron_array) * (int) sizeof (* neuron_system));
  52. }
  53. void neuron_configure (void) {
  54. int i, j;
  55. //~int i;
  56. for (j = 0; j != 3; ++j) {
  57. int offset;
  58. for (i = 0; i != 1 << neuron_array; ++i) {
  59. neuron_system [i] += j;
  60. }
  61. offset = neuron_system_factor (i);
  62. neuron_print ();
  63. for (i = 0; i != 1 << neuron_array; ++i) {
  64. neuron_system [i] -= 2 * j;
  65. }
  66. offset = neuron_system_factor (i);
  67. neuron_print ();
  68. for (i = 0; i != 1 << neuron_array; ++i) {
  69. neuron_system [i] += j;
  70. }
  71. echo ("-------------------------------------------------------------------\n");
  72. }
  73. //~for (i = 0; i != 1 << neuron_array; ++i) {
  74. //~int offset, offset_upper, offset_lower;
  75. //~offset = neuron_system_factor (i);
  76. //~neuron_print ();
  77. //~neuron_system [i] += 1;
  78. //~offset_upper = neuron_system_factor (i);
  79. //~neuron_print ();
  80. //~neuron_system [i] -= 2;
  81. //~offset_lower = neuron_system_factor (i);
  82. //~neuron_print ();
  83. //~neuron_system [i] += 1;
  84. //~echo ("-------------------------------------------------------------------\n");
  85. //~}
  86. }
  87. void neuron_deinitialize (void) {
  88. neuron_input = deallocate (neuron_input);
  89. neuron_output = deallocate (neuron_output);
  90. neuron_system = deallocate (neuron_system);
  91. }
  92. void neuron_print (void) {
  93. int i;
  94. terminal_colour (COLOUR_BLUE, EFFECT_BOLD);
  95. echo (number_to_string (neuron_system_factor (0)));
  96. terminal_cancel ();
  97. echo (" [ ");
  98. for (i = 0; i != 1 << neuron_array; ++i) {
  99. echo (number_to_string (neuron_system [i]));
  100. echo (" ");
  101. }
  102. echo ("]\n");
  103. }
  104. #endif