Home | Develop | Download | Contact
example_perceptron_kernel_gaussian_yinyang.cpp

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

g++ -static -o example_perceptron_kernel_gaussian_yinyang example_perceptron_kernel_gaussian_yinyang.cpp -lpdsmlmm

Para executar o programa:

./example_perceptron_kernel_gaussian_yinyang

Retornando por consola:

┌──────────────────────────────┐
│    Kmeans                    │
│    IterationConf init data   │
├──────────────────────────────┤
│        MinError: 1.0000e-05  │
│         MaxIter: 1e+04       │
└──────────────────────────────┘
┌──────────────────────────────┐
│            Iter: 22          │
│       LastError: 0.0000e+00  │
│ Elapsed time(s): 0.00029     │
└──────────────────────────────┘
┌──────────────────────────────┐
│    Kmeans                    │
│    IterationConf init data   │
├──────────────────────────────┤
│        MinError: 1.0000e-05  │
│         MaxIter: 1e+04       │
└──────────────────────────────┘
┌──────────────────────────────┐
│            Iter: 14          │
│       LastError: 0.0000e+00  │
│ Elapsed time(s): 0.000545    │
└──────────────────────────────┘

Neurona:
-0.5636647240059        4.2500671732378 5.4892010147833 5.3230443694196 -0.79303785676519       3.3063046749552 3.3613114987862 2.1955379034242 2.938246573117  1.8896910410267 0.085686982708166       3.7274552317887 5.7643894904731 3.3514813420701 -0.44825547327836       4.5324916859488 4.9867742065307 1.7749574275709 5.2433832244008 4.0659870664641 4.166780241898  2.2914392339366 5.45212789566411.0044276383258  4.4705395627767 2.3167806979269 4.3070381347576 3.4792946126242 4.2731504272416 3.6220403005052 4.0473395344371 5.7552191007249 3.0955220962961 2.9859493831289 2.4707323903569 0.55892896589753        4.9660083796706 0.95822437302003        4.4011969499203 2.8034196827806 4.5165444193199 4.0146951120763 2.6972829247613 3.8529558751443 1.1776467889837 4.1031636581869 2.05026783008355.6837202333931  0.6971254244837 2.1468060223755 8.1671378554394 3.1121086575305 3.356313090809  4.1925353817637 2.5714048833768 4.1664511072377 4.7111517197842 0.52444367568057        -1.7028097821304        1.5570539154892 4.5261158948409 -5.8551030502859        5.1537207802395 -1.564392905755 -1.0164655332193        -2.4341794874837        -4.0647004118528        -1.2719442894787        -3.6241326267765        -5.9005867516651        -1.9020763964996        -3.1480734109237        -4.085845436565 -2.2230498257697        -1.9348291596943        -4.9716760750194        -0.82372734825709       -6.7954870541113        -5.5916737524146        -4.1626808981897        -3.3620991776216        -1.2849891036665        -4.801136088596 -4.1978443857668        -3.3848607420899        -4.4170976696187        -5.3138657579617        0.75099192767982        -5.7527521039533        -2.7576193948384        0.12884007638803        -2.9539921941337        -3.5603954216387        -3.6908682066319        -2.168710562259-2.0559827864865 -1.3752807234752        -2.5769046038249        -1.4491630891129        -1.0682296915817        -4.7770862613907        -4.0243210525499        0.10255667798547        -0.46089061402273       -2.5046122271292        -1.9215637190145        -2.8572235393748        -1.4897494416152        -1.9977801075796        -1.7174822419324        -0.56322753832583       -3.1437621583034        -5.993908810349 -0.089989509639045      -4.7789178035185        -3.1564677923807        -5.9983397118331        -3.2812792656054        -3.0849490108091        -1.2786220304571        0.45286188790035

╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.5             ║
║          Samples: 2000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 994     17      ║
║ Pred.[1]/Act.[*]: 6       983     ║
╠═══════════════════════════════════╣
║         Accuracy: 98.85 %         ║
║        Precision: 99.39 %         ║
║           Recall: 98.3  %         ║
╠═══════════════════════════════════╣
║           FScore: 98.84 %         ║
╚═══════════════════════════════════╝

╔═══════════════════════════════════╗
║    ClassificationMetrics data     ║
╠═══════════════════════════════════╣
║        Threshold: 0.5             ║
║          Samples: 2000            ║
╠═══════════════════════════════════╣
║ Pred.[0]/Act.[*]: 988     23      ║
║ Pred.[1]/Act.[*]: 12      977     ║
╠═══════════════════════════════════╣
║         Accuracy: 98.25 %         ║
║        Precision: 98.79 %         ║
║           Recall: 97.7  %         ║
╠═══════════════════════════════════╣
║           FScore: 98.24 %         ║
╚═══════════════════════════════════╝
Clasification - data


Clasification - training


Clasification - testing

Código example_perceptron_kernel_gaussian_yinyang.cpp:

#include <iostream>
#include <Pds/Ra>
#include <Pds/Ml>
int main(void)
{
Pds::Vector Yp;
Pds::Matrix F;
Conf.SetMaxIter(10000); Conf.Show=false;
double Sigma=0.1;
// Generating data
unsigned int L=1000;
Pds::Matrix X;
Pds::Vector Y;
Pds::Matrix G;
Pds::Octave::Plot::PointsX2DY(X,Y,"testando.m","example_perceptron_kernel_gaussian_yinyang_data.png");
// Create Perceptron
G=Pds::MergeVer( {Pds::Clustering::Kmeans(Conf,X.GetRows(Pds::Find(Y)),60),
Pds::Clustering::Kmeans(Conf,X.GetRows(Pds::Find(1-Y)), 60)}
); //Random centroids to Gaussian Kernel
F=Pds::Kernel::Gaussian(X,G,Sigma);
Pds::Perceptron Neurona(Conf,F,Y);
Neurona.Print("\nNeurona:\n");
// Evaluate training data
Yp=Neurona.Evaluate(F);
// Metrics of training
Metrics.Print("\n");
Pds::Octave::Plot::PointsX2DY(X,Yp,"testando.m","example_perceptron_kernel_gaussian_yinyang_training.png");
// Evaluate testing data
F=Pds::Kernel::Gaussian(X,G,Sigma);
Yp=Neurona.Evaluate(F);
// Metrics testing
Metrics.Print("\n");
Pds::Octave::Plot::PointsX2DY(X,Yp,"testando.m","example_perceptron_kernel_gaussian_yinyang_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:63
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 > &Block, unsigned int K, Pds::Array< unsigned int > &IDMAP)
Calculo de los centroides.
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.
std::string YLabel
Texto correspondente a ylabel.
std::string XLabel
Texto correspondente a xlabel.
bool PointsX2DY(const Pds::Matrix &X, const Pds::Vector &Y, const std::string &octfilename, const std::string &imgfilename)
Plot de muestras en 2D en las columnas X, clasificadas de forma binaria con Y>=0.5,...
void Print(std::string str="") const
Imprime en pantalla el contenido del vector de pesos después del texto indicado en str.
double Evaluate(const std::initializer_list< double > list) const
Evalua el objeto de tipo Pds::Perceptron.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed