3 double TMath::E=2.71828182845904523536;
10 double& gamser,
const double& a,
const double& x,
double& gln){
11 static const int ITMAX=100;
12 static const double EPS=3.0e-7;
24 for (n=1; n<=ITMAX; n++){
28 if (fabs(del) < fabs(sum)*EPS){
29 gamser=sum*exp(-x+a*log(x)-(gln));
39 double& gammcf,
const double& a,
const double& x,
double& gln){
40 static const int ITMAX=100;
41 static const double EPS=3.0e-7;
42 static const double FPMIN=1.0e-30;
44 double an, b, c, d, del, h;
51 for (i=1;i<=ITMAX;i++){
55 if (fabs(d) < FPMIN) d=FPMIN;
57 if (fabs(c) < FPMIN) c=FPMIN;
61 if (fabs(del-1.0) < EPS)
break;
65 gammcf=exp(-x+a*log(x)-(gln))*h;
70 double gamser, gammcf, gln;
72 GammaPSeries(gamser,a,x,gln);
75 GammaQContFrac(gammcf,a,x,gln);
81 double x, y, tmp, ser;
82 static double cof[6]={76.18009172947146,-86.50532032941677,
83 24.01409824083091,-1.231739572450155,
84 0.1208650973866179e-2,-0.5395239384953e-5};
89 tmp -= (x+0.5)*log(tmp);
90 ser=1.000000000190015;
91 for (j=0;j<=5;j++) ser += cof[j]/++y;
92 return -tmp+log(2.5066282746310005*ser/x);
100 static const double MAXIT=100;
101 static const double EPS=3.0e-7;
102 static const double FPMIN=1.0e-30;
104 double aa,c,d,del,h,qab,qam,qap;
111 if (fabs(d) < FPMIN) d=FPMIN;
114 for (m=1;m<=MAXIT;m++) {
116 aa=m*(b-m)*x/((qam+m2)*(a+m2));
118 if (fabs(d) < FPMIN) d=FPMIN;
120 if (fabs(c) < FPMIN) c=FPMIN;
123 aa = -(a+m)*(qab+m)*x/((a+m2)*(qap+m2));
125 if (fabs(d) < FPMIN) d=FPMIN;
127 if (fabs(c) < FPMIN) c=FPMIN;
131 if (fabs(del-1.0) < EPS)
break;
133 if (m > MAXIT){
Fail;}
140 if (x < 0.0 || x > 1.0){
Fail;}
141 if (x == 0.0 || x == 1.0) bt=0.0;
144 if (x < (a+1.0)/(a+b+2.0))
145 return bt*
BetaCf(a,b,x)/a;
147 return 1.0-bt*
BetaCf(b,a,1.0-x)/b;
152 double& SigA,
double& SigB,
double& Chi2,
double& R2) {
155 double t, sxoss, sx = 0.0, sy = 0.0, st2 = 0.0, ss, sigdat;
157 A = B = SigA = SigB = Chi2 = 0.0;
158 for (i = 0; i < XY.
Len(); i++) {
164 for (i = 0; i <XY.
Len(); i++) {
165 t = XY[i].Val1 - sxoss;
170 A = (sy - sx * B) / ss;
171 SigA = sqrt((1.0 + sx * sx / (ss * st2)) / ss);
172 SigB = sqrt(1.0 / st2);
173 for (i = 0; i < XY.
Len(); i++)
174 Chi2 +=
TMath::Sqr(XY[i].Val2 - A - B * XY[i].Val1);
175 sigdat = sqrt(Chi2 / (XY.
Len() - 2));
180 {
double N = XY.
Len(), sXY=0.0, sX=0.0, sY=0.0, sSqX=0.0, sSqY=0.0;
181 for (
int s =0; s < XY.
Len(); s++) {
182 sX += XY[s].Val1; sY += XY[s].Val2;
183 sXY += XY[s].Val1 * XY[s].Val2;
187 R2 =
TMath::Sqr(N*sXY - sX*sY) / ((N*sSqX - sX*sX) * (N*sSqY - sY*sY)); }
188 if (1.1 < R2 || -1.1 > R2) R2 = 0.0;
189 if (_isnan(A) || ! _finite(A)) A = 0.0;
190 if (_isnan(B) || ! _finite(B)) B = 0.0;
194 double& SigA,
double& SigB,
double& Chi2,
double& R2) {
199 for (
int s = 0; s < XY.
Len(); s++) {
200 LogXY.
Add(
TFltPr(log((
double)XY[s].Val1), log((
double)XY[s].Val2)));
204 if (_isnan(AA) || ! _finite(AA)) A = 0.0;
205 if (_isnan(BB) || ! _finite(BB)) B = 0.0;
209 double& SigA,
double& SigB,
double& Chi2,
double& R2) {
212 for (
int s = 0; s < XY.
Len(); s++) {
213 LogXY.
Add(
TFltPr(log((
double)XY[s].Val1), XY[s].Val2));
219 double& SigA,
double& SigB,
double& Chi2,
double& R2) {
223 for (
int s = 0; s < XY.
Len(); s++) {
224 XLogY.
Add(
TFltPr(XY[s].Val1, log((
double)XY[s].Val2)));
233 for (
int i = 0; i < ValV.
Len(); i++) { NewValV[i] = ValV[i]; }
240 for (
int i = 0; i < ValV.
Len(); i++) {
241 const double& Val = ValV[i];
242 if (Val > 0.0) { Ent -= Val * log(Val); Sum += Val; }
254 for (
int i = 0; i < ValV.
Len(); i++) {
255 IAssert(ValV[i]==1 || ValV[i] == 0);
256 NewValV[i] = ValV[i];
267 while (2*Pow2 <= ValV.
Len()) { Pow2 *= 2; }
269 for (
int i = 0; i < Pow2; i++) { ValV1[i] = ValV[i];
270 IAssert(ValV[i]==1.0 || ValV[i] == 0.0); }
273 while (ValV1.
Len() > 2) {
274 ValV2.
Gen(ValV1.
Len() / 2);
275 for (
int i = 0; i < ValV1.
Len(); i++) {
276 ValV2[i/2] += ValV1[i];
288 for (
double p = 0.5; p < 1.0; p +=0.0001) {
289 double H = p * log(p) + (1.0-p) * log(1.0 - p);
295 else {
return -1.0; }
300 for (
int i = 0; MinX <= 0.0 && i < XValV.
Len(); i++) {
304 for (
int i = 0; i < XValV.
Len(); i++) {
305 if (XValV[i].Val < MinX)
continue;
306 LnSum += log(XValV[i] / MinX);
308 return 1.0 + double(XValV.
Len()) / LnSum;
312 for (
int i = 0; MinX <= 0.0 && i < XValCntV.
Len(); i++) {
313 MinX = XValCntV[i].Val1; }
315 double NSamples=0.0, LnSum=0.0;
316 for (
int i = 0; i < XValCntV.
Len(); i++) {
317 if (XValCntV[i].Val1() < MinX)
continue;
318 LnSum += XValCntV[i].Val2 * log(XValCntV[i].Val1 / MinX);
319 NSamples += XValCntV[i].Val2;
321 return 1.0 + NSamples / LnSum;
328 ValWgtV(_ValV.Len(), 0),
330 UsableP(false), UnusableVal(-1),
332 Mean(), Vari(), SDev(), SErr(),
333 Median(), Quart1(), Quart3(),
334 DecileV(), PercentileV(){
335 for (
int ValN=0; ValN<_ValV.
Len(); ValN++){
Add(_ValV[ValN], 1);}
351 const double Val=
ValWgtV[ValN].Val1;
369 if (CurSumW > 0.5*
SumW) {
371 else if (CurSumW == 0.5*
SumW) {
393 for (
int v = 0; v < ValWgtH.
Len(); v++) {
394 if (ValWgtH[v] > MxWgt) { MxWgt=ValWgtH[v];
Mode=ValWgtH.
GetKey(v); }
398 int DecileN = 1, PercentileN = 1;
404 if (CurSumW >
SumW*DecileN*0.1) {
406 if (CurSumW >
SumW*PercentileN*0.01) {
416 if (MomNm==
"Mean"){
return GetMean();}
417 else if (MomNm==
"Vari"){
return GetVari();}
418 else if (MomNm==
"SDev"){
return GetSDev();}
419 else if (MomNm==
"SErr"){
return GetSErr();}
420 else if (MomNm==
"Median"){
return GetMedian();}
421 else if (MomNm==
"Quart1"){
return GetQuart1();}
422 else if (MomNm==
"Quart3"){
return GetQuart3();}
423 else if (MomNm==
"Decile0"){
return GetDecile(0);}
424 else if (MomNm==
"Decile1"){
return GetDecile(1);}
425 else if (MomNm==
"Decile2"){
return GetDecile(2);}
426 else if (MomNm==
"Decile3"){
return GetDecile(3);}
427 else if (MomNm==
"Decile4"){
return GetDecile(4);}
428 else if (MomNm==
"Decile5"){
return GetDecile(5);}
429 else if (MomNm==
"Decile6"){
return GetDecile(6);}
430 else if (MomNm==
"Decile7"){
return GetDecile(7);}
431 else if (MomNm==
"Decile8"){
return GetDecile(8);}
432 else if (MomNm==
"Decile9"){
return GetDecile(9);}
433 else if (MomNm==
"Decile10"){
return GetDecile(10);}
434 else {
Fail;
return 0;}
450 const char& SepCh,
const char& DelimCh,
451 const bool& DecileP,
const bool& PercentileP,
const TStr& FmtStr)
const {
454 ChA+=
"["; ChA+=SepCh;
466 for (
int DecileN=0; DecileN<=10; DecileN++){
473 for (
int PercentileN=0; PercentileN<=100; PercentileN++){
487 const char& SepCh,
const bool& DecileP,
const bool& PercentileP){
489 ChA+=VarPfx; ChA+=
"Vals"; ChA+=SepCh;
490 ChA+=VarPfx; ChA+=
"Min"; ChA+=SepCh;
491 ChA+=VarPfx; ChA+=
"Max"; ChA+=SepCh;
492 ChA+=VarPfx; ChA+=
"Mean"; ChA+=SepCh;
494 ChA+=VarPfx; ChA+=
"SDev"; ChA+=SepCh;
496 ChA+=VarPfx; ChA+=
"Quart1"; ChA+=SepCh;
497 ChA+=VarPfx; ChA+=
"Median"; ChA+=SepCh;
498 ChA+=VarPfx; ChA+=
"Quart3";
501 for (
int DecileN=0; DecileN<=10; DecileN++){
503 if (DecileN<10){ChA+=SepCh;}
508 for (
int PercentileN=0; PercentileN<=100; PercentileN++){
509 ChA+=VarPfx; ChA+=
"Per"; ChA+=
TInt::GetStr(PercentileN);
510 if (PercentileN<100){ChA+=SepCh;}
517 const char& SepCh,
const bool& DecileP,
const bool& PercentileP)
const {
531 for (
int DecileN=0; DecileN<=10; DecileN++){
536 for (
int PercentileN=0; PercentileN<=100; PercentileN++){
542 if (DecileP){Vals+=11;}
543 if (PercentileP){Vals+=101;}
544 for (
int ValN=0; ValN<
Vals; ValN++){
546 if (ValN<Vals-1){ChA+=SepCh;}
555 ValVLen(ValV1.Len()), CorrCf(), CorrCfPrb(), FisherZ(){
556 static const double TINY=1.0e-20;
560 double MeanVal1=0;
double MeanVal2=0;
561 {
for (
int ValN=0; ValN<
ValVLen; ValN++){
562 MeanVal1+=ValV1[ValN]; MeanVal2+=ValV2[ValN];}}
567 double syy=0.0;
double sxy=0.0;
double sxx=0.0;
568 {
for (
int ValN=0; ValN<
ValVLen; ValN++){
569 xt=ValV1[ValN]-MeanVal1;
570 yt=ValV2[ValN]-MeanVal2;
592 for (
int ValN=0; ValN<ValV.
Len(); ValN++){
597 for (
int ValN=0; ValN<ValV.
Len(); ValN++){
598 double s=ValV[ValN]-Ave;
602 Var=(Var-ep*ep/ValV.
Len())/(ValV.
Len()-1);
606 const double EPS1 = 0.001;
607 const double EPS2 = 1.0e-8;
608 double a2 = -2.0*Alam*Alam, fac = 2.0, sum = 0.0, term, termbf = 0.0;
609 for (
int j=1; j <= 100; j++) {
610 term = fac*exp(a2*j*j);
612 if (fabs(term) <= EPS1*termbf || fabs(term) <= EPS2*sum)
621 const TFltV& ObservedBinV,
const TFltV& ExpectedBinV,
622 double& ChiSquareVal,
double& SignificancePrb){
624 int Bins=ObservedBinV.
Len();
626 int DegreesOfFreedom=Bins-Constraints;
628 for (
int BinN=0; BinN<Bins; BinN++){
630 double BinDiff=ObservedBinV[BinN]-ExpectedBinV[BinN];
631 ChiSquareVal+=BinDiff*BinDiff/ExpectedBinV[BinN];
638 const TFltV& ObservedBin1V,
const TFltV& ObservedBin2V,
639 double& ChiSquareVal,
double& SignificancePrb){
641 int Bins=ObservedBin1V.
Len();
643 int DegreesOfFreedom=Bins-Constraints;
645 for (
int BinN=0; BinN<Bins; BinN++){
646 if ((ObservedBin1V[BinN]==0.0) && (ObservedBin2V[BinN]==0.0)){
649 double BinDiff=ObservedBin1V[BinN]-ObservedBin2V[BinN];
650 ChiSquareVal+=BinDiff*BinDiff/(ObservedBin1V[BinN]+ObservedBin2V[BinN]);
658 const TFltV& ValV1,
const TFltV& ValV2,
double& TTestVal,
double& TTestPrb){
666 double ave1=Val1Mom->GetMean();
667 double ave2=Val2Mom->GetMean();
668 double var1=Val1Mom->GetVari();
669 double var2=Val2Mom->GetVari();
673 TTestVal=(ave1-ave2)/sqrt(var1/n1+var2/n2);
681 double CumSum1=0.0, CumSum2=0.0, Cdf1=0.0, Cdf2=0.0;
682 const double N1 = ValV1.
Len();
683 const double N2 = ValV2.
Len();
684 if (! (N1 > 0.0 && N2 > 0.0)) { DStat = 1.0; PVal = 0.0;
return; }
686 while (i1 < ValV1.
Len() && i2 < ValV2.
Len()) {
687 const double X1 = ValV1[i1];
688 const double X2 = ValV2[i2];
691 Cdf1 = (CumSum1 / N1);
696 Cdf2 = (CumSum2 / N2);
699 DStat =
TMath::Mx(DStat, fabs(Cdf1 - Cdf2));
701 const double En = sqrt( N1*N2 / (N1+N2));
708 double N1=0.0, N2=0.0, CumSum1=0.0, CumSum2=0.0, Cdf1=0.0, Cdf2=0.0;
710 for (
int i = 0; i < ValCntV1.
Len(); i++) N1 += ValCntV1[i].Val2;
711 for (
int i = 0; i < ValCntV2.
Len(); i++) N2 += ValCntV2[i].Val2;
712 if (! (N1 > 0.0 && N2 > 0.0)) { DStat = 1.0; PVal = 0.0;
return; }
714 while (i1 < ValCntV1.
Len() && i2 < ValCntV2.
Len()) {
715 const double X1 = ValCntV1[i1].Val1;
716 const double X2 = ValCntV2[i2].Val1;
718 CumSum1 += ValCntV1[i1].Val2;
719 Cdf1 = (CumSum1 / N1);
723 CumSum2 += ValCntV2[i2].Val2;
724 Cdf2 = (CumSum2 / N2);
727 DStat =
TMath::Mx(DStat, fabs(Cdf1 - Cdf2));
729 const double En = sqrt( N1*N2 / (N1+N2));
738 for (
int OrderN=0; OrderN<
Order; OrderN++){
739 ItemV[OrderN]=OrderN;}
744 while ((OrderN>=0)&&(
ItemV[OrderN]==
Items-(
Order-OrderN-1)-1)){OrderN--;}
749 for (
int SubOrderN=OrderN+1; SubOrderN<
Order; SubOrderN++){
751 CombN++;
return true;
760 int LCombs=1;
int HCombs=1;
761 for (
int OrderN=0; OrderN<
Order; OrderN++){
762 LCombs*=OrderN+1; HCombs*=
Items-OrderN;}
763 int Combs=HCombs/LCombs;
769 for (
int OrderN=0; OrderN<
Order; OrderN++){
770 if (OrderN>0){printf(
" ");}
771 printf(
"%d",
ItemV[OrderN]());
783 LinReg->SigV.Gen(LinReg->YV.Len());
784 LinReg->SigV.PutAll(1);
788 LinReg->Recs=LinReg->XVV.GetXDim();
789 LinReg->Vars=LinReg->XVV.GetYDim();
792 IAssert(LinReg->YV.Len()==LinReg->Recs);
793 IAssert(LinReg->SigV.Len()==LinReg->Recs);
794 LinReg->CovarVV.Gen(LinReg->Vars+1, LinReg->Vars+1);
795 LinReg->CfV.Gen(LinReg->Vars+1);
801 TFltVV& CovarVV,
const int& Vars,
const TIntV& ia,
const int& mfit){
802 for (
int i=mfit+1; i<=
Vars; i++){
803 for (
int j=1; j<=i; j++){
804 CovarVV.
At(i, j)=0; CovarVV.
At(j, i)=0.0;}
807 for (
int j=Vars; j>=1; j--){
809 for (
int i=1; i<=
Vars; i++){
Swap(CovarVV.
At(i, k), CovarVV.
At(i, j));}
810 {
for (
int i=1; i<=
Vars; i++){
Swap(CovarVV.
At(k, i), CovarVV.
At(j, i));}}
817 int i, icol=0, irow=0, j, k, l, ll;
818 double big, dum, pivinv;
823 for (j=1; j<=n; j++){ipiv[j]=0;}
824 for (i=1; i<=n; i++){
826 for (j=1; j<=n; j++){
828 for (k=1; k<=n; k++){
830 if (fabs(
double(a.
At(j, k))) >= big){
831 big=fabs(
double(a.
At(j, k)));
843 for (l=1; l<=n; l++){
Swap(a.
At(irow, l), a.
At(icol, l));}
844 for (l=1; l<=m; l++){
Swap(b.
At(irow, l), b.
At(icol, l));}
848 if (a.
At(icol, icol)==0.0){
850 pivinv=1.0/a.
At(icol, icol);
851 a.
At(icol, icol)=1.0;
852 for (l=1; l<=n; l++){a.
At(icol, l)=a.
At(icol, l)*pivinv;}
853 for (l=1; l<=m; l++){b.
At(icol, l)=b.
At(icol, l)*pivinv;}
854 for (ll=1; ll<=n; ll++){
858 for (l=1;l<=n;l++){a.
At(ll, l)-=a.
At(icol, l)*dum;}
859 for (l=1;l<=m;l++){b.
At(ll, l)-=b.
At(icol, l)*dum;}
863 for (l=n; l>=1; l--){
864 if (indxr[l]!=indxc[l]){
865 for (k=1; k<=n; k++){
866 Swap(a.
At(k, indxr[l]), a.
At(k, indxc[l]));}
872 int i,j,k,l,m,mfit=0;
873 double ym,wt,sum,sig2i;
878 for (j=1;j<=
Vars;j++){
879 if (ia[j]!=0){mfit++;}}
880 if (mfit==0){
TExcept::Throw(
"No parameters to be fitted in LFit");}
881 for (j=1; j<=mfit; j++){
882 for (k=1; k<=mfit; k++){
CovarVV.
At(j, k)=0.0;}
885 for (i=1; i<=
Recs; i++){
889 for (j=1;j<=
Vars;j++){
890 if (ia[j]==0){ym-=
CfV[j]*afunc[j];}}
893 for (j=0, l=1; l<=
Vars; l++){
896 for (j++, k=0, m=1; m<=l; m++){
897 if (ia[m]!=0){
CovarVV.
At(j, ++k)+=wt*afunc[m];}
899 beta.
At(j, 1)+=ym*wt;
903 for (j=2; j<=mfit; j++){
907 for (j=0, l=1; l<=
Vars; l++){
908 if (ia[l]!=0){
CfV[l]=beta.
At(++j, 1);}
911 for (i=1; i<=
Recs; i++){
913 for (sum=0.0, j=1; j<=
Vars; j++){sum+=
CfV[j]*afunc[j];}
920 printf(
"\n%11s %21s\n",
"parameter",
"uncertainty");
921 for (
int i=0; i<
Vars;i++){
922 printf(
" a[%1d] = %8.6f %12.6f\n",
925 printf(
"chi-squared = %12f\n",
GetChiSq());
927 printf(
"full covariance matrix\n");
928 {
for (
int i=0;i<
Vars;i++){
929 for (
int j=0;j<
Vars;j++){
942 Svd->SigV.Gen(Svd->YV.Len());
947 Svd->Recs=Svd->XVV.GetXDim();
948 Svd->Vars=Svd->XVV.GetYDim();
951 IAssert(Svd->YV.Len()==Svd->Recs);
952 IAssert(Svd->SigV.Len()==Svd->Recs);
953 Svd->CovarVV.Gen(Svd->Vars+1, Svd->Vars+1);
954 Svd->CfV.Gen(Svd->Vars+1);
966 return (absb == 0.0 ? 0.0 : absb*sqrt(1.0+
TMath::Sqr(absa/absb)));
971 int flag,i,its,j,jj,k,l=0,nm;
972 double anorm,c,f,g,h,s,scale,x,y,z;
981 for (k=i;k<=m;k++) scale += fabs(
double(a.
At(k,i)));
985 s += a.
At(k,i)*a.
At(k,i);
992 for (s=0.0,k=i;k<=m;k++) s += a.
At(k,i)*a(k,j);
994 for (k=i;k<=m;k++) a.
At(k,j) += f*a.
At(k,i);
996 for (k=i;k<=m;k++) a.
At(k,i) *= scale;
1001 if (i <= m && i != n) {
1002 for (k=l;k<=n;k++) scale += fabs(
double(a.
At(i,k)));
1004 for (k=l;k<=n;k++) {
1006 s += a.
At(i,k)*a.
At(i,k);
1012 for (k=l;k<=n;k++) rv1[k]=a.
At(i,k)/h;
1013 for (j=l;j<=m;j++) {
1014 for (s=0.0,k=l;k<=n;k++) s += a.
At(j,k)*a.
At(i,k);
1015 for (k=l;k<=n;k++) a.
At(j,k) += s*rv1[k];
1017 for (k=l;k<=n;k++) a.
At(i,k) *= scale;
1020 anorm=
NR_FMAX(anorm,(fabs(
double(w[i]))+fabs(
double(rv1[i]))));
1022 for (i=n;i>=1;i--) {
1026 v.
At(j,i)=(a.
At(i,j)/a.
At(i,l))/g;
1027 for (j=l;j<=n;j++) {
1028 for (s=0.0,k=l;k<=n;k++) s += a.
At(i,k)*v.
At(k,j);
1029 for (k=l;k<=n;k++) v.
At(k,j) += s*v.
At(k,i);
1032 for (j=l;j<=n;j++) v.
At(i,j)=v.
At(j,i)=0.0;
1038 for (i=
NR_IMIN(m,n);i>=1;i--) {
1041 for (j=l;j<=n;j++) a.
At(i,j)=0.0;
1044 for (j=l;j<=n;j++) {
1045 for (s=0.0,k=l;k<=m;k++) s += a.
At(k,i)*a.
At(k,j);
1047 for (k=i;k<=m;k++) a.
At(k,j) += f*a.
At(k,i);
1049 for (j=i;j<=m;j++) a.
At(j,i) *= g;
1050 }
else for (j=i;j<=m;j++) a.
At(j,i)=0.0;
1053 for (k=n;k>=1;k--) {
1054 for (its=1;its<=30;its++) {
1056 for (l=k;l>=1;l--) {
1058 if ((
double)(fabs(
double(rv1[l])+anorm)) == anorm) {
1062 if ((
double)(fabs(
double(w[nm]))+anorm) == anorm)
break;
1067 for (i=l;i<=k;i++) {
1070 if ((
double)(fabs(f)+anorm) == anorm)
break;
1077 for (j=1;j<=m;j++) {
1089 for (j=1;j<=n;j++) v.
At(j,k) = -v.
At(j,k);
1100 f=((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y);
1102 f=((x-z)*(x+z)+h*((y/(f+
NR_SIGN(g,f)))-h))/x;
1104 for (j=l;j<=nm;j++) {
1118 for (jj=1;jj<=n;jj++) {
1133 for (jj=1;jj<=m;jj++) {
1153 for (j=1;j<=n;j++) {
1156 for (i=1;i<=m;i++) s += u.
At(i,j)*b[i];
1161 for (j=1;j<=n;j++) {
1163 for (jj=1;jj<=n;jj++) s += v.
At(j,jj)*tmp[jj];
1173 for (i=1;i<=ma;i++) {
1175 if (w[i]) wti[i]=1.0/(w[i]*w[i]);
1177 for (i=1;i<=ma;i++) {
1178 for (j=1;j<=i;j++) {
1179 for (sum=0.0,k=1;k<=ma;k++) sum += v.
At(i,k)*v.
At(j,k)*wti[k];
1180 cvm.
At(j,i)=cvm.
At(i,j)=sum;
1187 double wmax,tmp,thresh,sum;
1195 for (i=1;i<=
Recs;i++) {
1198 for (j=1;j<=
Vars;j++){u.
At(i,j)=afunc[j]*tmp;}
1203 for (j=1;j<=
Vars;j++){
1204 if (w[j] > wmax){wmax=w[j];}}
1206 for (j=1;j<=
Vars;j++){
1207 if (
double(w[j])<thresh){w[j]=0.0;}}
1210 for (i=1;i<=
Recs;i++) {
1212 for (sum=0.0,j=1;j<=
Vars;j++){sum +=
CfV[j]*afunc[j];}
1226 for (
int VarN=0; VarN<
Vars; VarN++){
1236 for (
int x = 0; x < InMtx.
GetXDim(); x++) {
1237 for (
int y = 0; y < InMtx.
GetYDim(); y++) {
1238 LSingV.
At(x+1, y+1) = InMtx.
At(x, y);
1264 printf(
"\n%11s %21s\n",
"parameter",
"uncertainty");
1265 for (
int i=0; i<
Vars;i++){
1266 printf(
" a[%1d] = %8.6f %12.6f\n",
1269 printf(
"chi-squared = %12f\n",
GetChiSq());
1271 printf(
"full covariance matrix\n");
1272 {
for (
int i=0;i<
Vars;i++){
1273 for (
int j=0;j<
Vars;j++){
1305 for (
int BucketN = 0; BucketN < Buckets; BucketN++) {
static double LnGamma(const double &xx)
double GetCf(const int &VarN) const
static double NR_pythag(double a, double b)
static TStr GetNmVStr(const TStr &VarPfx, const char &SepCh='\t', const bool &DecileP=true, const bool &PercentileP=true)
double GetSig(const int RecN) const
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
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)
void NR_gaussj(TFltVV &a, const int &n, TFltVV &b, const int &m)
static void PowerFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
static PLinReg New(const TFltVV &XVV, const TFltV &YV, const TFltV &SigV=TFltV())
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
void DelX(const TSizeTy &X)
static double NR_FMAX(double maxarg1, double maxarg2)
void GetXV(const int RecN, TFltV &VarV) const
const TDat & GetDat(const TKey &Key) const
static double Sqr(const double &x)
void Add(const double &Val, const bool &OnlyInP)
void SaveStat(const TStr &ValNm, TSOut &FOut) const
bool Empty() const
Tests whether the vector is empty.
static double GammaQ(const double &a, const double &x)
static void NR_svdcmp(TFltVV &a, int m, int n, TFltV &w, TFltVV &v)
static void Svd(const TFltVV &InMtx, TFltVV &LSingV, TFltV &SingValV, TFltVV &RSingV)
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
TStr GetValVStr(const char &SepCh='\t', const bool &DecileP=true, const bool &PercentileP=true) const
void Add(const TFlt &Val, const TFlt &Wgt=1)
double GetCfUncer(const int &VarN) const
static void EntropyFracDim(const TIntV &ValV, TFltV &EntropyV)
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
void NR_covsrt(TFltVV &CovarVV, const int &Vars, const TIntV &ia, const int &mfit)
static void Throw(const TStr &MsgStr)
static void ChiSquareTwo(const TFltV &ObservedBin1V, const TFltV &ObservedBin2V, double &ChiSquareVal, double &SignificancePrb)
static double Round(const double &Val)
static void Svd1Based(const TFltVV &InMtx1, TFltVV &LSingV, TFltV &SingValV, TFltVV &RSingV)
const TVal & Last() const
Returns a reference to the last element of the vector.
static void ChiSquareOne(const TFltV &ObservedBinV, const TFltV &ExpectedBinV, double &ChiSquareVal, double &SignificancePrb)
static void AveVar(const TFltV &ValV, double &Ave, double &Var)
void GetCfUncerV(TFltV &CfUncerV)
TPair< TFlt, TFlt > TFltPr
double GetPercentile(const int &PercentileN) const
void NR_svdvar(TFltVV &v, int ma, TFltV &w, TFltVV &cvm)
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)
TStr GetStr(const char &SepCh=' ', const char &DelimCh=':', const bool &DecileP=true, const bool &PercentileP=true, const TStr &FmtStr="%g") const
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 DelY(const TSizeTy &Y)
static TStr Fmt(const char *FmtStr,...)
bool IsSorted(const bool &Asc=true) const
Checks whether the vector is sorted in ascending (if Asc=true) or descending (if Asc=false) order...
static void TTest(const TFltV &ValV1, const TFltV &ValV2, double &TTestVal, double &TTestPrb)
static PSvd New(const TFltVV &XVV, const TFltV &YV, const TFltV &SigV=TFltV())
static double LnComb(const int &n, const int &k)
void GetXV(const int RecN, TFltV &VarV) const
TStr GetStrByNm(const TStr &MomNm, char *FmtStr=NULL) const
static void GammaPSeries(double &gamser, const double &a, const double &x, double &gln)
double GetY(const int RecN) const
void NR_svbksb(TFltVV &u, TFltV &w, TFltVV &v, int m, int n, TFltV &b, TFltV &x)
static double Entropy(const TIntV &ValV)
void Reverse()
Reverses the order of the elements in the vector.
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.
double GetByNm(const TStr &MomNm) const
void MoveFrom(TVec< TVal, TSizeTy > &Vec)
Takes over the data and the capacity from Vec.
bool IsKey(const TKey &Key) const
int PutStrLn(const TStr &Str, const bool &ForceInLn=false)
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
double GetY(const int RecN) const
double GetSig(const int RecN) const
TDat & AddDat(const TKey &Key)
static double BetaCf(const double &a, const double &b, const double &x)
void Gen(const TSizeTy &_XDim, const TSizeTy &_YDim)
const TKey & GetKey(const int &KeyId) const
void Swap(TRec &Rec1, TRec &Rec2)
const TVal & At(const TSizeTy &X, const TSizeTy &Y) const
double GetCfUncer(const int &VarN) const