Improve neural randomization

Start implementing neural training algorithm.
This commit is contained in:
Marcel Plch 2024-10-26 09:55:43 +02:00
parent fa0d6291fe
commit 04bf753f09
Signed by: dormouse
GPG key ID: 2CA77596BC4BDFFE
2 changed files with 24 additions and 2 deletions

View file

@ -8,6 +8,7 @@
#include <math.h> #include <math.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <stdint.h>
// Include GLEW // Include GLEW
#include <GL/glew.h> #include <GL/glew.h>

View file

@ -54,13 +54,20 @@ void
neural_randomize(Neural_Network *self) { neural_randomize(Neural_Network *self) {
FILE *f; FILE *f;
Neural_Layer *nl; Neural_Layer *nl;
uint64_t *rand_vals;
f = fopen("/dev/urandom", "r"); f = fopen("/dev/urandom", "r");
for (int i = 0; i < self->layer_count; i++) { for (int i = 0; i < self->layer_count; i++) {
nl = self->layers[i]; nl = self->layers[i];
rand_vals = malloc(nl->layer_size_next * sizeof(uint64_t));
fread(rand_vals, sizeof(uint64_t),
nl->layer_size_next, f);
for (int j = 0; j < nl->layer_size; j++) { for (int j = 0; j < nl->layer_size; j++) {
fread(nl->neurons[j].synapses, sizeof(float), nl->layer_size_next, f); for (int k = 0; k < nl->layer_size_next; k++) {
nl->neurons[j].synapses[k] = UINT64_MAX / rand_vals[k]
}
} }
} }
} }
@ -137,11 +144,25 @@ neural_process(Neural_Network *self, float *input) {
return retval; return retval;
} }
// These two will be merged into one once I have
// enough patience to create more dynamic objects.
static void *
neural_backprop_up(Neural_Network *self, size_t neuron, size_t layer) {
return NULL;
}
static void *
neural_backprop_down(Neural_Network *self, size_t neuron, size_t layer) {
return NULL;
}
int int
neural_train(Neural_Network *self, neural_train(Neural_Network *self,
const char *testdata, const char *testdata,
const float *testresult) { const float *testresult) {
// Insert algorithm you lazy fuck. float *testdata_converted;
testdata_converted = malloc(self->layers[self->layer_count-1]->layer_size * sizeof(float));
return 0; return 0;
} }