tipe/src/cnn/initialisation.c

52 lines
2.0 KiB
C
Raw Normal View History

2022-07-05 08:13:25 +02:00
#include <stdlib.h>
#include <math.h>
2022-09-16 14:53:35 +02:00
#include "include/initialisation.h"
2022-07-05 08:13:25 +02:00
2022-09-26 18:00:31 +02:00
void initialisation_1d_matrix(int initialisation, float* matrix, int rows, int n) { // TODO
printf("\033[33;1m[WARNING]\033[0m Appel de initialisation_1d_matrix, incomplet\n");
2022-07-05 08:13:25 +02:00
float lower_bound = -6/sqrt((double)n);
float distance = -lower_bound-lower_bound;
for (int i=0; i < rows; i++) {
2022-07-05 08:13:25 +02:00
matrix[i] = lower_bound + RAND_FLT()*distance;
}
}
2022-09-26 18:00:31 +02:00
void initialisation_2d_matrix(int initialisation, float** matrix, int rows, int columns, int n) { // TODO
printf("\033[33;1m[WARNING]\033[0m Appel de initialisation_2d_matrix, incomplet\n");
2022-07-05 08:13:25 +02:00
float lower_bound = -6/sqrt((double)n);
float distance = -lower_bound-lower_bound;
for (int i=0; i < rows; i++) {
for (int j=0; j < columns; j++) {
2022-07-05 08:13:25 +02:00
matrix[i][j] = lower_bound + RAND_FLT()*distance;
}
}
}
2022-09-26 18:00:31 +02:00
void initialisation_3d_matrix(int initialisation, float*** matrix, int depth, int rows, int columns, int n) { // TODO
printf("\033[33;1m[WARNING]\033[0m Appel de initialisation_3d_matrix, incomplet\n");
2022-07-05 08:13:25 +02:00
float lower_bound = -6/sqrt((double)n);
float distance = -lower_bound-lower_bound;
for (int i=0; i < depth; i++) {
for (int j=0; j < rows; j++) {
for (int k=0; k < columns; k++) {
2022-07-05 08:13:25 +02:00
matrix[i][j][k] = lower_bound + RAND_FLT()*distance;
}
}
}
}
2022-09-26 18:00:31 +02:00
void initialisation_4d_matrix(int initialisation, float**** matrix, int rows, int columns, int rows1, int columns1, int n) { // TODO
printf("\033[33;1m[WARNING]\033[0m Appel de initialisation_4d_matrix, incomplet\n");
2022-07-05 08:13:25 +02:00
float lower_bound = -6/sqrt((double)n);
float distance = -lower_bound-lower_bound;
for (int i=0; i < rows; i++) {
for (int j=0; j < columns; j++) {
for (int k=0; k < rows1; k++) {
for (int l=0; l < columns1; l++) {
2022-07-05 08:13:25 +02:00
matrix[i][j][k][l] = lower_bound + RAND_FLT()*distance;
}
}
}
}
}