mirror of
https://github.com/augustin64/projet-tipe
synced 2025-02-02 19:39:39 +01:00
Add tests
This commit is contained in:
parent
f0a27c627b
commit
afdfd9a8ea
18
make.sh
18
make.sh
@ -18,3 +18,21 @@ if [[ $1 == "preview" ]]; then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $1 == "test" ]]; then
|
||||||
|
[[ $2 ]] || set -- "$1" "build"
|
||||||
|
if [[ $2 == "build" ]]; then
|
||||||
|
mkdir -p out
|
||||||
|
for i in $(ls test); do
|
||||||
|
gcc "test/$i" -o "out/test_$(echo $i | awk -F. '{print $1}')" $FLAGS
|
||||||
|
done
|
||||||
|
exit
|
||||||
|
elif [[ $2 == "run" ]]; then
|
||||||
|
$0 test build
|
||||||
|
for i in $(ls out/test_*); do
|
||||||
|
echo "--- $i ---"
|
||||||
|
$i
|
||||||
|
done
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
65
test/neuron_io.c
Normal file
65
test/neuron_io.c
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#include "../src/mnist/neuron_io.c"
|
||||||
|
|
||||||
|
|
||||||
|
Neurone* creer_neurone(int nb_sortants) {
|
||||||
|
Neurone* neurone = malloc(2*sizeof(float*)+6*sizeof(float));
|
||||||
|
neurone->poids_sortants = malloc(sizeof(float)*nb_sortants);
|
||||||
|
neurone->dw = malloc(sizeof(float)*nb_sortants);
|
||||||
|
|
||||||
|
for (int i=0; i < nb_sortants; i++) {
|
||||||
|
neurone->poids_sortants[i] = 0.5;
|
||||||
|
neurone->dw[i] = 0.0;
|
||||||
|
}
|
||||||
|
neurone->activation = 0.0;
|
||||||
|
neurone->biais = 0.0;
|
||||||
|
neurone->z = 0.0;
|
||||||
|
neurone->dactivation = 0.0;
|
||||||
|
neurone->dbiais = 0.0;
|
||||||
|
neurone->dz = 0.0;
|
||||||
|
|
||||||
|
return neurone;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Couche* creer_couche(int nb_neurones, int nb_sortants) {
|
||||||
|
Couche* couche = malloc(sizeof(int)+sizeof(Neurone**));
|
||||||
|
Neurone** tab = malloc(sizeof(Neurone*)*nb_neurones);
|
||||||
|
|
||||||
|
couche->nb_neurone = nb_neurones;
|
||||||
|
couche->neurone = tab;
|
||||||
|
|
||||||
|
for (int i=0; i<nb_neurones; i++) {
|
||||||
|
tab[i] = creer_neurone(nb_sortants);
|
||||||
|
}
|
||||||
|
return couche;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reseau* creer_reseau(int nb_couches, int nb_max_neurones, int nb_min_neurones) {
|
||||||
|
Reseau* reseau = malloc(sizeof(int)+sizeof(Couche**));
|
||||||
|
reseau->couche = malloc(sizeof(Couche*)*nb_couches);
|
||||||
|
int nb_neurones[nb_couches+1];
|
||||||
|
|
||||||
|
reseau->nb_couche = nb_couches;
|
||||||
|
|
||||||
|
for (int i=0; i < nb_couches; i++) {
|
||||||
|
nb_neurones[i] = i*(nb_min_neurones-nb_max_neurones)/(nb_couches-1) + nb_max_neurones;
|
||||||
|
}
|
||||||
|
nb_neurones[nb_couches] = 0;
|
||||||
|
|
||||||
|
for (int i=0; i < nb_couches; i++) {
|
||||||
|
reseau->couche[i] = creer_couche(nb_neurones[i], nb_neurones[i+1]);
|
||||||
|
}
|
||||||
|
return reseau;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Reseau* reseau = creer_reseau(5, 300, 10);
|
||||||
|
ecrire_reseau(".test-cache/neuron_io.bin", reseau);
|
||||||
|
return 1;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user