#include <linalg.h>
List of all members.
Public Member Functions |
| TSigmoid () |
| TSigmoid (const double &A_, const double &B_) |
| TSigmoid (const TFltIntKdV &data) |
| TSigmoid (TSIn &SIn) |
void | Load (TSIn &SIn) |
void | Save (TSOut &SOut) const |
double | GetVal (const double &x) const |
double | operator() (const double &x) const |
void | GetSigmoidAB (double &A_, double &B_) |
Static Private Member Functions |
static double | EvaluateFit (const TFltIntKdV &data, const double A, const double B) |
static void | EvaluateFit (const TFltIntKdV &data, const double A, const double B, double &J, double &JA, double &JB) |
static void | EvaluateFit (const TFltIntKdV &data, const double A, const double B, const double U, const double V, const double lambda, double &J, double &JJ, double &JJJ) |
Private Attributes |
TFlt | A |
TFlt | B |
Detailed Description
Definition at line 454 of file linalg.h.
Constructor & Destructor Documentation
Definition at line 1538 of file linalg.cpp.
{
double minProj = data[0].Key, maxProj = data[0].Key;
{for (int i = 1; i < data.Len(); i++) {
double zi = data[i].Key; if (zi < minProj) minProj = zi; if (zi > maxProj) maxProj = zi; }}
A = 1.0; B = 0.5 * (minProj + maxProj);
double bestJ = 0.0, bestA = 0.0, bestB = 0.0, lambda = 1.0;
for (int nIter = 0; nIter < 50; nIter++)
{
double J, JA, JB; TSigmoid::EvaluateFit(data, A, B, J, JA, JB);
if (nIter == 0 || J < bestJ) { bestJ = J; bestA = A; bestB = B; }
double norm = TMath::Sqr(JA) + TMath::Sqr(JB);
if (norm < 1e-10) break;
const int cl = -1;
double Jc = TSigmoid::EvaluateFit(data, A + cl * lambda * JA / norm, B + cl * lambda * JB / norm);
if (Jc > J) {
while (lambda > 1e-5) {
lambda = 0.5 * lambda;
Jc = TSigmoid::EvaluateFit(data, A + cl * lambda * JA / norm, B + cl * lambda * JB / norm);
} }
else if (Jc < J) {
while (lambda < 1e5) {
double lambda2 = 2 * lambda;
double Jc2 = TSigmoid::EvaluateFit(data, A + cl * lambda2 * JA / norm, B + cl * lambda2 * JB / norm);
if (Jc2 > Jc) break;
lambda = lambda2; Jc = Jc2; } }
if (Jc >= J) break;
A += cl * lambda * JA / norm; B += cl * lambda * JB / norm;
}
A = bestA; B = bestB;
}
Member Function Documentation
Definition at line 1480 of file linalg.cpp.
{
double J = 0.0;
for (int i = 0; i < data.Len(); i++)
{
double zi = data[i].Key; int yi = data[i].Dat;
double e = exp(-A * zi + B);
double denum = 1.0 + e;
double prob = (yi > 0) ? (1.0 / denum) : (e / denum);
J -= log(prob < 1e-20 ? 1e-20 : prob);
}
return J;
}
Definition at line 1494 of file linalg.cpp.
{
J = 0.0; double sum_all_PyNeg = 0.0, sum_all_ziPyNeg = 0.0, sum_yNeg_zi = 0.0, sum_yNeg_1 = 0.0;
for (int i = 0; i < data.Len(); i++)
{
double zi = data[i].Key; int yi = data[i].Dat;
double e = exp(-A * zi + B);
double denum = 1.0 + e;
double prob = (yi > 0) ? (1.0 / denum) : (e / denum);
J -= log(prob < 1e-20 ? 1e-20 : prob);
sum_all_PyNeg += e / denum;
sum_all_ziPyNeg += zi * e / denum;
if (yi < 0) { sum_yNeg_zi += zi; sum_yNeg_1 += 1; }
}
JA = -sum_all_ziPyNeg + sum_yNeg_zi;
JB = sum_all_PyNeg - sum_yNeg_1;
}
void TSigmoid::EvaluateFit |
( |
const TFltIntKdV & |
data, |
|
|
const double |
A, |
|
|
const double |
B, |
|
|
const double |
U, |
|
|
const double |
V, |
|
|
const double |
lambda, |
|
|
double & |
J, |
|
|
double & |
JJ, |
|
|
double & |
JJJ |
|
) |
| [static, private] |
Definition at line 1516 of file linalg.cpp.
{
J = 0.0; JJ = 0.0; JJJ = 0.0;
for (int i = 0; i < data.Len(); i++)
{
double zi = data[i].Key; int yi = data[i].Dat;
double e = exp(-A * zi + B);
double denum = 1.0 + e;
double prob = (yi > 0) ? (1.0 / denum) : (e / denum);
J -= log(prob < 1e-20 ? 1e-20 : prob);
double VU = V - U * zi;
JJ += VU * (e / denum); if (yi < 0) JJ -= VU;
JJJ += VU * VU * e / denum / denum;
}
}
Definition at line 484 of file linalg.h.
{
return 1.0 / (1.0 + exp(-A * x + B)); }
double TSigmoid::operator() |
( |
const double & |
x | ) |
const [inline] |
Member Data Documentation
The documentation for this class was generated from the following files: