Home | Develop | Download | Contact
example_nbgmm_2d.cpp

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

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

Para executar o programa:

./example_nbgmm_2d

Retornando por consola:

----- NBGMM :
Dat[0]:
Sinv[0]:
57.512774425347  -3.5675801168447 
-3.5675801168447 23.906878837636  
Sinv[1]:
9.2988606601571  -2.9974220018541 
-2.9974220018541 23.307826521451  
Mu[0]:
0.6838152805562   0.044181321081201 
Mu[1]:
1.3029639890898     -0.0071845637268321 
Det[0]: 0.00073409403480011
Det[1]: 0.0048134385244901
Pi[0]: 0.48340302205376
Pi[1]: 0.51659697794624
Dat[1]:
Sinv[0]:
843.73943027504 101.98522017984 
101.98522017984 20.328223711271 
Sinv[1]:
2.430847925041   0.57181311660923 
0.57181311660923 16.095766128233  
Mu[0]:
-1.4379679792559 0.77696959813356 
Mu[1]:
-0.2873765198266 0.90079394116991 
Det[0]: 0.00014813193576568
Det[1]: 0.02577360144222
Pi[0]: 0.17541832616091
Pi[1]: 0.82458167383909
Dat[2]:
Sinv[0]:
53.257340465961 9.3316943350241 
9.3316943350241 26.581841815239 
Sinv[1]:
19.858121008278 9.5434147475367 
9.5434147475367 31.562390053018 
Mu[0]:
-0.8979376935544  -0.84701905458908 
Mu[1]:
-0.27306690649968 -0.8747926917522  
Det[0]: 0.0007526732995238
Det[1]: 0.0018667408526513
Pi[0]: 0.32528696320006
Pi[1]: 0.67471303679994
Pi[0]:  0.33333333333333
Pi[1]:  0.33333333333333
Pi[2]:  0.33333333333333
Label[0]:       0
Label[1]:       1
Label[2]:       2

----- NBGMM2 :
Dat[0]:
Sinv[0]:
57.512774425347  -3.5675801168447 
-3.5675801168447 23.906878837636  
Sinv[1]:
9.2988606601571  -2.9974220018541 
-2.9974220018541 23.307826521451  
Mu[0]:
0.6838152805562   0.044181321081201 
Mu[1]:
1.3029639890898     -0.0071845637268321 
Det[0]: 0.00073409403480011
Det[1]: 0.0048134385244901
Pi[0]: 0.48340302205376
Pi[1]: 0.51659697794624
Dat[1]:
Sinv[0]:
843.73943027504 101.98522017984 
101.98522017984 20.328223711271 
Sinv[1]:
2.430847925041   0.57181311660923 
0.57181311660923 16.095766128233  
Mu[0]:
-1.4379679792559 0.77696959813356 
Mu[1]:
-0.2873765198266 0.90079394116991 
Det[0]: 0.00014813193576568
Det[1]: 0.02577360144222
Pi[0]: 0.17541832616091
Pi[1]: 0.82458167383909
Dat[2]:
Sinv[0]:
53.257340465961 9.3316943350241 
9.3316943350241 26.581841815239 
Sinv[1]:
19.858121008278 9.5434147475367 
9.5434147475367 31.562390053018 
Mu[0]:
-0.8979376935544  -0.84701905458908 
Mu[1]:
-0.27306690649968 -0.8747926917522  
Det[0]: 0.0007526732995238
Det[1]: 0.0018667408526513
Pi[0]: 0.32528696320006
Pi[1]: 0.67471303679994
Pi[0]:  0.33333333333333
Pi[1]:  0.33333333333333
Pi[2]:  0.33333333333333
Label[0]:       0
Label[1]:       1
Label[2]:       2

Tarining data:

example_nbgmm_2d_data.png



Confusion matrix:

example_nbgmm_2d_ConfMatrix.png



Decision boundaries:

example_nbgmm_2d_class.png

Código example_nbgmm_2d.cpp:

#include <iostream>
#include <Pds/Ra>
#include <Pds/Ml>
int main(void)
{
unsigned int L=48;
unsigned int K=3;
Pds::Octave::MarkerSize=64;
Pds::Octave::YLimits=true;
Pds::Octave::XLimits=true;
Pds::Octave::DAspect=true;
Pds::Matrix X;
Pds::Vector Y,Ys;
// Load dataset of L samples an K gaussian normal.
// Plor de dataset X with label Y.
Pds::Octave::Plot::ScatterX2DY(X,Y,"testando3d.m","example_nbgmm_2d_data.png");
// Calculate the NbGmm classifier.
Pds::NBGMM NbGmm(Conf,X,Y,{2,2,2});
NbGmm.Print("\n----- NBGMM :\n");
// Test of training
Ys=NbGmm.Predict(X);
// Confusion matrix
Pds::Octave::Plot::ConfMatrix(CM.Data,NbGmm.GetLabel(),"testando.m","example_nbgmm_2d_ConfMatrix.png");
// Load new dataset Xt.
Pds::Matrix Min=X.MinInCols();
Pds::Matrix Max=X.MaxInCols();
Pds::Matrix X1=Pds::Matrix(100*L,1); X1.FillRandU(Min.Get(0),Max.Get(0));
Pds::Matrix X2=Pds::Matrix(100*L,1); X2.FillRandU(Min.Get(1),Max.Get(1));
X=Pds::MergeHor({X1,X2});
// Predict the datset Xt.
Ys=NbGmm.Predict(X);
// Print the result of classification.
Pds::Octave::Plot::ScatterX2DY(X,Ys,"testando3d.m","example_nbgmm_2d_class.png");
NbGmm.ExportFile("salida.txt");
Pds::NBGMM NbGmm2("salida.txt");
NbGmm.Print("\n----- NBGMM2 :\n");
return 0;
}
La clase tipo Pds::ConfusionMatrix . Esta clase genera un bloque de datos para analizar curvas de apr...
La clase tipo Pds::IterationConf . Esta clase genera una matriz de Nlin lineas y 1 columna....
La clase tipo Pds::NBGMM . Esta clase genera una matriz de Nlin lineas y 1 columna....
Definition: NBGMM.hpp:65
static Pds::ConfusionMatrix Calculate(const Pds::Vector &Ypredict, const Pds::Vector &Yactual)
Crea un objeto Dat de tipo Pds::ConfusionMatrix.
void Print(std::string str="") const
Imprime en pantalla el contenido del NBGMM.
void LoadKGaussian(unsigned int L, unsigned int K, Pds::Matrix &X, Pds::Vector &Y, double factor=0.70711)
Clasificación múltiple de datos.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed