2 #define q_factor_val 2.0
5 namespace LogisticModel{
37 if(W.IsEmpty())
return Pds::Ra::Nan;
38 if(X.IsEmpty())
return Pds::Ra::Nan;
39 if(Y.IsEmpty())
return Pds::Ra::Nan;
41 if(X.Nlin()!=Y.Nlin())
return Pds::Ra::Nan;
42 if(X.Ncol()!=(W.Nlin()-1))
return Pds::Ra::Nan;
44 Pds::Vector Yh=Y.Geq(0.5);
49 unsigned int L=Yh.Nlin();
58 else E1=Pds::XqHb(N1/Na,q);
62 double P=(Np-N1)/(L-Na);
66 else E0=Pds::XqHb(P,q);
70 return (Na/L)*E1+((L-Na)/L)*E0;
79 if(W.IsEmpty())
return Pds::Vector();
80 if(X.IsEmpty())
return Pds::Vector();
81 if(Y.IsEmpty())
return Pds::Vector();
83 if(X.Nlin()!=Y.Nlin())
return Pds::Vector();
84 if(X.Ncol()!=(W.Nlin()-1))
return Pds::Vector();
86 if(h==0.0)
return Pds::Vector();
88 unsigned int N=W.Nel();
98 for(
unsigned int n=0;n<N;n++)
100 Whp.SetRaw(n,W.GetRaw(n)+h);
101 Whm.SetRaw(n,W.GetRaw(n)-h);
108 Whp.SetRaw(n,W.GetRaw(n));
109 Whm.SetRaw(n,W.GetRaw(n));
115 const Pds::Matrix &X,
116 const Pds::Vector &Y,
119 if(W.IsEmpty())
return Pds::Vector();
120 if(X.IsEmpty())
return Pds::Vector();
121 if(Y.IsEmpty())
return Pds::Vector();
123 if(X.Nlin()!=Y.Nlin())
return Pds::Vector();
124 if(X.Ncol()!=(W.Nlin()-1))
return Pds::Vector();
126 Pds::Vector Yt=Y.Geq(0.5);
127 unsigned int N=Yt.Sum();
128 unsigned int L=Yt.Nel();
130 Pds::Matrix R=Pds::RegressorMatrix(X);
131 Pds::Vector z=Pds::Sigmoid(R*W);
132 Pds::Vector Dz=z.Product(1.0-z);
137 double p2=(N-N1)/(L-Na);
139 double h1=Pds::XqHb(p1,q);
140 double h2=Pds::XqHb(p2,q);
141 double Dh1=Pds::DXqHb(p1,q);
142 double Dh2=Pds::DXqHb(p2,q);
144 double factor1=-(-h1+h2+p1*Dh1-p2*Dh2)/L;
145 double factor2=-(-Dh1+Dh2)/L;
146 Pds::Vector Der= factor1*R.TMul(Dz)+factor2*R.TMul(Dz.Product(Yt));
Pds::Vector Classify(const Pds::Vector &W, const Pds::Matrix &X)
Calculo del resultado del clasificador.
Pds::Vector GradientCostXqEntropy(const Pds::Vector &W, const Pds::Matrix &X, const Pds::Vector &Y, double q, double h)
double CostXqEntropy(const Pds::Vector &W, const Pds::Matrix &X, const Pds::Vector &Y, double q)
Pds::Vector GradientCostXqEntropySoft(const Pds::Vector &W, const Pds::Matrix &X, const Pds::Vector &Y, double q)
Nombre de espacio para Pds (Procesamiento Digital de Senales)