|
|
@@ -0,0 +1,140 @@ |
|
|
|
/* |
|
|
|
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>*/ |
|
|
|
#include "xeuron.h" |
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
int neuron_array = 0; |
|
|
|
int neuron_count = 0; |
|
|
|
int * neuron_input = NULL; |
|
|
|
int * neuron_output = NULL; |
|
|
|
int * neuron_system = NULL; |
|
|
|
/* |
|
|
|
square : right up |
|
|
|
bd abd bcd abcd |
|
|
|
d ad cd acd |
|
|
|
b ab bc abc |
|
|
|
1 a c ac |
|
|
|
*/ |
|
|
|
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) { |
|
|
|
int i, j; |
|
|
|
//~int i; |
|
|
|
|
|
|
|
for (j = 0; j != 3; ++j) { |
|
|
|
int offset; |
|
|
|
|
|
|
|
for (i = 0; i != 1 << neuron_array; ++i) { |
|
|
|
neuron_system [i] += j; |
|
|
|
} |
|
|
|
offset = neuron_system_factor (i); |
|
|
|
neuron_print (); |
|
|
|
|
|
|
|
for (i = 0; i != 1 << neuron_array; ++i) { |
|
|
|
neuron_system [i] -= 2 * j; |
|
|
|
} |
|
|
|
offset = neuron_system_factor (i); |
|
|
|
neuron_print (); |
|
|
|
|
|
|
|
for (i = 0; i != 1 << neuron_array; ++i) { |
|
|
|
neuron_system [i] += j; |
|
|
|
} |
|
|
|
|
|
|
|
echo ("-------------------------------------------------------------------\n"); |
|
|
|
} |
|
|
|
|
|
|
|
//~for (i = 0; i != 1 << neuron_array; ++i) { |
|
|
|
//~int offset, offset_upper, offset_lower; |
|
|
|
|
|
|
|
//~offset = neuron_system_factor (i); |
|
|
|
//~neuron_print (); |
|
|
|
|
|
|
|
//~neuron_system [i] += 1; |
|
|
|
//~offset_upper = neuron_system_factor (i); |
|
|
|
//~neuron_print (); |
|
|
|
|
|
|
|
//~neuron_system [i] -= 2; |
|
|
|
//~offset_lower = neuron_system_factor (i); |
|
|
|
//~neuron_print (); |
|
|
|
|
|
|
|
//~neuron_system [i] += 1; |
|
|
|
|
|
|
|
//~echo ("-------------------------------------------------------------------\n"); |
|
|
|
//~} |
|
|
|
} |
|
|
|
|
|
|
|
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 |