#include <xmath.h>
Definition at line 345 of file xmath.h.
TLinReg::TLinReg |
( |
TSIn & |
| ) |
|
|
inline |
double TLinReg::GetCf |
( |
const int & |
VarN | ) |
const |
|
inline |
Definition at line 377 of file xmath.h.
Referenced by Wr().
377 {
return CfV[VarN+1];}
double TLinReg::GetCfUncer |
( |
const int & |
VarN | ) |
const |
|
inline |
Definition at line 378 of file xmath.h.
Referenced by Wr().
379 return sqrt(
double(
CovarVV.
At(VarN+1, VarN+1)));}
const TVal & At(const int &X, const int &Y) const
double TLinReg::GetChiSq |
( |
| ) |
const |
|
inline |
double TLinReg::GetCovar |
( |
const int & |
VarN1, |
|
|
const int & |
VarN2 |
|
) |
| const |
|
inline |
Definition at line 380 of file xmath.h.
Referenced by Wr().
const TVal & At(const int &X, const int &Y) const
int TLinReg::GetRecs |
( |
| ) |
const |
|
inline |
double TLinReg::GetSig |
( |
const int |
RecN | ) |
const |
|
inline |
int TLinReg::GetVars |
( |
| ) |
const |
|
inline |
void TLinReg::GetXV |
( |
const int |
RecN, |
|
|
TFltV & |
VarV |
|
) |
| const |
|
inline |
double TLinReg::GetY |
( |
const int |
RecN | ) |
const |
|
inline |
static double TLinReg::LinInterp |
( |
const double & |
x1, |
|
|
const double & |
y1, |
|
|
const double & |
x2, |
|
|
const double & |
y2, |
|
|
const double & |
AtX |
|
) |
| |
|
inlinestatic |
Definition at line 385 of file xmath.h.
387 if (x1 == x2)
return (y1+y2)/2.0;
388 const double k = (y2 - y1) / (x2 - x1);
389 return k*(AtX - x1) + y1;
Definition at line 778 of file xmath.cpp.
References TVec< TVal, TSizeTy >::Empty(), IAssert, and TLinReg().
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);
void TLinReg::NR_covsrt |
( |
TFltVV & |
CovarVV, |
|
|
const int & |
Vars, |
|
|
const TIntV & |
ia, |
|
|
const int & |
mfit |
|
) |
| |
Definition at line 800 of file xmath.cpp.
References TVVec< TVal >::At(), Swap(), and Vars.
Referenced by NR_lfit().
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));}}
const TVal & At(const int &X, const int &Y) const
void Swap(TRec &Rec1, TRec &Rec2)
void TLinReg::NR_gaussj |
( |
TFltVV & |
a, |
|
|
const int & |
n, |
|
|
TFltVV & |
b, |
|
|
const int & |
m |
|
) |
| |
Definition at line 816 of file xmath.cpp.
References TVVec< TVal >::At(), Swap(), and TExcept::Throw().
Referenced by NR_lfit().
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]));}
static void Throw(const TStr &MsgStr)
const TVal & At(const int &X, const int &Y) const
void Swap(TRec &Rec1, TRec &Rec2)
void TLinReg::NR_lfit |
( |
| ) |
|
Definition at line 871 of file xmath.cpp.
References TVVec< TVal >::At(), CfV, ChiSq, CovarVV, GetSig(), GetXV(), GetY(), NR_covsrt(), NR_gaussj(), Recs, TMath::Sqr(), TExcept::Throw(), and Vars.
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];}
double GetSig(const int RecN) const
void NR_gaussj(TFltVV &a, const int &n, TFltVV &b, const int &m)
static double Sqr(const double &x)
void NR_covsrt(TFltVV &CovarVV, const int &Vars, const TIntV &ia, const int &mfit)
static void Throw(const TStr &MsgStr)
void GetXV(const int RecN, TFltV &VarV) const
double GetY(const int RecN) const
const TVal & At(const int &X, const int &Y) const
void TLinReg::Save |
( |
TSOut & |
| ) |
|
|
inline |
void TLinReg::Wr |
( |
| ) |
const |
Definition at line 919 of file xmath.cpp.
References GetCf(), GetCfUncer(), GetChiSq(), GetCovar(), and Vars.
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++){
double GetCf(const int &VarN) const
double GetCovar(const int &VarN1, const int &VarN2) const
double GetCfUncer(const int &VarN) const
The documentation for this class was generated from the following files: