Home | Develop | Download | Contact
example_perceptron_kernel_gaussian_yinyang2.cpp

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

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

Para executar o programa:

./example_perceptron_kernel_gaussian_yinyang2

Retornando por consola:

Neurona:
0.1758083022248  -8.6487555419947 -8.788829119114  -7.5034303296872 -7.221256389084  -7.4351142358589 -7.1386765267093 -8.5061559836684 -8.8781505169577 -8.7493849843645 -4.9570411895064 -7.3867368563384 -7.0667960156638 6.9274895852939  6.4736966944438  7.6067216407531  6.3736354528218  7.8450425370139  7.3352561755174  7.3670027696057  6.1262235652442  4.9086447179916  7.5959828499847  7.2198125494198  7.6606725092723  

╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.5             ║
║          Samples: 2000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 952     47      ║
║ Pred.[1]/Act.[*]: 48      953     ║
╠═══════════════════════════════════╣
║         Accuracy: 95.25 %         ║
║        Precision: 95.2  %         ║
║           Recall: 95.3  %         ║
╠═══════════════════════════════════╣
║           FScore: 95.25 %         ║
╚═══════════════════════════════════╝

╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.5             ║
║          Samples: 2000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 950     64      ║
║ Pred.[1]/Act.[*]: 50      936     ║
╠═══════════════════════════════════╣
║         Accuracy: 94.3  %         ║
║        Precision: 94.93 %         ║
║           Recall: 93.6  %         ║
╠═══════════════════════════════════╣
║           FScore: 94.26 %         ║
╚═══════════════════════════════════╝
Classification - data


Classification - training


Classification - testing

Código example_perceptron_kernel_gaussian_yinyang2.cpp:

#include <iostream>
#include <Pds/Ra>
#include <Pds/Ml>
int main(void)
{
Pds::Vector Yp;
Pds::Matrix F;
Conf.SetMaxIter(10000); Conf.Show=false;
unsigned int K=12;
// Generating data
unsigned int L=1000;
Pds::Matrix X;
Pds::Vector Y;
Pds::Matrix G;
Pds::Octave::XLabel="x_1";
Pds::Octave::YLabel="x_2";
Pds::Octave::Plot::PointsX2DY(X,Y,"testando.m","example_perceptron_kernel_gaussian_yinyang2_data.png");
// Create Perceptron
Pds::Array<unsigned int> ID0,ID1;
std::vector<Pds::Matrix> Block=X.FindRowsBlock(Y);
Pds::Matrix G0=Pds::Clustering::Kmeans(Conf,Block[0],K,ID0);
Pds::Matrix G1=Pds::Clustering::Kmeans(Conf,Block[1],K,ID1);
std::vector<double> Sigma0=Pds::Clustering::KmeansSigma(Block[0],ID0);
std::vector<double> Sigma1=Pds::Clustering::KmeansSigma(Block[1],ID1);
G=Pds::MergeVer({G0,G1});
Sigma0.insert(Sigma0.end() , Sigma1.begin() , Sigma1.end());
F=Pds::Kernel::Gaussian(X,G,Sigma0);
Pds::Perceptron Neurona(Conf,F,Y);
Neurona.Print("\nNeurona:\n");
// Predict training data
Yp=Neurona.Predict(F);
// Metrics of training
Metrics.Print("\n");
Pds::Octave::Plot::PointsX2DY(X,Yp,"testando.m","example_perceptron_kernel_gaussian_yinyang2_training.png");
// Predict testing data
F=Pds::Kernel::Gaussian(X,G,Sigma0);
Yp=Neurona.Predict(F);
// Metrics testing
Metrics.Print("\n");
Pds::Octave::Plot::PointsX2DY(X,Yp,"testando.m","example_perceptron_kernel_gaussian_yinyang2_testing.png");
return 0;
}
La clase tipo Pds::ClassificationMetrics . Esta clase genera un bloque de datos para analizar curvas ...
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 SetMaxIter(unsigned int MaxIter)
Coloca el valor MaxIter.
Pds::Matrix Kmeans(Pds::IterationConf &Conf, const std::vector< Pds::Matrix > &IMG, unsigned int K, Pds::Array< unsigned int > &IDMAP)
Calculo de los centroides de las muestras (pixels) en std::vector<Pds::Matrix> IMG.
void LoadDataYinYang(unsigned int L, Pds::Matrix &X, Pds::Vector &Y)
Clasificacion de datos separados por mas de una curva.
Pds::Matrix Gaussian(const Pds::Matrix &X, const Pds::Matrix &G, double Sigma=1.0)
Crea una nueva matriz de "features" kernelizando de forma gaussiana.
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.
std::vector< double > KmeansSigma(const Pds::Matrix &X, const Pds::Array< unsigned int > &ID)

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed