Updating/Adding functions
这个提交包含在:
父节点
ce66110173
当前提交
048e1cee61
共有 9 个文件被更改,包括 69 次插入 和 4 次删除
7
Makefile
7
Makefile
|
|
@ -1 +1,6 @@
|
||||||
default : executable
|
send :
|
||||||
|
git add .
|
||||||
|
git commit
|
||||||
|
git push
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
二进制
exe
可执行文件
二进制
exe
可执行文件
二进制文件未显示。
8
main.c
8
main.c
|
|
@ -1,11 +1,19 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "randomness.h"
|
||||||
#include "neurons.h"
|
#include "neurons.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
init_randomness();
|
||||||
|
|
||||||
printf("Bonjour et bienvenu ;)\n");
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "randomness.h"
|
||||||
#include "neurons.h"
|
#include "neurons.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
|
|
@ -8,3 +9,11 @@ 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
|
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
|
#endif
|
||||||
22
neurons.c
22
neurons.c
|
|
@ -1,19 +1,37 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "randomness.h"
|
||||||
#include "neurons.h"
|
#include "neurons.h"
|
||||||
|
|
||||||
Neuron *init_neuron(int n_weights)
|
Neuron *init_neuron(int n_weights)
|
||||||
{
|
{
|
||||||
Neuron *neuron = (Neuron*)malloc(sizeof(Neuron));
|
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->output = 0.0;
|
||||||
neuron->delta_error = 0.0;
|
neuron->delta_error = 0.0;
|
||||||
neuron->same_layer_next_neuron = NULL;
|
neuron->same_layer_next_neuron = NULL;
|
||||||
|
|
||||||
|
return neuron;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_neuron(Neuron *neuron)
|
void destroy_neuron(Neuron *neuron)
|
||||||
{
|
{
|
||||||
free(neuron->weights);
|
if(neuron->weights != NULL)
|
||||||
|
{
|
||||||
|
free(neuron->weights);
|
||||||
|
}
|
||||||
free(neuron);
|
free(neuron);
|
||||||
}
|
}
|
||||||
|
|
@ -4,7 +4,8 @@
|
||||||
typedef struct neuron Neuron;
|
typedef struct neuron Neuron;
|
||||||
struct 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 output; //output of the neuron
|
||||||
float delta_error; //the delta error for updating current weights
|
float delta_error; //the delta error for updating current weights
|
||||||
Neuron *same_layer_next_neuron;
|
Neuron *same_layer_next_neuron;
|
||||||
|
|
|
||||||
15
randomness.c
普通文件
15
randomness.c
普通文件
|
|
@ -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
普通文件
7
randomness.h
普通文件
|
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef RANDOMNESS_H
|
||||||
|
#define RANDOMNESS_H
|
||||||
|
|
||||||
|
void init_randomness(void);
|
||||||
|
float random_float(float min, float max);
|
||||||
|
|
||||||
|
#endif
|
||||||
正在加载…
在新工单中引用