mirror of
https://github.com/augustin64/projet-tipe
synced 2025-01-23 23:26:25 +01:00
Add mean squared error (MSE)
This commit is contained in:
parent
e4ec06705b
commit
638cada723
@ -53,11 +53,11 @@ void forward_propagation(Network* network) {
|
||||
output_width = network->width[i+1];
|
||||
activation = k_i->activation;
|
||||
|
||||
if (k_i->cnn!=NULL) { // Convolution
|
||||
if (k_i->cnn) { // Convolution
|
||||
make_convolution(k_i->cnn, input, output, output_width);
|
||||
choose_apply_function_matrix(activation, output, output_depth, output_width);
|
||||
}
|
||||
else if (k_i->nn!=NULL) { // Full connection
|
||||
else if (k_i->nn) { // Full connection
|
||||
if (input_depth==1) { // Vecteur -> Vecteur
|
||||
make_dense(k_i->nn, input[0][0], output[0][0], input_width, output_width);
|
||||
} else { // Matrice -> vecteur
|
||||
@ -80,7 +80,7 @@ void backward_propagation(Network* network, float wanted_number) {
|
||||
printf_warning("Appel de backward_propagation, incomplet\n");
|
||||
float* wanted_output = generate_wanted_output(wanted_number);
|
||||
int n = network->size;
|
||||
float loss = compute_cross_entropy_loss(network->input[n][0][0], wanted_output, network->width[n]);
|
||||
float loss = compute_mean_squared_error(network->input[n][0][0], wanted_output, network->width[n]);
|
||||
int activation, input_depth, input_width, output_depth, output_width;
|
||||
float*** input;
|
||||
float*** output;
|
||||
@ -106,6 +106,18 @@ void backward_propagation(Network* network, float wanted_number) {
|
||||
free(wanted_output);
|
||||
}
|
||||
|
||||
float compute_mean_squared_error(float* output, float* wanted_output, int len) {
|
||||
if (len==0) {
|
||||
printf("Erreur MSE: la longueur de la sortie est de 0 -> division par 0 impossible\n");
|
||||
return 0.;
|
||||
}
|
||||
float loss=0.;
|
||||
for (int i=0; i < len ; i++) {
|
||||
loss += (output[i]-wanted_output[i])*(output[i]-wanted_output[i]);
|
||||
}
|
||||
return loss/len;
|
||||
}
|
||||
|
||||
float compute_cross_entropy_loss(float* output, float* wanted_output, int len) {
|
||||
float loss=0.;
|
||||
for (int i=0; i < len ; i++) {
|
||||
|
@ -7,12 +7,12 @@
|
||||
/*
|
||||
* Renvoie si oui ou non (1 ou 0) le neurone va être abandonné
|
||||
*/
|
||||
int will_be_drop(int dropout_prob); //CHECKED
|
||||
int will_be_drop(int dropout_prob);
|
||||
|
||||
/*
|
||||
* Écrit une image 28*28 au centre d'un tableau 32*32 et met à 0 le reste
|
||||
*/
|
||||
void write_image_in_network_32(int** image, int height, int width, float** input); //CHECKED
|
||||
void write_image_in_network_32(int** image, int height, int width, float** input);
|
||||
|
||||
/*
|
||||
* Propage en avant le cnn
|
||||
@ -22,10 +22,15 @@ void forward_propagation(Network* network);
|
||||
/*
|
||||
* Propage en arrière le cnn
|
||||
*/
|
||||
void backward_propagation(Network* network, float wanted_number); // TODO
|
||||
void backward_propagation(Network* network, float wanted_number);
|
||||
|
||||
/*
|
||||
* Renvoie l'erreur du réseau neuronal pour une sortie
|
||||
* Renvoie l'erreur du réseau neuronal pour une sortie (RMS)
|
||||
*/
|
||||
float compute_mean_squared_error(float* output, float* wanted_output, int len);
|
||||
|
||||
/*
|
||||
* Renvoie l'erreur du réseau neuronal pour une sortie (CEL)
|
||||
*/
|
||||
float compute_cross_entropy_loss(float* output, float* wanted_output, int len);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user