From d8ccd42fd848c18ae67ca9aadaebaa876581ccdf Mon Sep 17 00:00:00 2001 From: xolatile Date: Sat, 28 Oct 2023 13:42:49 -0400 Subject: [PATCH] Adding files... --- compile.sh | 9 ++++ main.c | 30 +++++++++++++ xeuron.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xeuron.h | 26 ++++++++++++ 4 files changed, 205 insertions(+) create mode 100644 compile.sh create mode 100644 main.c create mode 100644 xeuron.c create mode 100644 xeuron.h diff --git a/compile.sh b/compile.sh new file mode 100644 index 0000000..0d9653e --- /dev/null +++ b/compile.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -xe + +clang -g -ansi -Weverything -Ofast -o main main.c + +valgrind ./main + +exit diff --git a/main.c b/main.c new file mode 100644 index 0000000..0eecc94 --- /dev/null +++ b/main.c @@ -0,0 +1,30 @@ +#include "xeuron.c" + +int main (void) { + //~int input [] = { 0, 0, 1, 1, 0, 1, 0, 1 }, output [] = { 0, 0, 0, 1 }; /* AND */ + //~int input [] = { 0, 0, 1, 1, 0, 1, 0, 1 }, output [] = { 0, 1, 1, 1 }; /* OR */ + int input [] = { 0, 0, 1, 1, 0, 1, 0, 1 }, output [] = { 0, 1, 1, 0 }; /* XOR */ + + neuron_initialize (2, 4, input, output); + + neuron_configure (); + + //~neuron_system [0] = 0; /* AND */ + //~neuron_system [1] = 0; + //~neuron_system [2] = 0; + //~neuron_system [3] = 1; + //~neuron_system [0] = 0; /* OR */ + //~neuron_system [1] = 1; + //~neuron_system [2] = 1; + //~neuron_system [3] = -1; + neuron_system [0] = 0; /* XOR */ + neuron_system [1] = 1; + neuron_system [2] = 1; + neuron_system [3] = -2; + + neuron_print (); + + neuron_deinitialize (); + + return (EXIT_SUCCESS); +} diff --git a/xeuron.c b/xeuron.c new file mode 100644 index 0000000..15eaeb0 --- /dev/null +++ b/xeuron.c @@ -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 */ +#include "xeuron.h" +#include + +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 diff --git a/xeuron.h b/xeuron.h new file mode 100644 index 0000000..d78cefe --- /dev/null +++ b/xeuron.h @@ -0,0 +1,26 @@ +/* +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_HEADER +#define XEURON_HEADER + +#include + +extern int neuron_array; +extern int neuron_count; +extern int * neuron_input; +extern int * neuron_output; +extern int * neuron_system; + +extern void neuron_initialize (int array, int count, int * input_data, int * output_data); +extern void neuron_configure (void); +extern void neuron_deinitialize (void); + +extern void neuron_print (void); + +#endif