Home | Develop | Download | Contact
example_logisticregression_ig.cpp

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

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

Para executar o programa:

./example_logisticregression_ig

Retornando por consola:

    W_ig: 0.4812        0       -1
 Cost(W): 0.15893202856795

-------------------------
   IterationConf data    
-------------------------
    Alpha: 0.1
 MinError: 1e-07
  MaxIter: 1000
-------------------------
iter:   1000 Alpha: 0.020986616658128 last_error: 0.0074522609311292 
-------------------------
    Alpha: 0.020986616658128
LastError: 0.0074522609311292
 LastIter: 1000
-------------------------
    W_ig: -0.73261682797554     -0.63672966050461       2.1557255295481
 Cost(W): 0.30983446123018
Classification - data


Classification - ortogonal


Classification - gradient

Código example_logisticregression_ig.cpp:

#include <iostream>
#include <Pds/Ra>
#include <Pds/Ml>
int main(void)
{
Conf.Show=true; Conf.SetMinError(1e-07); Conf.SetAlpha(0.01); Conf.SetLambda(0.01); Conf.SetGamma(0.1);
Pds::Ra::Randomize();
// Generating data
//Pds::Matrix X(Pds::Ra::TextFormat,"../test/hard-data-x.txt");
//Pds::Vector Y(Pds::Ra::TextFormat,"../test/hard-data-y.txt");
unsigned int L=1000;
Pds::Matrix X;
Pds::Vector Y;
Pds::Octave::XLabel="x_1";
Pds::Octave::YLabel="x_2";
Pds::Octave::Plot::PointsX2DY(X,Y,"testando.m","example_logisticregression_ig_data.png");
Pds::Vector Yp;
Pds::Vector W;
// Create W using training data
// Método ortogonal
W.T().Print(" W_ig: ");
std::cout<< " Cost(W): "<<Pds::LogisticModel::CostInformationGain(W,X,Y)<<"\n\n";
Pds::Octave::Plot::PointsX2DY(X,Yp,"testando.m","example_logisticregression_ig_ortogonal.png");
// Método de gradiente
W.T().Print(" W_ig: ");
std::cout<< " Cost(W): "<<Pds::LogisticModel::CostInformationGain(W,X,Y)<<"\n";
Pds::Octave::Plot::PointsX2DY(X,Yp,"testando_gradient.m","example_logisticregression_ig_gradient.png");
return 0;
}
La clase tipo Pds::IterationConf . Esta clase genera una matriz de Nlin lineas y 1 columna....
bool SetLambda(double Lambda)
Coloca el valor lambda.
bool SetAlpha(double Alpha)
Coloca el valor alpha.
bool SetMinError(double MinError)
Coloca el valor MinError.
bool SetGamma(double Lambda)
Coloca el valor gamma.
void LoadDataBand(unsigned int L, Pds::Matrix &X, Pds::Vector &Y)
Clasificacion de datos separados por mas de una curva.
Pds::Vector FittingGradientIG(Pds::IterationConf &Conf, const Pds::Matrix &X, const Pds::Vector &Y, const Pds::Vector &W0)
Calculo de pesos.
double CostInformationGain(const Pds::Vector &W, const Pds::Matrix &X, const Pds::Vector &Y)
Calculo de costo.
Pds::Vector Classify(const Pds::Vector &W, const Pds::Matrix &X)
Calculo del resultado del clasificador.
Pds::Vector GetW0MeanMethod(const Pds::Matrix &X)
Obtiene de forma rapida un vector inicial para usar en regresion logistica.
Pds::Vector FittingOrtogonalIG(const Pds::Matrix &X, const Pds::Vector &Y, unsigned int MinID)
Calculo de pesos.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed