Home | Develop | Download | Contact
example_fcnn_training_actfunc.cpp
1 
33 #include <Pds/Ra>
34 #include <Pds/Nn>
35 
36 int main(void)
37 {
38  unsigned int M=8000;
39  Pds::Vector Acc0(M);
40  Pds::Vector Acc1(M);
41  Pds::Vector Acc2(M);
42  std::string str;
43 
44  Pds::Matrix X(Pds::Ra::TextFormat,"../test/data_x_yinyang.txt");
45  Pds::Matrix Y(Pds::Ra::TextFormat,"../test/data_y_yinyang.txt");
46  Pds::Matrix Ys(Y.Size());
47 
48  std::vector<unsigned int> N={2,5,11,23,11,5,1};
49  Pds::FCNn NN0=Pds::FCNn(N,Pds::Sigmoid,Pds::DSigmoid);
50 
51  Pds::FCNn NN1=Pds::FCNn(NN0);
52  NN1.SetActFunc(0,Pds::ELU,Pds::DELU);
53  NN1.SetActFunc(1,Pds::Tanh,Pds::DTanh);
54  NN1.SetActFunc(2,Pds::ELU,Pds::DELU);
55  NN1.SetActFunc(3,Pds::Tanh,Pds::DTanh);
56  NN1.SetActFunc(4,Pds::ELU,Pds::DELU);
57 
58  Pds::FCNn NN2=Pds::FCNn(NN0);
59  NN2.SetActFunc(Pds::Tanh,Pds::DTanh);
60 
61  for(unsigned int k=0;k<M;k++)
62  {
63  NN0.Training(X,Y,0.1,0.01);
64  NN1.Training(X,Y,0.1,0.01);
65  NN2.Training(X,Y,0.1,0.01);
66 
67  NN0.Predict(X,Ys);
68  Acc0.Set(k,100.0*Pds::Accuracy(Ys.Geq(0.5),Y));
69 
70  NN1.Predict(X,Ys);
71  Acc1.Set(k,100.0*Pds::Accuracy(Ys.Geq(0.5),Y));
72 
73  NN2.Predict(X,Ys);
74  Acc2.Set(k,100.0*Pds::Accuracy(Ys.Geq(0.5),Y));
75 
76  // Progress bar
77  str="acc0: "+std::to_string(Acc0.At(k));
78  str=str+"\tacc1: "+std::to_string(Acc1.At(k));
79  str=str+"\tacc2: "+std::to_string(Acc2.At(k));
80  Pds::Ra::ProgressBarWithTime(32,k,M,false,str);
81  }
82  std::cout<<std::endl;
83 
84  // Ploting
85  Pds::Octave::XLabel="Iter";
86  Pds::Octave::YLabel="Accuracy";
87  Pds::Octave::Legend={"Pds::Sigmoid","Compound"};
88  Pds::Octave::Plot::CurveXYXY( Pds::LinSpace(0,M-1,M),Acc0,
89  Pds::LinSpace(0,M-1,M),Acc1,
90  "testandoAcc01.m",
91  "example_fcnn_training_actfunc_Acc01.png");
92  Pds::Octave::Legend={"Pds::Sigmoid","Pds::Tanh"};
93  Pds::Octave::Plot::CurveXYXY( Pds::LinSpace(0,M-1,M),Acc0,
94  Pds::LinSpace(0,M-1,M),Acc2,
95  "testandoAcc02.m",
96  "example_fcnn_training_actfunc_Acc02.png");
97 
98  Pds::Octave::XLabel="x_1";
99  Pds::Octave::YLabel="x_2";
100  Pds::Octave::Plot::PointsX2DY(X,Y ,"testando.m","example_fcnn_training_actfunc_Y.png");
101 
102  NN0.Predict(X,Ys);
103  Pds::Octave::Plot::PointsX2DY(X,Ys,"testando.m","example_fcnn_training_actfunc_Ys0.png");
104 
105  NN1.Predict(X,Ys);
106  Pds::Octave::Plot::PointsX2DY(X,Ys,"testando.m","example_fcnn_training_actfunc_Ys1.png");
107 
108  NN2.Predict(X,Ys);
109  Pds::Octave::Plot::PointsX2DY(X,Ys,"testando.m","example_fcnn_training_actfunc_Ys2.png");
110  return 0;
111 }
La clase tipo Pds::FCNn . Esta clase genera un objeto con dos parametros Nlin y Ncol....
Definition: FCNn.hpp:62
const std::string FCNn
Tag de un objeto de tipo Pds::FCNn.
Definition: NnDefines.hpp:165
bool Training(const Pds::Matrix &X, const Pds::Matrix &Y, double alpha, double lambda)
Treina la NN como um bloque de datos entero X para encontrar una variacion de pesos.
Pds::SampleBlock Predict(const Pds::SampleBlock &In) const
Evalua la capa de la CNN.
bool SetActFunc(unsigned int k, double(*func)(double), double(*dfunc)(double))
Retorna true si la funcion de activacion fue modificada o false si no.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed