Home | Develop | Download | Contact
example_fcnn_training_actfunc.cpp

Programa para el testeo de las funciones Fully Connected Layer.Para compilar o código example_fcnn_training_actfunc.cpp:

g++ -static -o example_fcnn_training_actfunc example_fcnn_training_actfunc.cpp -lpdsramm -lpdsnnmm

Para executar o programa:

./example_fcnn_training_actfunc

Retornando por consola:

 8000/8000 [================================] -- ERT  0:00 -- acc0: 81.000000   acc1: 89.300000 acc2: 88.900000
Datos de treinamento.
Datos despues del treinamento NN0.
Datos despues del treinamento NN1.
Datos despues del treinamento NN2.
Datos de Accuracy.
Datos de Accuracy.

Código example_fcnn_training_actfunc.cpp:

#include <Pds/Ra>
#include <Pds/Nn>
int main(void)
{
unsigned int M=8000;
Pds::Vector Acc0(M);
Pds::Vector Acc1(M);
Pds::Vector Acc2(M);
std::string str;
Pds::Matrix X(Pds::Ra::TextFormat,"../test/data_x_yinyang.txt");
Pds::Matrix Y(Pds::Ra::TextFormat,"../test/data_y_yinyang.txt");
Pds::Matrix Ys(Y.Size());
std::vector<unsigned int> N={2,5,11,23,11,5,1};
Pds::FCNn NN0=Pds::FCNn(N,Pds::Sigmoid,Pds::DSigmoid);
Pds::FCNn NN1=Pds::FCNn(NN0);
NN1.SetActFunc(0,Pds::ELU,Pds::DELU);
NN1.SetActFunc(1,Pds::Tanh,Pds::DTanh);
NN1.SetActFunc(2,Pds::ELU,Pds::DELU);
NN1.SetActFunc(3,Pds::Tanh,Pds::DTanh);
NN1.SetActFunc(4,Pds::ELU,Pds::DELU);
Pds::FCNn NN2=Pds::FCNn(NN0);
NN2.SetActFunc(Pds::Tanh,Pds::DTanh);
for(unsigned int k=0;k<M;k++)
{
NN0.Training(X,Y,0.1,0.01);
NN1.Training(X,Y,0.1,0.01);
NN2.Training(X,Y,0.1,0.01);
NN0.Predict(X,Ys);
Acc0.Set(k,100.0*Pds::Accuracy(Ys.Geq(0.5),Y));
NN1.Predict(X,Ys);
Acc1.Set(k,100.0*Pds::Accuracy(Ys.Geq(0.5),Y));
NN2.Predict(X,Ys);
Acc2.Set(k,100.0*Pds::Accuracy(Ys.Geq(0.5),Y));
// Progress bar
str="acc0: "+std::to_string(Acc0.At(k));
str=str+"\tacc1: "+std::to_string(Acc1.At(k));
str=str+"\tacc2: "+std::to_string(Acc2.At(k));
Pds::Ra::ProgressBarWithTime(32,k,M,false,str);
}
std::cout<<std::endl;
// Ploting
Pds::Octave::XLabel="Iter";
Pds::Octave::YLabel="Accuracy";
Pds::Octave::Legend={"Pds::Sigmoid","Compound"};
Pds::Octave::Plot::CurveXYXY( Pds::LinSpace(0,M-1,M),Acc0,
Pds::LinSpace(0,M-1,M),Acc1,
"testandoAcc01.m",
"example_fcnn_training_actfunc_Acc01.png");
Pds::Octave::Legend={"Pds::Sigmoid","Pds::Tanh"};
Pds::Octave::Plot::CurveXYXY( Pds::LinSpace(0,M-1,M),Acc0,
Pds::LinSpace(0,M-1,M),Acc2,
"testandoAcc02.m",
"example_fcnn_training_actfunc_Acc02.png");
Pds::Octave::XLabel="x_1";
Pds::Octave::YLabel="x_2";
Pds::Octave::Plot::PointsX2DY(X,Y ,"testando.m","example_fcnn_training_actfunc_Y.png");
NN0.Predict(X,Ys);
Pds::Octave::Plot::PointsX2DY(X,Ys,"testando.m","example_fcnn_training_actfunc_Ys0.png");
NN1.Predict(X,Ys);
Pds::Octave::Plot::PointsX2DY(X,Ys,"testando.m","example_fcnn_training_actfunc_Ys1.png");
NN2.Predict(X,Ys);
Pds::Octave::Plot::PointsX2DY(X,Ys,"testando.m","example_fcnn_training_actfunc_Ys2.png");
return 0;
}
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