Home | Develop | Download | Contact
example_pwc_2d.cpp

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

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

Para executar o programa:

./example_pwc_2d

Retornando por consola:

----- PWC :
Sinv[0]:
10.508259400698 1.2184910031121 
1.2184910031121 16.950516539257 
Sinv[1]:
14.255593224349  -2.9575614667343 
-2.9575614667343 4.809030544633   
Sinv[2]:
10.993362414067 3.253587669365  
3.253587669365  22.752640686429 
C[0]:
1.3644409888407     0.30865651107002    
0.54131182660107    0.44114495084899    
1.5324162542992     0.14380173219132    
0.97871457046996    -0.18576091033362   
1.3876975812547     0.070248649824618   
1.0203924581723     -0.0057782712383694 
1.1769301989566     -0.34171433422429   
1.1218514560964     -0.038982261037875  
0.8884985073224     -0.05565910359112   
1.2271749967129     0.09841290538946    
0.99857556456138    -0.23146236798853   
1.6598606670507     -0.02060121152307   
0.94371782045289    0.4284496938752     
0.50728372691774    -0.0194365378146    
1.0974957584231     0.029652671259746   
1.0968559693676     0.50113184761604    
C[1]:
-0.25961050691028 0.89053649663561  
-0.80480907844468 1.4915402321155   
-0.68898013757129 0.72699052315729  
-0.53245033420155 0.47112321672329  
-0.68995508901464 0.27050527200838  
-0.34656812351992 1.2482637053898   
-0.6976362185919  0.17714042700049  
-0.73318210830763 0.33102017885852  
-0.35647477595586 0.4584366859044   
-0.08392852260589 1.7417310159774   
-0.93210338819838 0.38977128216341  
-0.41643922216927 0.77156518615808  
-0.37870995455512 0.25172159025657  
-0.29111639115852 0.066746937314765 
0.010714904864282 0.90740411891361  
-0.89954897623521 0.38551771374969  
C[2]:
-0.66112560108544 -0.87049156907102 
-0.52804795228685 -0.8672966328694  
-0.43566909780379 -0.94980184776189 
-0.22716404986642 -0.67799560651687 
-0.79662600149394 -1.0408359836312  
-0.18486958217368 -1.0957016657007  
-0.63305696873477 -0.67890120414008 
-0.50055048658681 -0.86737494858135 
-1.3780148158635  -0.71760686635723 
-0.63498228834285 -0.99162653832398 
-0.71112857652456 -0.69221599100083 
-0.11936963729904 -0.89966246735625 
-0.5498631148545  -0.49879009427498 
-0.29457811015415 -1.0517252539927  
-0.59578615882064 -1.406338314246   
-0.90718771406244 -0.8225673771406  
Det[0]: 0.0056613695579741
Det[1]: 0.016720055638442
Det[2]: 0.0041746299085322
Label[0]:       0
Label[1]:       1
Label[2]:       2

----- PWC2 :
Sinv[0]:
10.508259400698 1.2184910031121 
1.2184910031121 16.950516539257 
Sinv[1]:
14.255593224349  -2.9575614667343 
-2.9575614667343 4.809030544633   
Sinv[2]:
10.993362414067 3.253587669365  
3.253587669365  22.752640686429 
C[0]:
1.3644409888407     0.30865651107002    
0.54131182660107    0.44114495084899    
1.5324162542992     0.14380173219132    
0.97871457046996    -0.18576091033362   
1.3876975812547     0.070248649824618   
1.0203924581723     -0.0057782712383694 
1.1769301989566     -0.34171433422429   
1.1218514560964     -0.038982261037875  
0.8884985073224     -0.05565910359112   
1.2271749967129     0.09841290538946    
0.99857556456138    -0.23146236798853   
1.6598606670507     -0.02060121152307   
0.94371782045289    0.4284496938752     
0.50728372691774    -0.0194365378146    
1.0974957584231     0.029652671259746   
1.0968559693676     0.50113184761604    
C[1]:
-0.25961050691028 0.89053649663561  
-0.80480907844468 1.4915402321155   
-0.68898013757129 0.72699052315729  
-0.53245033420155 0.47112321672329  
-0.68995508901464 0.27050527200838  
-0.34656812351992 1.2482637053898   
-0.6976362185919  0.17714042700049  
-0.73318210830763 0.33102017885852  
-0.35647477595586 0.4584366859044   
-0.08392852260589 1.7417310159774   
-0.93210338819838 0.38977128216341  
-0.41643922216927 0.77156518615808  
-0.37870995455512 0.25172159025657  
-0.29111639115852 0.066746937314765 
0.010714904864282 0.90740411891361  
-0.89954897623521 0.38551771374969  
C[2]:
-0.66112560108544 -0.87049156907102 
-0.52804795228685 -0.8672966328694  
-0.43566909780379 -0.94980184776189 
-0.22716404986642 -0.67799560651687 
-0.79662600149394 -1.0408359836312  
-0.18486958217368 -1.0957016657007  
-0.63305696873477 -0.67890120414008 
-0.50055048658681 -0.86737494858135 
-1.3780148158635  -0.71760686635723 
-0.63498228834285 -0.99162653832398 
-0.71112857652456 -0.69221599100083 
-0.11936963729904 -0.89966246735625 
-0.5498631148545  -0.49879009427498 
-0.29457811015415 -1.0517252539927  
-0.59578615882064 -1.406338314246   
-0.90718771406244 -0.8225673771406  
Det[0]: 0.0056613695579741
Det[1]: 0.016720055638442
Det[2]: 0.0041746299085322
Label[0]:       0
Label[1]:       1
Label[2]:       2

Tarining data:

Training data



Confusion matrix:

Confusion matrix



Decision boundaries:

Regions

Código example_pwc_2d.cpp:

#include <iostream>
#include <Pds/Ra>
#include <Pds/Ml>
int main(void)
{
unsigned int L=16;
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_pwc_2d_data.png");
// Calculate the Pwc classifier.
Pds::PWC Pwc(X,Y);
Pwc.Print("----- PWC :\n");
// Test of training
Ys=Pwc.Predict(X,0.5);
// Confusion matrix
Pds::Octave::Plot::ConfMatrix(CM.Data,Pwc.GetLabel(),"testando.m","example_pwc_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=Pwc.Predict(X,0.5);
// Print the result of classification.
Pds::Octave::Plot::ScatterX2DY(X,Ys,"testando3d.m","example_pwc_2d_class.png");
Pwc.ExportFile("salida.txt");
Pds::PWC Pwc2("salida.txt");
Pwc.Print("----- PWC2 :\n");
return 0;
}
La clase tipo Pds::ConfusionMatrix . Esta clase genera un bloque de datos para analizar curvas de apr...
La clase tipo Pds::PWC . Esta clase genera una matriz de Nlin lineas y 1 columna. Para usar incluir P...
Definition: PWC.hpp:63
static Pds::ConfusionMatrix Calculate(const Pds::Vector &Ypredict, const Pds::Vector &Yactual)
Crea un objeto Dat de tipo Pds::ConfusionMatrix.
std::vector< int > GetLabel(void) const
Retorna un std::vector de vectores que representan las etiquetas para cada ID.
bool ExportFile(const std::string &filename) const
Salva en formato .txt el objeto de tipo Pds::PWC.
void Print(std::string str="") const
Imprime en pantalla el contenido del PWC.
double Predict(const Pds::Vector &x, double h=0.1) const
Evalua el objeto de tipo Pds::PWC.
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