jacobian

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 5a1e4177e6292021e578b43e862f81782c89fe11
parent 7d08eb02d8394b83a83313721ff9295e30b6863c
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Sun,  7 Jun 2020 15:57:34 -0700

Basic neural net initialization

Diffstat:
Mbpnn.c | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 56 insertions(+), 6 deletions(-)

diff --git a/bpnn.c b/bpnn.c @@ -1,9 +1,12 @@ #include <stdio.h> +#include <math.h> #include "../mapreduce/mapreduce.h" #include "../mapreduce/server.h" #include "../mapreduce/worker.h" +#define BUFSIZE 2048 + struct node; struct edge { @@ -28,20 +31,67 @@ struct network { int length; }; -float activate (float value) { - +float activate (double value) { + // Sigmoid + value = 1/(1+pow(M_E, -value)); } struct network initialize (char* path, int inputs, int neurons, int layers, int outputs) { - struct layer input; - for (int i = 0; i < 4; i++) { - input.nodes[i].activation = 0; // Needs some sort of scaling + // Read from CSV + FILE* fptr = fopen(path, "r"); + double data[inputs]; + fscanf(fptr, "%d,%d,%d,%d,*d", &data[0], &data[1], &data[2], &data[3]); + + // Initialize network + struct network net; + net.layers = malloc((layers + 2) * sizeof(struct layer)); + + // Initialize input nodes + for (int i = 0; i < inputs; i++) { + net.layers[0].nodes[i].activation = activate(data[i]); + } + + // Init hidden layer nodes and output nodes to 0 (will be replaced by feedforward) + for (int i = 1; i < layers; i++) { + for (int j = 0; j < neurons; j++) { + net.layers[i].nodes[j].activation = 0; + } + } + for (int i = 0; i < outputs; i++) { + net.layers[layers-1].nodes[i].activation = 0; + } + + // Init edges between layers with random numbers TODO make a function to initialize edges between two layers for the love of God + for (int i = 0; i < inputs; i++) { + for (int j = 0; j < neurons; j++) { + struct edge connection = {&net.layers[0].nodes[i], &net.layers[1].nodes[j], rand()}; + net.layers[0].nodes[i].outgoing[j] = connection; + net.layers[1].nodes[j].incoming[i] = connection; + } + } + for (int i = 0; i < layers-1; i++) { + for (int j = 0; j < neurons; j++) { + for (int k = 0; k < neurons; k++) { + struct edge connection = {&net.layers[i].nodes[j], &net.layers[i+1].nodes[k], rand()}; + net.layers[i].nodes[j].outgoing[k] = connection; + net.layers[i+1].nodes[k].incoming[j] = connection; + } + } + } + for (int i = 0; i < neurons; i++) { + for (int j = 0; j < outputs; j++) { + struct edge connection = {&net.layers[0].nodes[i], &net.layers[1].nodes[j], rand()}; + net.layers[0].nodes[i].outgoing[j] = connection; + net.layers[1].nodes[j].incoming[i] = connection; + } } + // Epic, everything's initialized TODO add biases! + return net; } struct int_pair* map (struct str_pair file) { - + initialize("./data_banknote_authentication.txt", 4, 5, 2, 2); } struct int_pair* reduce (struct int_pair* input)