11 static double Inv(
const double& x){
IAssert(x!=0.0);
return (1.0/x);}
12 static double Sqr(
const double& x){
return x*x;}
13 static double Sqrt(
const double& x){
IAssert(!(x<0.0));
return sqrt(x);}
14 static double Log(
const double& Val){
return log(Val);}
15 static double Log2(
const double& Val){
return log(Val)/
LogOf2;}
16 static double Round(
const double& Val){
17 return (Val>0)?floor(Val+0.5):ceil(Val-0.5);}
18 static double Round(
const double & Val,
int Decs){
19 const double pwr=pow(10.0, Decs);
return Round(Val * pwr) / pwr;}
20 static int Fac(
const int& Val){
21 if (Val<=1){
return 1;}
else {
return Val*
Fac(Val-1);}}
22 static int Choose(
const int& N,
const int& K){
25 static double Power(
const double& Base,
const double& Exponent){
26 return exp(log(Base)*Exponent);}
29 static int Sign(
const T& Val){
return Val<0?-1:(Val>0?1:0);}
32 static const T&
Mx(
const T& LVal,
const T& RVal) {
33 return LVal > RVal ? LVal : RVal;}
36 static const T&
Mn(
const T& LVal,
const T& RVal){
37 return LVal < RVal ? LVal : RVal;}
40 static const T&
Mx(
const T& Val1,
const T& Val2,
const T& Val3) {
42 if (Val1 > Val3)
return Val1;
45 if (Val2 > Val3)
return Val2;
51 static const T&
Mn(
const T& Val1,
const T& Val2,
const T& Val3) {
53 if (Val1 < Val3)
return Val1;
56 if (Val2 < Val3)
return Val2;
62 static const T&
Median(
const T& Val1,
const T& Val2,
const T& Val3) {
64 if (Val2 < Val3)
return Val2;
65 else if (Val3 < Val1)
return Val1;
68 if (Val1 < Val3)
return Val1;
69 else if (Val3 < Val2)
return Val2;
75 static const T&
InRange(
const T& Val,
const T&
Mn,
const T&
Mx) {
76 IAssert(Mn <= Mx);
return Val < Mn ? Mn : (Val > Mx ? Mx : Val);}
80 IAssert(Mn <= Mx);
return Val >= Mn && Val <=
Mx;}
83 static bool IsInEps(
const T& Val,
const T& Eps) {
84 return Val >= -Eps && Val <= Eps;}
92 double& gamser,
const double& a,
const double& x,
double& gln);
94 double& gammcf,
const double& a,
const double& x,
double& gln);
95 static double GammaQ(
const double& a,
const double& x);
96 static double LnGamma(
const double& xx);
98 const double& a,
const double& b,
const double& x);
99 static double BetaI(
const double& a,
const double& b,
const double& x);
103 double& SigA,
double& SigB,
double& Chi2,
double& R2);
106 double& SigA,
double& SigB,
double& Chi2,
double& R2);
109 double& SigA,
double& SigB,
double& Chi2,
double& R2);
112 double& SigA,
double& SigB,
double& Chi2,
double& R2);
114 static double LnComb(
const int& n,
const int& k);
145 DefP(false), ValWgtV(),
146 SumW(), ValSumW(), Vals(),
147 UsableP(false), UnusableVal(-1),
149 Mean(), Vari(), SDev(), SErr(),
150 Median(), Quart1(), Quart3(), Mode(),
151 DecileV(), PercentileV(){}
153 DefP(Mom.DefP), ValWgtV(Mom.ValWgtV),
154 SumW(Mom.SumW), ValSumW(Mom.ValSumW), Vals(Mom.Vals),
155 UsableP(Mom.UsableP), UnusableVal(Mom.UnusableVal),
156 Mn(Mom.Mn), Mx(Mom.Mx),
157 Mean(Mom.Mean), Vari(Mom.Vari), SDev(Mom.SDev), SErr(Mom.SErr),
158 Median(Mom.Median), Quart1(Mom.Quart1), Quart3(Mom.Quart3), Mode(Mom.Mode),
159 DecileV(Mom.DecileV), PercentileV(Mom.PercentileV){}
162 MomV.
Gen(Moms);
for (
int MomN=0; MomN<Moms; MomN++){MomV[MomN]=New();}}
164 MomVV.
Gen(XMoms, YMoms);
165 for (
int XMomN=0; XMomN<XMoms; XMomN++){
166 for (
int YMomN=0; YMomN<YMoms; YMomN++){
167 MomVV.
At(XMomN, YMomN)=New();}}}
174 SumW(SIn), ValSumW(SIn), Vals(SIn),
175 UsableP(SIn), UnusableVal(SIn),
177 Mean(SIn), Vari(SIn), SDev(SIn), SErr(SIn),
178 Median(SIn), Quart1(SIn), Quart3(SIn), Mode(SIn),
179 DecileV(SIn), PercentileV(SIn){}
184 SumW.Save(SOut); ValSumW.Save(SOut); Vals.Save(SOut);
185 UsableP.Save(SOut); UnusableVal.Save(SOut);
186 Mn.Save(SOut); Mx.Save(SOut);
187 Mean.Save(SOut); Vari.Save(SOut); SDev.Save(SOut); SErr.Save(SOut);
188 Median.Save(SOut); Quart1.Save(SOut); Quart3.Save(SOut); Mode.Save(SOut);
189 DecileV.Save(SOut); PercentileV.Save(SOut);}
196 Mn=Mom.
Mn; Mx=Mom.
Mx;
202 return Vals==Mom.
Vals;}
204 return Vals<Mom.
Vals;}
209 for (
int MomN=0; MomN<MomV.
Len(); MomN++){MomV[MomN]->Def();}}
211 for (
int XMomN=0; XMomN<MomVV.
GetXDim(); XMomN++){
212 for (
int YMomN=0; YMomN<MomVV.
GetYDim(); YMomN++){
213 MomVV.
At(XMomN, YMomN)->Def();}}}
218 ValWgtV.Add(
TFltPr(Val, Wgt)); SumW+=Wgt; ValSumW+=Wgt*Val; Vals++;}
227 for (
int MomN=0; MomN<MomV.
Len(); MomN++){
228 if (!MomV[MomN]->IsUsable()){
return false;}}
231 for (
int XMomN=0; XMomN<MomVV.
GetXDim(); XMomN++){
232 for (
int YMomN=0; YMomN<MomVV.
GetYDim(); YMomN++){
233 if (!MomVV.
At(XMomN, YMomN)->IsUsable()){
return false;}}}
249 Assert(DefP&&UsableP);
return DecileV[DecileN];}
251 Assert(DefP&&UsableP);
return PercentileV[PercentileN];}
252 double GetByNm(
const TStr& MomNm)
const;
253 TStr GetStrByNm(
const TStr& MomNm,
char* FmtStr=NULL)
const;
256 TStr GetStr(
const char& SepCh=
' ',
const char& DelimCh=
':',
257 const bool& DecileP=
true,
const bool& PercentileP=
true,
const TStr& FmtStr=
"%g")
const;
258 static TStr GetNmVStr(
const TStr& VarPfx,
259 const char& SepCh=
'\t',
const bool& DecileP=
true,
const bool& PercentileP=
true);
260 TStr GetValVStr(
const char& SepCh=
'\t',
const bool& DecileP=
true,
const bool& PercentileP=
true)
const;
296 static void AveVar(
const TFltV& ValV,
double& Ave,
double& Var);
297 static double KsProb(
const double& Alam);
300 const TFltV& ObservedBinV,
const TFltV& ExpectedBinV,
301 double& ChiSquareVal,
double& SignificancePrb);
303 const TFltV& ObservedBin1V,
const TFltV& ObservedBin2V,
304 double& ChiSquareVal,
double& SignificancePrb);
307 const TFltV& ValV1,
const TFltV& ValV2,
double& TTestVal,
double& TTestPrb);
310 static void KsTest(
const TFltV& ValV1,
const TFltV& ValV2,
double& DStat,
double& PVal);
311 static void KsTest(
const TFltPrV& ValCntV1,
const TFltPrV& ValCntV2,
double& DStat,
double& PVal);
323 TComb(): Items(-1), Order(-1), CombN(-1), ItemV(){}
324 TComb(
const int& _Items,
const int& _Order):
325 Items(_Items), Order(_Order), CombN(0), ItemV(){
326 IAssert((Order>0)&&(Order<=Items));}
327 static PComb New(
const int& Items,
const int& Order){
339 int GetCombs()
const;
354 void GetXV(const
int RecN,
TFltV& VarV)
const {
356 for (
int VarN=0; VarN<Vars; VarN++){VarV[VarN+1]=XVV.
At(RecN-1, VarN);}
358 double GetY(
const int RecN)
const {
return YV[RecN-1];}
359 double GetSig(
const int RecN)
const {
return SigV[RecN-1];}
360 void NR_covsrt(
TFltVV& CovarVV,
const int& Vars,
const TIntV& ia,
const int& mfit);
361 void NR_gaussj(
TFltVV& a,
const int& n,
TFltVV& b,
const int& m);
377 double GetCf(
const int& VarN)
const {
return CfV[VarN+1];}
379 return sqrt(
double(CovarVV.At(VarN+1, VarN+1)));}
380 double GetCovar(
const int& VarN1,
const int& VarN2)
const {
381 return CovarVV.At(VarN1+1, VarN2+1);}
385 static double LinInterp(
const double& x1,
const double& y1,
386 const double& x2,
const double& y2,
const double& AtX)
_CMPWARN{
387 if (x1 == x2)
return (y1+y2)/2.0;
388 const double k = (y2 - y1) / (x2 - x1);
389 return k*(AtX - x1) + y1;
406 void GetXV(const
int RecN,
TFltV& VarV)
const {
408 for (
int VarN=0; VarN<Vars; VarN++){VarV[VarN+1]=XVV.
At(RecN-1, VarN);}
410 double GetY(
const int RecN)
const {
return YV[RecN-1];}
411 double GetSig(
const int RecN)
const {
return SigV[RecN-1];}
412 static double NR_SIGN(
double a,
double b){
return b >= 0.0 ? fabs(a) : -fabs(a);}
413 static double NR_FMAX(
double maxarg1,
double maxarg2){
414 return maxarg1 > maxarg2 ? maxarg1 : maxarg2;}
415 static int NR_IMIN(
int iminarg1,
int iminarg2){
416 return iminarg1 < iminarg2 ? iminarg1 : iminarg2;}
417 static double NR_pythag(
double a,
double b);
437 double GetCf(
const int& VarN)
const {
return CfV[VarN+1];}
439 return sqrt(
double(CovarVV.At(VarN+1, VarN+1)));}
440 double GetCovar(
const int& VarN1,
const int& VarN2)
const {
441 return CovarVV.At(VarN1+1, VarN2+1);}
445 void GetCfV(
TFltV& _CfV);
446 void GetCfUncerV(
TFltV& CfUncerV);
465 THist(
const double& _MnVal,
const double& _MxVal,
const int& Buckets):
469 void Add(
const double& Val,
const bool& OnlyInP);
static const T & Mn(const T &LVal, const T &RVal)
static const T & Mn(const T &Val1, const T &Val2, const T &Val3)
static double LnGamma(const double &xx)
double GetCf(const int &VarN) const
static bool IsUsableVV(const TVVec< PMom > &MomVV)
double GetSig(const int RecN) const
static void NewV(TMomV &MomV, const int &Moms)
static PLinReg Load(TSIn &SIn)
double GetCovar(const int &VarN1, const int &VarN2) const
static const T & Mx(const T &LVal, const T &RVal)
static double KsProb(const double &Alam)
static void PowerFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
double GetCorrCfPrb() const
static void ExpFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
static int NR_IMIN(int iminarg1, int iminarg2)
TSizeTy Len() const
Returns the number of elements in the vector.
static void LogFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
double GetCovar(const int &VarN1, const int &VarN2) const
TComb & operator=(const TComb &)
static double Sqrt(const double &x)
THash< TInt, TMomV > TIntMomVH
static int Fac(const int &Val)
static double NR_FMAX(double maxarg1, double maxarg2)
double GetBucketMn(const int &BucketN) const
static void NewVV(TVVec< PMom > &MomVV, const int &XMoms, const int &YMoms)
static double Sqr(const double &x)
void Add(const double &Val, const bool &OnlyInP)
static bool IsInRange(const T &Val, const T &Mn, const T &Mx)
void SaveStat(const TStr &ValNm, TSOut &FOut) const
THist(const double &_MnVal, const double &_MxVal, const int &Buckets)
static int Choose(const int &N, const int &K)
static void DefV(TMomV &MomV)
static double Inv(const double &x)
TSvd & operator=(const TSvd &)
TLinReg & operator=(const TLinReg &)
static double GammaQ(const double &a, const double &x)
#define ClassTP(TNm, PNm)
static uint Pow2(const int &pow)
#define ClassTPV(TNm, PNm, TNmV)
static PMom New(const TFltV &ValV)
void Add(const TFlt &Val, const TFlt &Wgt=1)
static const T & Mx(const T &Val1, const T &Val2, const T &Val3)
double GetCfUncer(const int &VarN) const
static void EntropyFracDim(const TIntV &ValV, TFltV &EntropyV)
TCorr & operator=(const TCorr &)
static void ChiSquareTwo(const TFltV &ObservedBin1V, const TFltV &ObservedBin2V, double &ChiSquareVal, double &SignificancePrb)
static double Round(const double &Val)
bool operator<(const TMom &Mom) const
static double Power(const double &Base, const double &Exponent)
THash< TInt, PMom > TIntMomH
static bool IsUsableV(const TMomV &MomV)
static void ChiSquareOne(const TFltV &ObservedBinV, const TFltV &ExpectedBinV, double &ChiSquareVal, double &SignificancePrb)
static void AveVar(const TFltV &ValV, double &Ave, double &Var)
TPair< TFlt, TFlt > TFltPr
double GetPercentile(const int &PercentileN) const
static double Round(const double &Val, int Decs)
static double EntropyBias(const double &B)
static void KsTest(const TFltV &ValV1, const TFltV &ValV2, double &DStat, double &PVal)
static void GammaQContFrac(double &gammcf, const double &a, const double &x, double &gln)
static bool IsInEps(const T &Val, const T &Eps)
static double GetPowerCoef(const TFltV &XValV, double MinX=-1.0)
static double NR_SIGN(double a, double b)
static double BetaI(const double &a, const double &b, const double &x)
void SaveTxt(const TStr &ValNm, const TStr &FNm) const
static PSvd Load(TSIn &SIn)
void Save(TSOut &SOut) const
double GetBucketValPerc(const int &BucketN) const
static void TTest(const TFltV &ValV1, const TFltV &ValV2, double &TTestVal, double &TTestPrb)
static PMom Load(TSIn &SIn)
static int Sign(const T &Val)
static double LnComb(const int &n, const int &k)
static double Log2(const double &Val)
static void GammaPSeries(double &gamser, const double &a, const double &x, double &gln)
double GetY(const int RecN) const
THash< TInt, TMomVV > TIntMomVVH
static double Entropy(const TIntV &ValV)
double GetDecile(const int &DecileN) const
double GetCf(const int &VarN) const
static void LinearFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
static double Log(const double &Val)
static const T & Median(const T &Val1, const T &Val2, const T &Val3)
static const T & InRange(const T &Val, const T &Mn, const T &Mx)
bool operator==(const TMom &Mom) const
double GetBucketMx(const int &BucketN) const
static double LinInterp(const double &x1, const double &y1, const double &x2, const double &y2, const double &AtX) _CMPWARN
static PComb Load(TSIn &SIn)
double GetY(const int RecN) const
static PCorr Load(TSIn &SIn)
TFlt GetVal(const int &ValN) const
double GetSig(const int RecN) const
TComb(const int &_Items, const int &_Order)
static double BetaCf(const double &a, const double &b, const double &x)
TMom & operator=(const TMom &Mom)
static PComb New(const int &Items, const int &Order)
void Gen(const TSizeTy &_XDim, const TSizeTy &_YDim)
static void DefVV(TVVec< PMom > &MomVV)
static PCorr New(const TFltV &ValV1, const TFltV &ValV2)
int GetBucketVal(const int &BucketN) const
const TVal & At(const TSizeTy &X, const TSizeTy &Y) const
double GetCfUncer(const int &VarN) const