SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
xmath.h
Go to the documentation of this file.
1 #include "bd.h"
2 
4 // Mathematics-Utilities
5 class TMath{
6 public:
7  static double E;
8  static double Pi;
9  static double LogOf2;
10 
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){ // binomial coefficient
23  return Fac(N)/(Fac(K)*Fac(N-K)); }
24  static uint Pow2(const int& pow){return uint(1u<<pow);}
25  static double Power(const double& Base, const double& Exponent){
26  return exp(log(Base)*Exponent);}
27 
28  template <typename T>
29  static int Sign(const T& Val){return Val<0?-1:(Val>0?1:0);}
30 
31  template <class T>
32  static const T& Mx(const T& LVal, const T& RVal) {
33  return LVal > RVal ? LVal : RVal;}
34 
35  template <class T>
36  static const T& Mn(const T& LVal, const T& RVal){
37  return LVal < RVal ? LVal : RVal;}
38 
39  template <class T>
40  static const T& Mx(const T& Val1, const T& Val2, const T& Val3) {
41  if (Val1 > Val2) {
42  if (Val1 > Val3) return Val1;
43  else return Val3;
44  } else {
45  if (Val2 > Val3) return Val2;
46  else return Val3;
47  }
48  }
49 
50  template <class T>
51  static const T& Mn(const T& Val1, const T& Val2, const T& Val3) {
52  if(Val1 < Val2) {
53  if (Val1 < Val3) return Val1;
54  else return Val3;
55  } else {
56  if (Val2 < Val3) return Val2;
57  else return Val3;
58  }
59  }
60 
61  template <class T>
62  static const T& Median(const T& Val1, const T& Val2, const T& Val3) {
63  if (Val1 < Val2) {
64  if (Val2 < Val3) return Val2;
65  else if (Val3 < Val1) return Val1;
66  else return Val3;
67  } else {
68  if (Val1 < Val3) return Val1;
69  else if (Val3 < Val2) return Val2;
70  else return Val3;
71  }
72  }
73 
74  template <class T>
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);}
77 
78  template <class T>
79  static bool IsInRange(const T& Val, const T& Mn, const T& Mx) {
80  IAssert(Mn <= Mx); return Val >= Mn && Val <= Mx;}
81 
82  template <class T>
83  static bool IsInEps(const T& Val, const T& Eps) {
84  return Val >= -Eps && Val <= Eps;}
85 };
86 
88 // Special-Functions
89 class TSpecFunc{
90 public:
91  static void GammaPSeries/*gser*/(
92  double& gamser, const double& a, const double& x, double& gln);
93  static void GammaQContFrac/*gcf*/(
94  double& gammcf, const double& a, const double& x, double& gln);
95  static double GammaQ/*gammq*/(const double& a, const double& x);
96  static double LnGamma/*gammln*/(const double& xx);
97  static double BetaCf/*betacf*/(
98  const double& a, const double& b, const double& x);
99  static double BetaI(const double& a, const double& b, const double& x);
100 
101  static void LinearFit( // Y = A + B*X
102  const TVec<TFltPr>& XY, double& A, double& B,
103  double& SigA, double& SigB, double& Chi2, double& R2);
104  static void PowerFit( // Y = A * X^B
105  const TVec<TFltPr>& XY, double& A, double& B,
106  double& SigA, double& SigB, double& Chi2, double& R2);
107  static void LogFit( // Y = A + B*log(X)
108  const TVec<TFltPr>& XY, double& A, double& B,
109  double& SigA, double& SigB, double& Chi2, double& R2);
110  static void ExpFit( // Y = A * exp(B*X)
111  const TVec<TFltPr>& XY, double& A, double& B,
112  double& SigA, double& SigB, double& Chi2, double& R2);
113 public:
114  static double LnComb(const int& n, const int& k);
115 public:
116  static double Entropy(const TIntV& ValV);
117  static double Entropy(const TFltV& ValV);
118  static void EntropyFracDim(const TIntV& ValV, TFltV& EntropyV);
119  static void EntropyFracDim(const TFltV& ValV, TFltV& EntropyV);
120 public:
121  static double EntropyBias(const double& B); // solves for p: B = p*log2(p)+(1-p)log2(1-p)
122  //MLE of the power-law coefficient
123  static double GetPowerCoef(const TFltV& XValV, double MinX=-1.0); // values (sampled from the distribution)
124  static double GetPowerCoef(const TFltPrV& XValCntV, double MinX=-1.0); // (value, count) pairs
125 };
126 
128 // Statistical-Moments
130 private:
131  TBool DefP;
132  TFltPrV ValWgtV;
133  TFlt SumW, ValSumW;
134  TInt Vals;
135  TBool UsableP;
136  TFlt UnusableVal;
137  TFlt Mn, Mx;
138  TFlt Mean, Vari, SDev, SErr;
139  TFlt Median, Quart1, Quart3;
140  TFlt Mode;
141  TFltV DecileV; // 0=min 1=1.decile, ..., 9=9.decile, 10=max
142  TFltV PercentileV; // 0=min 1=1.percentile, ..., 9=9.percentile, 10=max
143 public:
144  TMom():
145  DefP(false), ValWgtV(),
146  SumW(), ValSumW(), Vals(),
147  UsableP(false), UnusableVal(-1),
148  Mn(), Mx(),
149  Mean(), Vari(), SDev(), SErr(),
150  Median(), Quart1(), Quart3(), Mode(),
151  DecileV(), PercentileV(){}
152  TMom(const TMom& Mom):
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){}
160  static PMom New(){return PMom(new TMom());}
161  static void NewV(TMomV& MomV, const int& Moms){
162  MomV.Gen(Moms); for (int MomN=0; MomN<Moms; MomN++){MomV[MomN]=New();}}
163  static void NewVV(TVVec<PMom>& MomVV, const int& XMoms, const int& YMoms){
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();}}}
168  TMom(const TFltV& _ValV);
169  static PMom New(const TFltV& ValV){
170  return PMom(new TMom(ValV));}
171  TMom(TSIn& SIn):
172  DefP(SIn),
173  ValWgtV(SIn),
174  SumW(SIn), ValSumW(SIn), Vals(SIn),
175  UsableP(SIn), UnusableVal(SIn),
176  Mn(SIn), Mx(SIn),
177  Mean(SIn), Vari(SIn), SDev(SIn), SErr(SIn),
178  Median(SIn), Quart1(SIn), Quart3(SIn), Mode(SIn),
179  DecileV(SIn), PercentileV(SIn){}
180  static PMom Load(TSIn& SIn){return new TMom(SIn);}
181  void Save(TSOut& SOut) const {
182  DefP.Save(SOut);
183  ValWgtV.Save(SOut);
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);}
190 
191  TMom& operator=(const TMom& Mom){
192  Assert(!DefP); DefP=Mom.DefP;
193  ValWgtV=Mom.ValWgtV;
194  SumW=Mom.SumW; ValSumW=Mom.ValSumW; Vals=Mom.Vals;
195  UsableP=Mom.UsableP; UnusableVal=Mom.UnusableVal;
196  Mn=Mom.Mn; Mx=Mom.Mx;
197  Mean=Mom.Mean; Vari=Mom.Vari; SDev=Mom.SDev; SErr=Mom.SErr;
198  Median=Mom.Median; Quart1=Mom.Quart1; Quart3=Mom.Quart3; Mode=Mom.Mode;
199  DecileV=Mom.DecileV; PercentileV=Mom.PercentileV;
200  return *this;}
201  bool operator==(const TMom& Mom) const {
202  return Vals==Mom.Vals;}
203  bool operator<(const TMom& Mom) const {
204  return Vals<Mom.Vals;}
205 
206  // define
207  void Def();
208  static void DefV(TMomV& MomV){
209  for (int MomN=0; MomN<MomV.Len(); MomN++){MomV[MomN]->Def();}}
210  static void DefVV(TVVec<PMom>& MomVV){
211  for (int XMomN=0; XMomN<MomVV.GetXDim(); XMomN++){
212  for (int YMomN=0; YMomN<MomVV.GetYDim(); YMomN++){
213  MomVV.At(XMomN, YMomN)->Def();}}}
214  bool IsDef() const {return DefP;}
215 
216  // values
217  void Add(const TFlt& Val, const TFlt& Wgt=1){Assert(!DefP);
218  ValWgtV.Add(TFltPr(Val, Wgt)); SumW+=Wgt; ValSumW+=Wgt*Val; Vals++;}
219  double GetWgt() const {return SumW;}
220  int GetVals() const {return Vals;}
221  TFlt GetVal(const int& ValN) const {IAssert(!IsDef()); return ValWgtV[ValN].Val1;}
222  //const TFltV& GetValV() const {IAssert(!IsDef()); return ValV;} //J:
223 
224  // usability
225  bool IsUsable() const {Assert(DefP); return UsableP;}
226  static bool IsUsableV(const TMomV& MomV){
227  for (int MomN=0; MomN<MomV.Len(); MomN++){
228  if (!MomV[MomN]->IsUsable()){return false;}}
229  return true;}
230  static bool IsUsableVV(const TVVec<PMom>& MomVV){
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;}}}
234  return true;}
235 
236  // moments
237  double GetMn() const {Assert(DefP&&UsableP); return Mn;}
238  double GetMx() const {Assert(DefP&&UsableP); return Mx;}
239  double GetExtent() const {Assert(DefP&&UsableP); return Mx-Mn;}
240  double GetMean() const {Assert(DefP&&UsableP); return Mean;}
241  double GetVari() const {Assert(DefP&&UsableP); return Vari;}
242  double GetSDev() const {Assert(DefP&&UsableP); return SDev;}
243  double GetSErr() const {Assert(DefP&&UsableP); return SErr;}
244  double GetMedian() const {Assert(DefP&&UsableP); return Median;}
245  double GetQuart1() const {Assert(DefP&&UsableP); return Quart1;}
246  double GetQuart3() const {Assert(DefP&&UsableP); return Quart3;}
247  double GetMode() const {Assert(DefP&&UsableP); return Mode;}
248  double GetDecile(const int& DecileN) const {
249  Assert(DefP&&UsableP); return DecileV[DecileN];}
250  double GetPercentile(const int& PercentileN) const {
251  Assert(DefP&&UsableP); return PercentileV[PercentileN];}
252  double GetByNm(const TStr& MomNm) const;
253  TStr GetStrByNm(const TStr& MomNm, char* FmtStr=NULL) const;
254 
255  // strings
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;
261 };
266 
268 // Correlation
270 private:
271  int ValVLen;
272  double CorrCf;
273  double CorrCfPrb;
274  double FisherZ;
275 public:
276  TCorr(){}
277  TCorr(const TFltV& ValV1, const TFltV& ValV2);
278  static PCorr New(const TFltV& ValV1, const TFltV& ValV2){
279  return PCorr(new TCorr(ValV1, ValV2));}
281  static PCorr Load(TSIn& SIn){return new TCorr(SIn);}
282  void Save(TSOut&){Fail;}
283 
284  TCorr& operator=(const TCorr&){Fail; return *this;}
285 
286  double GetCorrCf() const {return CorrCf;}
287  double GetCorrCfPrb() const {return CorrCfPrb;}
288 
289  TStr GetStr() const;
290 };
291 
293 // Statistical Tests
294 class TStatTest {
295 private:
296  static void AveVar(const TFltV& ValV, double& Ave, double& Var);
297  static double KsProb(const double& Alam);
298 public:
299  static void ChiSquareOne(
300  const TFltV& ObservedBinV, const TFltV& ExpectedBinV,
301  double& ChiSquareVal, double& SignificancePrb);
302  static void ChiSquareTwo(
303  const TFltV& ObservedBin1V, const TFltV& ObservedBin2V,
304  double& ChiSquareVal, double& SignificancePrb);
305 
306  static void TTest(
307  const TFltV& ValV1, const TFltV& ValV2, double& TTestVal, double& TTestPrb);
308 
309  // Kolmogorov-Smirnov (are two distributions the same)
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);
312 };
313 
315 // Combinations
317 public:
318  int Items;
319  int Order;
320  int CombN;
321  TIntV ItemV;
322 public:
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){
328  return PComb(new TComb(Items, Order));}
329  ~TComb(){}
331  static PComb Load(TSIn& SIn){return new TComb(SIn);}
332  void Save(TSOut&){Fail;}
333 
334  TComb& operator=(const TComb&){Fail; return *this;}
335 
336  bool GetNext();
337  TIntV& GetItemV(){return ItemV;}
338  int GetCombN() const {return CombN;}
339  int GetCombs() const;
340  void Wr();
341 };
342 
344 // Linear-Regression
346 public:
347  TFltVV XVV;
348  TFltV YV;
349  TFltV SigV;
350  int Recs, Vars;
351  TFltVV CovarVV; // 1 based
352  TFltV CfV; // 1 based
353  double ChiSq;
354  void GetXV(const int RecN, TFltV& VarV) const {
355  VarV.Gen(Vars+1);
356  for (int VarN=0; VarN<Vars; VarN++){VarV[VarN+1]=XVV.At(RecN-1, VarN);}
357  }
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);
362  void NR_lfit();
363 public:
365  static PLinReg New(
366  const TFltVV& XVV, const TFltV& YV, const TFltV& SigV=TFltV());
369  static PLinReg Load(TSIn& SIn){return new TLinReg(SIn);}
370  void Save(TSOut&){Fail;}
371 
372  TLinReg& operator=(const TLinReg&){Fail; return *this;}
373 
374  int GetRecs() const {return Recs;}
375  int GetVars() const {return Vars;}
376 
377  double GetCf(const int& VarN) const {return CfV[VarN+1];}
378  double GetCfUncer(const int& VarN) const {
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);}
382 
383  double GetChiSq() const {return ChiSq;}
384 
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;
390  }
391 
392  void Wr() const;
393 };
394 
396 // Singular-Value-Decomposition
398 public:
399  TFltVV XVV;
400  TFltV YV;
401  TFltV SigV;
402  int Recs, Vars;
403  TFltVV CovarVV; // 1 based
404  TFltV CfV; // 1 based
405  double ChiSq;
406  void GetXV(const int RecN, TFltV& VarV) const {
407  VarV.Gen(Vars+1);
408  for (int VarN=0; VarN<Vars; VarN++){VarV[VarN+1]=XVV.At(RecN-1, VarN);}
409  }
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);
418  static void NR_svdcmp(TFltVV& a, int m, int n, TFltV& w, TFltVV& v);
419  void NR_svbksb(
420  TFltVV& u, TFltV& w, TFltVV& v, int m, int n, TFltV& b, TFltV& x);
421  void NR_svdvar(TFltVV& v, int ma, TFltV& w, TFltVV& cvm);
422  void NR_svdfit();
423 public:
424  TSvd(){}
425  static PSvd New(
426  const TFltVV& XVV, const TFltV& YV, const TFltV& SigV=TFltV());
427  ~TSvd(){}
429  static PSvd Load(TSIn& SIn){return new TSvd(SIn);}
430  void Save(TSOut&){Fail;}
431 
432  TSvd& operator=(const TSvd&){Fail; return *this;}
433 
434  int GetRecs() const {return Recs;}
435  int GetVars() const {return Vars;}
436 
437  double GetCf(const int& VarN) const {return CfV[VarN+1];}
438  double GetCfUncer(const int& VarN) const {
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);}
442 
443  double GetChiSq() const {return ChiSq;}
444 
445  void GetCfV(TFltV& _CfV);
446  void GetCfUncerV(TFltV& CfUncerV);
447 
448  static void Svd(const TFltVV& InMtx, TFltVV& LSingV, TFltV& SingValV, TFltVV& RSingV);
449  static void Svd1Based(const TFltVV& InMtx1, TFltVV& LSingV, TFltV& SingValV, TFltVV& RSingV);
450 
451  void Wr() const;
452 };
453 
455 // Histogram
456 class THist {
457 private:
463 public:
464  THist() { }
465  THist(const double& _MnVal, const double& _MxVal, const int& Buckets):
466  MnVal(_MnVal), MxVal(_MxVal), BucketV(Buckets) {
467  BucketSize = (MxVal == MnVal) ? 1.0 : (1.01 * double(MxVal - MnVal) / double(Buckets)); }
468 
469  void Add(const double& Val, const bool& OnlyInP);
470 
471  int GetVals() const { return Vals; }
472  int GetBuckets() const { return BucketV.Len(); }
473  double GetBucketMn(const int& BucketN) const { return MnVal + BucketN * BucketSize; }
474  double GetBucketMx(const int& BucketN) const { return MnVal + (BucketN + 1) * BucketSize; }
475  int GetBucketVal(const int& BucketN) const { return BucketV[BucketN]; }
476  double GetBucketValPerc(const int& BucketN) const {
477  return (Vals > 0) ? (double(BucketV[BucketN]) / double(Vals)) : 0.0; }
478 
479  void SaveStat(const TStr& ValNm, TSOut& FOut) const;
480  void SaveTxt(const TStr& ValNm, const TStr& FNm) const {
481  TFOut FOut(FNm); SaveStat(ValNm, FOut); }
482 };
void Save(TSOut &)
Definition: xmath.h:430
#define IAssert(Cond)
Definition: bd.h:262
static const T & Mn(const T &LVal, const T &RVal)
Definition: xmath.h:36
static const T & Mn(const T &Val1, const T &Val2, const T &Val3)
Definition: xmath.h:51
TFlt SDev
Definition: xmath.h:138
TBool UsableP
Definition: xmath.h:135
static double LnGamma(const double &xx)
Definition: xmath.cpp:80
double GetCf(const int &VarN) const
Definition: xmath.h:377
double GetWgt() const
Definition: xmath.h:219
static bool IsUsableVV(const TVVec< PMom > &MomVV)
Definition: xmath.h:230
double GetMedian() const
Definition: xmath.h:244
TFlt MxVal
Definition: xmath.h:459
double GetSig(const int RecN) const
Definition: xmath.h:359
static void NewV(TMomV &MomV, const int &Moms)
Definition: xmath.h:161
static PLinReg Load(TSIn &SIn)
Definition: xmath.h:369
double GetCovar(const int &VarN1, const int &VarN2) const
Definition: xmath.h:440
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
TLinReg(TSIn &)
Definition: xmath.h:368
TInt Vals
Definition: xmath.h:462
static double KsProb(const double &Alam)
Definition: xmath.cpp:605
static void PowerFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
Definition: xmath.cpp:193
int GetVals() const
Definition: xmath.h:220
unsigned int uint
Definition: bd.h:11
bool IsDef() const
Definition: xmath.h:214
void Save(TSOut &)
Definition: xmath.h:282
#define Fail
Definition: bd.h:238
double GetExtent() const
Definition: xmath.h:239
double GetCorrCfPrb() const
Definition: xmath.h:287
Definition: xmath.h:456
static void ExpFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
Definition: xmath.cpp:218
static int NR_IMIN(int iminarg1, int iminarg2)
Definition: xmath.h:415
Definition: fl.h:319
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TFlt Mx
Definition: xmath.h:137
void Save(TSOut &)
Definition: xmath.h:370
static void LogFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
Definition: xmath.cpp:208
double GetCovar(const int &VarN1, const int &VarN2) const
Definition: xmath.h:380
TComb & operator=(const TComb &)
Definition: xmath.h:334
static double Sqrt(const double &x)
Definition: xmath.h:13
TFlt Mode
Definition: xmath.h:140
THash< TInt, TMomV > TIntMomVH
Definition: xmath.h:264
static int Fac(const int &Val)
Definition: xmath.h:20
static double NR_FMAX(double maxarg1, double maxarg2)
Definition: xmath.h:413
Definition: xmath.h:129
double GetBucketMn(const int &BucketN) const
Definition: xmath.h:473
static void NewVV(TVVec< PMom > &MomVV, const int &XMoms, const int &YMoms)
Definition: xmath.h:163
static double Sqr(const double &x)
Definition: xmath.h:12
void Add(const double &Val, const bool &OnlyInP)
Definition: xmath.cpp:1281
double GetSDev() const
Definition: xmath.h:242
static bool IsInRange(const T &Val, const T &Mn, const T &Mx)
Definition: xmath.h:79
void SaveStat(const TStr &ValNm, TSOut &FOut) const
Definition: xmath.cpp:1302
double GetChiSq() const
Definition: xmath.h:443
THist(const double &_MnVal, const double &_MxVal, const int &Buckets)
Definition: xmath.h:465
bool IsUsable() const
Definition: xmath.h:225
Definition: dt.h:1386
static int Choose(const int &N, const int &K)
Definition: xmath.h:22
static void DefV(TMomV &MomV)
Definition: xmath.h:208
Definition: fl.h:58
static double Inv(const double &x)
Definition: xmath.h:11
static double LogOf2
Definition: xmath.h:9
TSvd & operator=(const TSvd &)
Definition: xmath.h:432
TLinReg & operator=(const TLinReg &)
Definition: xmath.h:372
Definition: xmath.h:345
static double GammaQ(const double &a, const double &x)
Definition: xmath.cpp:68
#define ClassTP(TNm, PNm)
Definition: bd.h:126
TVVec< PMom > TMomVV
Definition: xmath.h:262
~TSvd()
Definition: xmath.h:427
static uint Pow2(const int &pow)
Definition: xmath.h:24
#define ClassTPV(TNm, PNm, TNmV)
Definition: bd.h:162
TFlt Mn
Definition: xmath.h:137
double GetSErr() const
Definition: xmath.h:243
#define _CMPWARN
Definition: base.h:31
double GetMx() const
Definition: xmath.h:238
static PMom New(const TFltV &ValV)
Definition: xmath.h:169
void Add(const TFlt &Val, const TFlt &Wgt=1)
Definition: xmath.h:217
static const T & Mx(const T &Val1, const T &Val2, const T &Val3)
Definition: xmath.h:40
double GetCfUncer(const int &VarN) const
Definition: xmath.h:438
TSvd()
Definition: xmath.h:424
static void EntropyFracDim(const TIntV &ValV, TFltV &EntropyV)
Definition: xmath.cpp:252
TCorr & operator=(const TCorr &)
Definition: xmath.h:284
Definition: ds.h:2223
Definition: xmath.h:269
static PMom New()
Definition: xmath.h:160
TCorr(TSIn &)
Definition: xmath.h:280
TSizeTy GetYDim() const
Definition: ds.h:2251
TMom(TSIn &SIn)
Definition: xmath.h:171
static void ChiSquareTwo(const TFltV &ObservedBin1V, const TFltV &ObservedBin2V, double &ChiSquareVal, double &SignificancePrb)
Definition: xmath.cpp:637
Definition: xmath.h:397
static double Round(const double &Val)
Definition: xmath.h:16
bool operator<(const TMom &Mom) const
Definition: xmath.h:203
#define Assert(Cond)
Definition: bd.h:251
static double Power(const double &Base, const double &Exponent)
Definition: xmath.h:25
THash< TInt, PMom > TIntMomH
Definition: xmath.h:263
TFlt Vari
Definition: xmath.h:138
TLinReg()
Definition: xmath.h:364
TFlt SumW
Definition: xmath.h:133
TFlt ValSumW
Definition: xmath.h:133
static bool IsUsableV(const TMomV &MomV)
Definition: xmath.h:226
static void ChiSquareOne(const TFltV &ObservedBinV, const TFltV &ExpectedBinV, double &ChiSquareVal, double &SignificancePrb)
Definition: xmath.cpp:620
static void AveVar(const TFltV &ValV, double &Ave, double &Var)
Definition: xmath.cpp:590
TPt< TCorr > PCorr
Definition: xmath.h:269
int GetVars() const
Definition: xmath.h:375
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
Definition: fl.h:128
static double Pi
Definition: xmath.h:8
int GetCombN() const
Definition: xmath.h:338
int GetRecs() const
Definition: xmath.h:434
double GetPercentile(const int &PercentileN) const
Definition: xmath.h:250
Definition: xmath.h:5
TFlt Mean
Definition: xmath.h:138
double GetChiSq() const
Definition: xmath.h:383
static double Round(const double &Val, int Decs)
Definition: xmath.h:18
~TComb()
Definition: xmath.h:329
double GetQuart3() const
Definition: xmath.h:246
void Save(TSOut &)
Definition: xmath.h:332
TFlt Quart3
Definition: xmath.h:139
static double EntropyBias(const double &B)
Definition: xmath.cpp:285
TFlt UnusableVal
Definition: xmath.h:136
static void KsTest(const TFltV &ValV1, const TFltV &ValV2, double &DStat, double &PVal)
Definition: xmath.cpp:678
Definition: dt.h:1137
static void GammaQContFrac(double &gammcf, const double &a, const double &x, double &gln)
Definition: xmath.cpp:38
static bool IsInEps(const T &Val, const T &Eps)
Definition: xmath.h:83
static double GetPowerCoef(const TFltV &XValV, double MinX=-1.0)
Definition: xmath.cpp:299
int GetVars() const
Definition: xmath.h:435
static double NR_SIGN(double a, double b)
Definition: xmath.h:412
TIntV & GetItemV()
Definition: xmath.h:337
TIntV BucketV
Definition: xmath.h:460
TInt Vals
Definition: xmath.h:134
TPt< TComb > PComb
Definition: xmath.h:316
static double BetaI(const double &a, const double &b, const double &x)
Definition: xmath.cpp:137
void SaveTxt(const TStr &ValNm, const TStr &FNm) const
Definition: xmath.h:480
static PSvd Load(TSIn &SIn)
Definition: xmath.h:429
TVec< TFlt > TFltV
Definition: ds.h:1596
void Save(TSOut &SOut) const
Definition: xmath.h:181
double GetMean() const
Definition: xmath.h:240
THist()
Definition: xmath.h:464
Definition: dt.h:412
double GetCorrCf() const
Definition: xmath.h:286
double GetBucketValPerc(const int &BucketN) const
Definition: xmath.h:476
static void TTest(const TFltV &ValV1, const TFltV &ValV2, double &TTestVal, double &TTestPrb)
Definition: xmath.cpp:657
TSizeTy GetXDim() const
Definition: ds.h:2250
static PMom Load(TSIn &SIn)
Definition: xmath.h:180
Definition: hash.h:97
static int Sign(const T &Val)
Definition: xmath.h:29
static double LnComb(const int &n, const int &k)
Definition: xmath.cpp:95
double GetQuart1() const
Definition: xmath.h:245
static double Log2(const double &Val)
Definition: xmath.h:15
static void GammaPSeries(double &gamser, const double &a, const double &x, double &gln)
Definition: xmath.cpp:9
double GetY(const int RecN) const
Definition: xmath.h:358
TFltPrV ValWgtV
Definition: xmath.h:132
double GetVari() const
Definition: xmath.h:241
THash< TInt, TMomVV > TIntMomVVH
Definition: xmath.h:265
Definition: bd.h:196
static double Entropy(const TIntV &ValV)
Definition: xmath.cpp:231
double GetDecile(const int &DecileN) const
Definition: xmath.h:248
double GetCf(const int &VarN) const
Definition: xmath.h:437
static void LinearFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
Definition: xmath.cpp:150
TSvd(TSIn &)
Definition: xmath.h:428
TFlt SErr
Definition: xmath.h:138
TComb(TSIn &)
Definition: xmath.h:330
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
static double Log(const double &Val)
Definition: xmath.h:14
TFlt BucketSize
Definition: xmath.h:461
TMom(const TMom &Mom)
Definition: xmath.h:152
static const T & Median(const T &Val1, const T &Val2, const T &Val3)
Definition: xmath.h:62
double GetMode() const
Definition: xmath.h:247
static const T & InRange(const T &Val, const T &Mn, const T &Mx)
Definition: xmath.h:75
TFlt Median
Definition: xmath.h:139
bool operator==(const TMom &Mom) const
Definition: xmath.h:201
double GetBucketMx(const int &BucketN) const
Definition: xmath.h:474
int GetVals() const
Definition: xmath.h:471
static double LinInterp(const double &x1, const double &y1, const double &x2, const double &y2, const double &AtX) _CMPWARN
Definition: xmath.h:385
TBool DefP
Definition: xmath.h:131
static PComb Load(TSIn &SIn)
Definition: xmath.h:331
double GetY(const int RecN) const
Definition: xmath.h:410
Definition: dt.h:974
static PCorr Load(TSIn &SIn)
Definition: xmath.h:281
TFlt GetVal(const int &ValN) const
Definition: xmath.h:221
double GetSig(const int RecN) const
Definition: xmath.h:411
TFltV PercentileV
Definition: xmath.h:142
TComb(const int &_Items, const int &_Order)
Definition: xmath.h:324
static double BetaCf(const double &a, const double &b, const double &x)
Definition: xmath.cpp:99
TFltV DecileV
Definition: xmath.h:141
TMom & operator=(const TMom &Mom)
Definition: xmath.h:191
static PComb New(const int &Items, const int &Order)
Definition: xmath.h:327
double GetMn() const
Definition: xmath.h:237
int GetBuckets() const
Definition: xmath.h:472
~TLinReg()
Definition: xmath.h:367
static double E
Definition: xmath.h:7
void Gen(const TSizeTy &_XDim, const TSizeTy &_YDim)
Definition: ds.h:2247
TPt< TMom > PMom
Definition: xmath.h:129
static void DefVV(TVVec< PMom > &MomVV)
Definition: xmath.h:210
Definition: xmath.h:316
int GetRecs() const
Definition: xmath.h:374
TFlt MnVal
Definition: xmath.h:458
static PCorr New(const TFltV &ValV1, const TFltV &ValV2)
Definition: xmath.h:278
TFlt Quart1
Definition: xmath.h:139
int GetBucketVal(const int &BucketN) const
Definition: xmath.h:475
const TVal & At(const TSizeTy &X, const TSizeTy &Y) const
Definition: ds.h:2256
double GetCfUncer(const int &VarN) const
Definition: xmath.h:378