Quellcode durchsuchen

Adding files...

master
Ognjen Milan Robovic vor 7 Monaten
Ursprung
Commit
d8ccd42fd8
4 geänderte Dateien mit 205 neuen und 0 gelöschten Zeilen
  1. +9
    -0
      compile.sh
  2. +30
    -0
      main.c
  3. +140
    -0
      xeuron.c
  4. +26
    -0
      xeuron.h

+ 9
- 0
compile.sh Datei anzeigen

@@ -0,0 +1,9 @@
#!/bin/bash

set -xe

clang -g -ansi -Weverything -Ofast -o main main.c

valgrind ./main

exit

+ 30
- 0
main.c Datei anzeigen

@@ -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);
}

+ 140
- 0
xeuron.c Datei anzeigen

@@ -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

+ 26
- 0
xeuron.h Datei anzeigen

@@ -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 <xolatile/xtandard.c>

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

Laden…
Abbrechen
Speichern