/* Initialize the neural network with all neurons */
NN *nn_create(unsigned int layers, unsigned int *neurons) {
    ASSERT(layers > 0);
    ASSERT(neurons);

    // allocate memory
    NN *network = (NN *)malloc(sizeof(NN));
    if (network == NULL) {
        return NULL;
    }

    network->layers = (Neuron **)malloc(sizeof(Neuron *) * layers);
    for (unsigned int layer = 0; layer < layers; layer++) {
        network->layers[layer] = (Neuron *)malloc(sizeof(Neuron) * neurons[layer]);
        for (unsigned int neuron = 0; neuron < neurons[layer]; neuron++) {
            neuron_init(&network->layers[layer][neuron]);
        }
    }

    network->layer_count = layers;
    network->synapses = NULL;
    network->synapse_count = 0;
    network->neuron_count = (unsigned int *)malloc(sizeof(unsigned int) * layers);
    memcpy(network->neuron_count, neurons, sizeof(unsigned int) * layers);

    return network;
}
neuron_layer_t *neuron_layer_init(neuron_layer_type_t type, uint32_t num_neurons, uint32_t num_inputs) {
	neuron_layer_t *self = malloc(sizeof(neuron_layer_t));

	if(type == NEURON_LAYER_TYPE_INPUT)
		num_inputs = 1;

	self->type = type;
	self->num_neurons = num_neurons;
	self->neurons = malloc(sizeof(neuron_t *) * num_neurons);
	for(uint32_t i = 0; i < num_neurons; ++i)
		self->neurons[i] = neuron_init(num_inputs);

	return self;
}
Example #3
0
//TODO: change this fn's name to something like calc_sphere_neuron_distribution
void calc_neuron_distribution(Neuron * neurons, int length) {

    // Electrostatic repulsion Force
    Point fer_i, distance;
    int i, j, iter;

    for( i = 0; i < length; i++) {
        // Initialice neuron i with random weigths
        neuron_init(  &(neurons[i]), MAX_SYNAPSIS_NUMBER );
    };


    //Calculate the neuron distribution
    for(iter = 0; iter < MAX_ITERATION_NUMBER; iter++){
        for(i = 0; i < length; i++) {

            point_init(&fer_i, 0, 0, 0);

            for(j = 0; j < length; j++) {

                distance.x = neurons[i].point.x - neurons[j].point.x;
                distance.y = neurons[i].point.y - neurons[j].point.y;
                distance.z = neurons[i].point.z - neurons[j].point.z;

                point_standarize( &distance );


                fer_i.x += distance.x;
                fer_i.y += distance.y;
                fer_i.z += distance.z;
            };

            //Calculate the position change due to the Electrostatic Repulsion Force aceleration
            neurons[i].point.x += fer_i.x * DLTT2;
            neurons[i].point.y += fer_i.y * DLTT2;
            neurons[i].point.z += fer_i.z * DLTT2;

            point_standarize(  &(neurons[i].point)  );
        };
    };
};