Home | Develop | Download | Contact
example_ensembleperceptron.cpp

Programa para el testeo de las funciones.Para compilar o código example_ensembleperceptron.cpp:

g++ -static -o example_ensembleperceptron example_ensembleperceptron.cpp -lpdsmlmm -lpdsramm -lpdsspmm

Para executar o programa:

./example_ensembleperceptron

Retornando por consola:

Neurona:
-0.11603021997882 10.001964690054   -6.542530569312   0.025256512632287 -0.3183411876224  0.43248749720606  -45.870618298473  0.48795419807822  2.8318121968681   -2.7818812997173  -0.52305124232496 0.80011046190252  1.1350172602529   -0.33451294878204 -0.49635613933674 34.223260003171   -1.7127562893219  11.503275189772   1.5628272648821   -7.7860246338422  5.1299349023412   
Perceptron:
╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.5             ║
║          Samples: 2000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 946     67      ║
║ Pred.[1]/Act.[*]: 54      933     ║
╠═══════════════════════════════════╣
║         Accuracy: 93.95 %         ║
║        Precision: 94.53 %         ║
║           Recall: 93.3  %         ║
╠═══════════════════════════════════╣
║           FScore: 93.91 %         ║
╚═══════════════════════════════════╝
Trained bag 0 with 1200 samples.
Trained bag 1 with 1200 samples.
Trained bag 2 with 1200 samples.
Trained bag 3 with 1200 samples.
Trained bag 4 with 1200 samples.
Trained bag 5 with 1200 samples.
Trained bag 6 with 1200 samples.
Trained bag 7 with 1200 samples.
Trained bag 8 with 1200 samples.
Trained bag 9 with 1200 samples.
EnsemblePerceptron:
╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.5             ║
║          Samples: 2000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 989     21      ║
║ Pred.[1]/Act.[*]: 11      979     ║
╠═══════════════════════════════════╣
║         Accuracy: 98.4  %         ║
║        Precision: 98.89 %         ║
║           Recall: 97.9  %         ║
╠═══════════════════════════════════╣
║           FScore: 98.39 %         ║
╚═══════════════════════════════════╝
Saving file: ensemble0.dat
Saving file: ensemble1.dat
Saving file: ensemble2.dat
Saving file: ensemble3.dat
Saving file: ensemble4.dat
Saving file: ensemble5.dat
Saving file: ensemble6.dat
Saving file: ensemble7.dat
Saving file: ensemble8.dat
Saving file: ensemble9.dat
Classification - data


Classification - perceptron


Classification - ensemble

Código example_ensembleperceptron.cpp:

#include <iostream>
#include <Pds/Ra>
#include <Pds/Ml>
int main(void)
{
Pds::Vector Yp;
Conf.SetMaxIter(5000);
unsigned int M=5;
// Generating data
unsigned int L=1000;
Pds::Matrix X;
Pds::Vector Y;
Pds::Matrix F=Pds::Kernel::Polynomial(X,M);
Pds::Octave::XLabel="x_1";
Pds::Octave::YLabel="x_2";
Pds::Octave::Plot::PointsX2DY(X,Y,"testando.m","example_ensembleperceptron_data.png");
// Create Perceptron
Pds::Perceptron Neurona(Conf,F,Y);
Neurona.Print("\nNeurona:\n");
// Predict training data
Yp=Neurona.Predict(F);
// Metrics of training
Metrics.Print("Perceptron:\n");
Pds::Octave::Plot::PointsX2DY(X,Yp,"testando.m","example_ensembleperceptron_perceptron.png");
// Create Perceptron
unsigned int Nel=10;
Pds::EnsemblePerceptron BagN(Conf,F,Y,Nel,0.5);
BagN.Print("BagN:\n");
Yp=BagN.Predict(F);
// Metrics testing
Metrics.Print("EnsemblePerceptron:\n");
Pds::Octave::Plot::PointsX2DY(X,Yp,"testando.m","example_ensembleperceptron_ensemble.png");
// Test export import
BagN.ExportFile("example_ensembleperceptron_ensemble.dat");
return 0;
}
La clase tipo Pds::ClassificationMetrics . Esta clase genera un bloque de datos para analizar curvas ...
La clase tipo Pds::EnsemblePerceptron . Esta clase genera una matriz de Nlin lineas y 1 columna....
La clase tipo Pds::IterationConf . Esta clase genera una matriz de Nlin lineas y 1 columna....
La clase tipo Pds::Perceptron . Esta clase genera una matriz de Nlin lineas y 1 columna....
Definition: Perceptron.hpp:64
static Pds::ClassificationMetrics Calculate(double Threshold, const Pds::Vector &Ypredict, const Pds::Vector &Yactual)
Crea un objeto Dat de tipo Pds::ClassificationMetrics.
void Print(std::string str="")
Imprime en pantalla los datos de la estructura tipo Pds::ClassificationMetrics.
bool ExportFile(const std::string &filename) const
Salva en formato texto el objeto de tipo Pds::EnsemblePerceptron.
double Predict(const Pds::Vector &x) const
Evalua el objeto de tipo Pds::EnsemblePerceptron.
void Print(std::string str="") const
Imprime en pantalla el contenido del vector de pesos después del texto indicado en str.
bool SetMaxIter(unsigned int MaxIter)
Coloca el valor MaxIter.
void LoadDataSine(unsigned int L, Pds::Matrix &X, Pds::Vector &Y)
Clasificacion de datos separados por una curva.
Pds::Matrix Polynomial(const Pds::Matrix &X, unsigned int M)
Crea una nueva matriz de "features" kernelizando de forma polinomial.
double Predict(const std::initializer_list< double > list) const
Evalua el objeto de tipo Pds::Perceptron.
void Print(std::string str="") const
Imprime en pantalla el contenido del vector de pesos después del texto indicado en str.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed