cbasedann/neurons.c

37 lines
No EOL
776 B
C

#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));
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)
{
if(neuron->weights != NULL)
{
free(neuron->weights);
}
free(neuron);
}