47 lines
No EOL
1.1 KiB
C
47 lines
No EOL
1.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "randomness.h"
|
|
#include "neurons.h"
|
|
#include "activations.h"
|
|
|
|
Neuron *init_neuron(int n_weights, char *activation_function)
|
|
{
|
|
Neuron *neuron = (Neuron*)malloc(sizeof(Neuron));
|
|
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;
|
|
if(strcmp(activation_function, "nothing") == 0)
|
|
{
|
|
//to be completed later with tanh, relu, etc : for now only sigmoid is supported and will be the default function
|
|
}
|
|
else
|
|
{
|
|
neuron->activation = sigmoid;
|
|
neuron->activation_derivative = sigmoid_derivative;
|
|
}
|
|
neuron->delta_error = 0.0;
|
|
neuron->same_layer_next_neuron = NULL;
|
|
|
|
return neuron;
|
|
}
|
|
|
|
void destroy_neuron(Neuron *neuron)
|
|
{
|
|
if(neuron->weights != NULL)
|
|
{
|
|
free(neuron->weights);
|
|
}
|
|
free(neuron);
|
|
} |