summaryrefslogtreecommitdiff
path: root/Layer/Layer.cpp
blob: 52b98613a3d9da3867381384881ca959c17656b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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<Neurone*>(nbneur);
  input=std::vector<double>(nbinput);
  output= std::vector<double>(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 : "<<i<<std::endl;
    membres[i]->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<double> Layer::getInput(){
    return input;
}
std::vector<double> 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<double> Layer::fire(std::vector<double> 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;
}