From b4c345e6a5fa929ba20eac19183b9c777055f52d Mon Sep 17 00:00:00 2001 From: Gaspard Coulet Date: Wed, 28 Apr 2021 23:12:36 +0200 Subject: Initial commit --- Layer/InputLayer.cpp | 31 ++++++++++++++++++++++ Layer/InputLayer.h | 10 +++++++ Layer/Layer.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Layer/Layer.h | 32 ++++++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 Layer/InputLayer.cpp create mode 100644 Layer/InputLayer.h create mode 100644 Layer/Layer.cpp create mode 100644 Layer/Layer.h (limited to 'Layer') diff --git a/Layer/InputLayer.cpp b/Layer/InputLayer.cpp new file mode 100644 index 0000000..79c0751 --- /dev/null +++ b/Layer/InputLayer.cpp @@ -0,0 +1,31 @@ +#include "./InputLayer.h" +/** + * Constructeur par taille + * @method InputLayer::InputLayer + * @param taille Nombre de neurones dans le layer + */ +InputLayer::InputLayer(int taille,FonctionActivation::EnumFonctionActivation fct){ + membres =std::vector (taille); + nbNeurone = taille; + input=std::vector(taille); + output= std::vector(taille); + for (int i = 0; i < taille; i ++){ + membres[i] = new Neurone(1, new std::vector(1,1),fct); + } +} +/** + * Méthode de propagation en avant + * @method InputLayer::fire + * @param input Vecteur en entrées + * @param k Coefficient de sigmoid + * @return Valeur d'activation + */ +std::vector InputLayer::fire(std::vector input, double k){ + for (unsigned int i =0; i < input.size(); i ++){ + this->input[i] = input[i]; + } + for (int i = 0 ; i < nbNeurone; i ++){ + output[i]=membres[i]->fire({input[i]},k); //faut il activer ou non? OUI! + } + return output; +} diff --git a/Layer/InputLayer.h b/Layer/InputLayer.h new file mode 100644 index 0000000..aa89a4c --- /dev/null +++ b/Layer/InputLayer.h @@ -0,0 +1,10 @@ +#ifndef _INPUTLAYER_H_ +#define _INPUTLAYER_H_ +#include "./Layer.h" + +class InputLayer : public Layer { +public: + InputLayer(int,FonctionActivation::EnumFonctionActivation fct); + std::vector fire(std::vector, double); +}; +#endif diff --git a/Layer/Layer.cpp b/Layer/Layer.cpp new file mode 100644 index 0000000..52b9861 --- /dev/null +++ b/Layer/Layer.cpp @@ -0,0 +1,75 @@ +#include"./Layer.h" + +/** + * Constructeur par défauts + * @method Layer::Layer + */ +Layer::Layer(){} +/** + * Constructeur avec arguments + * @method Layer::Layer + * @param type Type de layer + * @param nbneur Nombre de neurone + * @param nbinput Nombre d'entrée par neurone + */ +Layer::Layer(TypeLayer type,int nbneur, int nbinput, FonctionActivation::EnumFonctionActivation fct):nbNeurone(nbneur) +{ + membres = std::vector(nbneur); + input=std::vector(nbinput); + output= std::vector(nbneur); + for (int i =0; i < nbneur; i ++){ + membres[i]= new NeuroneB(nbinput,fct); + } +} +/** +* @method Layer::getNeurone +* @param index index +* @return Neurone +*/ +Neurone * Layer::getNeurone (int index){ + return membres[index]; +} +/** + * Affiche les poids + * @method Layer::printWeight + */ +void Layer::printWeight(){ + for (int i =0; i < nbNeurone;i++){ + std::cout<<"Neurone numero : "<printWeight(); + } +} +/** + * @method Layer::getNbNeurones + * @return Nombre de neurones + */ +int Layer::getNbNeurones(){ + return nbNeurone; +} +/** + * @method Layer::getInput + * @return Retourne le vecteur d'entrées + */ +std::vector Layer::getInput(){ + return input; +} +std::vector Layer::getOutput(){ + return output; +} + +/** + * Propagation en avant + * @method Layer::fire + * @param input Vecteur en entrées + * @param k Coefficient de sigmoid + * @return Vecteur des valeurs d'activations + */ +std::vector Layer::fire(std::vector input, double k) { + for (unsigned int i =0; i < input.size(); i ++){ + this->input[i] = input[i]; + } + for (int i = 0; i < nbNeurone; i++){ + output[i] = membres[i]->fw_activate(membres[i]->fw_sum(input),k); + } +return output; +} diff --git a/Layer/Layer.h b/Layer/Layer.h new file mode 100644 index 0000000..501ed86 --- /dev/null +++ b/Layer/Layer.h @@ -0,0 +1,32 @@ +#ifndef _LAYER_H_ +#define _LAYER_H_ +#include"../Neurone/Neurone.h" +#include"../Neurone/NeuroneB.h" +#include "../Neurone/FonctionActivation.h" +#include + +class Layer { +public: + enum TypeLayer { + INPUT, + OUTPUT, + HIDDEN + }; +protected: + double k; + int nbNeurone; + std::vector membres; + std::vector input; + std::vector output; + TypeLayer type; +public: + Layer(); + Layer(TypeLayer,int,int,FonctionActivation::EnumFonctionActivation); + Neurone * getNeurone(int index); + virtual std::vector fire(std::vector, double); + int getNbNeurones(); + std::vector getInput(); + std::vector getOutput(); + void printWeight(); +}; + #endif -- cgit v1.2.3