Updating/Adding functions
This commit is contained in:
parent
ce66110173
commit
048e1cee61
9 changed files with 69 additions and 4 deletions
7
Makefile
7
Makefile
|
|
@ -1 +1,6 @@
|
|||
default : executable
|
||||
send :
|
||||
git add .
|
||||
git commit
|
||||
git push
|
||||
|
||||
|
||||
|
|
|
|||
BIN
exe
Uitvoerbaar bestand
BIN
exe
Uitvoerbaar bestand
Binary file not shown.
8
main.c
8
main.c
|
|
@ -1,11 +1,19 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "randomness.h"
|
||||
#include "neurons.h"
|
||||
#include "network.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
init_randomness();
|
||||
|
||||
printf("Bonjour et bienvenu ;)\n");
|
||||
int i;
|
||||
for(i=1 ; i<= 30 ; i++)
|
||||
{
|
||||
printf("%dth generated fload = %f\n", i, random_float(0.0 , 1.0));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,10 +1,19 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "randomness.h"
|
||||
#include "neurons.h"
|
||||
#include "network.h"
|
||||
|
||||
Neuron *generate_layer(int n_neurons, int n_neurons_prev_layer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Network *init_network(int n_neurons_per_layer[])
|
||||
{
|
||||
/* initialize the network based on array n_neurons_per_layer :
|
||||
- size of n_neurons_per_layer is the number of layers
|
||||
- each ith number in array n_neurons_per_layer is the number of neurons in ith layer
|
||||
*/
|
||||
}
|
||||
|
|
@ -9,5 +9,7 @@ struct network
|
|||
int number_layers; //keeps track of layers' number
|
||||
};
|
||||
|
||||
Neuron *generate_layer(int n_neurons, int n_neurons_prev_layer);
|
||||
Network *init_network(int n_neurons_per_layer[]);
|
||||
|
||||
#endif
|
||||
22
neurons.c
22
neurons.c
|
|
@ -1,19 +1,37 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "randomness.h"
|
||||
#include "neurons.h"
|
||||
|
||||
Neuron *init_neuron(int n_weights)
|
||||
{
|
||||
Neuron *neuron = (Neuron*)malloc(sizeof(Neuron));
|
||||
neuron->weights = (float*)malloc(n_weights*sizeof(float));
|
||||
if(n_weights == 0)
|
||||
{
|
||||
neuron->weights = NULL;
|
||||
}else
|
||||
{
|
||||
neuron->weights = (float*)malloc(n_weights*sizeof(float));
|
||||
int i;
|
||||
for(i=1 ; i<=n_weights ; i++)
|
||||
{
|
||||
neuron->weights[i] = random_float(0.0 , 1.0);
|
||||
}
|
||||
}
|
||||
neuron->bias = random_float(0.0 , 1.0);
|
||||
neuron->output = 0.0;
|
||||
neuron->delta_error = 0.0;
|
||||
neuron->same_layer_next_neuron = NULL;
|
||||
|
||||
return neuron;
|
||||
}
|
||||
|
||||
void destroy_neuron(Neuron *neuron)
|
||||
{
|
||||
free(neuron->weights);
|
||||
if(neuron->weights != NULL)
|
||||
{
|
||||
free(neuron->weights);
|
||||
}
|
||||
free(neuron);
|
||||
}
|
||||
|
|
@ -4,7 +4,8 @@
|
|||
typedef struct neuron Neuron;
|
||||
struct neuron
|
||||
{
|
||||
float *weights; //weights associated to the neuron + neuron's bias
|
||||
float *weights; //weights associated to the neuron
|
||||
float bias; //neuron's bias
|
||||
float output; //output of the neuron
|
||||
float delta_error; //the delta error for updating current weights
|
||||
Neuron *same_layer_next_neuron;
|
||||
|
|
|
|||
15
randomness.c
Normaal bestaand
15
randomness.c
Normaal bestaand
|
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include "randomness.h"
|
||||
|
||||
void init_randomness(void) //to be called only one time in main function
|
||||
{
|
||||
srand(time(NULL));
|
||||
}
|
||||
|
||||
float random_float(float min, float max)
|
||||
{
|
||||
//generate a random float number in [min ; max] inclusive
|
||||
return min + ((float)rand()/(float)RAND_MAX) * (max-min);
|
||||
}
|
||||
7
randomness.h
Normaal bestaand
7
randomness.h
Normaal bestaand
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef RANDOMNESS_H
|
||||
#define RANDOMNESS_H
|
||||
|
||||
void init_randomness(void);
|
||||
float random_float(float min, float max);
|
||||
|
||||
#endif
|
||||
Laden…
Reference in a new issue