|
- /*
- Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic
-
- Xeuron is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation.
- 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.
- 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.
- */
-
- #ifndef XEURON_SOURCE
- #define XEURON_SOURCE
-
- #include <xolatile/xeuron.h>
-
- int neuron_array = 0;
- int neuron_count = 0;
- int * neuron_input = NULL;
- int * neuron_output = NULL;
- int * neuron_system = NULL;
-
- static int neuron_system_expect (int element) {
- int i, j;
-
- int offset = 0;
-
- for (i = 0; i != 1 << neuron_array; ++i) {
- int square = 1;
-
- for (j = 0; j != neuron_array; ++j) {
- square *= ((i & (1 << j)) ? neuron_input [j * neuron_count + element] : 1);
- }
-
- offset += (neuron_system [i]) * square;
- }
-
- return (offset);
- }
-
- static int neuron_system_factor (int factor) {
- int i;
-
- int offset = 0;
-
- for (i = 0; i != neuron_count; ++i) {
- offset += (i + 1) * (neuron_output [i + factor] - neuron_system_expect (i));
- }
-
- return (offset);
- }
-
- void neuron_initialize (int array, int count, int * input_data, int * output_data) {
- neuron_array = array;
- neuron_count = count;
-
- neuron_input = allocate (neuron_array * neuron_count * (int) sizeof (* neuron_input));
- neuron_output = allocate ( neuron_count * (int) sizeof (* neuron_output));
-
- memory_copy (neuron_input, input_data, neuron_array * neuron_count * (int) sizeof (* neuron_input));
- memory_copy (neuron_output, output_data, neuron_count * (int) sizeof (* neuron_output));
-
- neuron_system = allocate ((1 << neuron_array) * (int) sizeof (* neuron_system));
- }
-
- void neuron_configure (void) { /* Unimplemented. */
- int i, j;
-
- for (j = 0; j != 3; ++j) {
- for (i = 0; i != 1 << neuron_array; ++i) {
- neuron_system [i] += j;
- }
-
- neuron_print ();
-
- for (i = 0; i != 1 << neuron_array; ++i) {
- neuron_system [i] -= 2 * j;
- }
-
- neuron_print ();
-
- for (i = 0; i != 1 << neuron_array; ++i) {
- neuron_system [i] += j;
- }
- }
- }
-
- void neuron_deinitialize (void) {
- neuron_input = deallocate (neuron_input);
- neuron_output = deallocate (neuron_output);
- neuron_system = deallocate (neuron_system);
- }
-
- void neuron_print (void) {
- int i;
-
- terminal_colour (COLOUR_BLUE, EFFECT_BOLD);
- echo (number_to_string (neuron_system_factor (0)));
- terminal_cancel ();
-
- echo (" [ ");
-
- for (i = 0; i != 1 << neuron_array; ++i) {
- echo (number_to_string (neuron_system [i]));
- echo (" ");
- }
-
- echo ("]\n");
- }
-
- #endif
|