SNAP Library 3.0, Developer Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TSvd Class Reference

#include <xmath.h>

Collaboration diagram for TSvd:

Public Member Functions

void GetXV (const int RecN, TFltV &VarV) const
 
double GetY (const int RecN) const
 
double GetSig (const int RecN) const
 
void NR_svbksb (TFltVV &u, TFltV &w, TFltVV &v, int m, int n, TFltV &b, TFltV &x)
 
void NR_svdvar (TFltVV &v, int ma, TFltV &w, TFltVV &cvm)
 
void NR_svdfit ()
 
 TSvd ()
 
 ~TSvd ()
 
 TSvd (TSIn &)
 
void Save (TSOut &)
 
TSvdoperator= (const TSvd &)
 
int GetRecs () const
 
int GetVars () const
 
double GetCf (const int &VarN) const
 
double GetCfUncer (const int &VarN) const
 
double GetCovar (const int &VarN1, const int &VarN2) const
 
double GetChiSq () const
 
void GetCfV (TFltV &_CfV)
 
void GetCfUncerV (TFltV &CfUncerV)
 
void Wr () const
 

Static Public Member Functions

static double NR_SIGN (double a, double b)
 
static double NR_FMAX (double maxarg1, double maxarg2)
 
static int NR_IMIN (int iminarg1, int iminarg2)
 
static double NR_pythag (double a, double b)
 
static void NR_svdcmp (TFltVV &a, int m, int n, TFltV &w, TFltVV &v)
 
static PSvd New (const TFltVV &XVV, const TFltV &YV, const TFltV &SigV=TFltV())
 
static PSvd Load (TSIn &SIn)
 
static void Svd (const TFltVV &InMtx, TFltVV &LSingV, TFltV &SingValV, TFltVV &RSingV)
 
static void Svd1Based (const TFltVV &InMtx1, TFltVV &LSingV, TFltV &SingValV, TFltVV &RSingV)
 

Public Attributes

TFltVV XVV
 
TFltV YV
 
TFltV SigV
 
int Recs
 
int Vars
 
TFltVV CovarVV
 
TFltV CfV
 
double ChiSq
 

Private Attributes

TCRef CRef
 

Friends

class TPt< TSvd >
 

Detailed Description

Definition at line 397 of file xmath.h.

Constructor & Destructor Documentation

TSvd::TSvd ( )
inline

Definition at line 424 of file xmath.h.

Referenced by New().

424 {}

Here is the caller graph for this function:

TSvd::~TSvd ( )
inline

Definition at line 427 of file xmath.h.

427 {}
TSvd::TSvd ( TSIn )
inline

Definition at line 428 of file xmath.h.

References Fail.

428 {Fail;}
#define Fail
Definition: bd.h:238

Member Function Documentation

double TSvd::GetCf ( const int &  VarN) const
inline

Definition at line 437 of file xmath.h.

Referenced by Wr().

437 {return CfV[VarN+1];}
TFltV CfV
Definition: xmath.h:404

Here is the caller graph for this function:

double TSvd::GetCfUncer ( const int &  VarN) const
inline

Definition at line 438 of file xmath.h.

Referenced by GetCfUncerV(), and Wr().

438  {
439  return sqrt(double(CovarVV.At(VarN+1, VarN+1)));}
TFltVV CovarVV
Definition: xmath.h:403
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:2190

Here is the caller graph for this function:

void TSvd::GetCfUncerV ( TFltV CfUncerV)

Definition at line 1224 of file xmath.cpp.

References TVec< TVal, TSizeTy >::Gen(), GetCfUncer(), and Vars.

1224  {
1225  CfUncerV.Gen(Vars);
1226  for (int VarN=0; VarN<Vars; VarN++){
1227  CfUncerV[VarN]=GetCfUncer(VarN);
1228  }
1229 }
double GetCfUncer(const int &VarN) const
Definition: xmath.h:438
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
int Vars
Definition: xmath.h:402

Here is the call graph for this function:

void TSvd::GetCfV ( TFltV _CfV)

Definition at line 1220 of file xmath.cpp.

References CfV, and TVec< TVal, TSizeTy >::Del().

1220  {
1221  _CfV=CfV; _CfV.Del(0);
1222 }
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
Definition: ds.h:1130
TFltV CfV
Definition: xmath.h:404

Here is the call graph for this function:

double TSvd::GetChiSq ( ) const
inline

Definition at line 443 of file xmath.h.

Referenced by Wr().

443 {return ChiSq;}
double ChiSq
Definition: xmath.h:405

Here is the caller graph for this function:

double TSvd::GetCovar ( const int &  VarN1,
const int &  VarN2 
) const
inline

Definition at line 440 of file xmath.h.

Referenced by Wr().

440  {
441  return CovarVV.At(VarN1+1, VarN2+1);}
TFltVV CovarVV
Definition: xmath.h:403
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:2190

Here is the caller graph for this function:

int TSvd::GetRecs ( ) const
inline

Definition at line 434 of file xmath.h.

434 {return Recs;}
int Recs
Definition: xmath.h:402
double TSvd::GetSig ( const int  RecN) const
inline

Definition at line 411 of file xmath.h.

Referenced by NR_svdfit().

411 {return SigV[RecN-1];}
TFltV SigV
Definition: xmath.h:401

Here is the caller graph for this function:

int TSvd::GetVars ( ) const
inline

Definition at line 435 of file xmath.h.

435 {return Vars;}
int Vars
Definition: xmath.h:402
void TSvd::GetXV ( const int  RecN,
TFltV VarV 
) const
inline

Definition at line 406 of file xmath.h.

References TVVec< TVal >::At(), and TVec< TVal, TSizeTy >::Gen().

Referenced by NR_svdfit().

406  {
407  VarV.Gen(Vars+1);
408  for (int VarN=0; VarN<Vars; VarN++){VarV[VarN+1]=XVV.At(RecN-1, VarN);}
409  }
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
int Vars
Definition: xmath.h:402
TFltVV XVV
Definition: xmath.h:399
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:2190

Here is the call graph for this function:

Here is the caller graph for this function:

double TSvd::GetY ( const int  RecN) const
inline

Definition at line 410 of file xmath.h.

Referenced by NR_svdfit().

410 {return YV[RecN-1];}
TFltV YV
Definition: xmath.h:400

Here is the caller graph for this function:

static PSvd TSvd::Load ( TSIn SIn)
inlinestatic

Definition at line 429 of file xmath.h.

429 {return new TSvd(SIn);}
TSvd()
Definition: xmath.h:424
PSvd TSvd::New ( const TFltVV XVV,
const TFltV YV,
const TFltV SigV = TFltV() 
)
static

Definition at line 937 of file xmath.cpp.

References TVec< TVal, TSizeTy >::Empty(), IAssert, Svd(), and TSvd().

937  {
938  PSvd Svd=PSvd(new TSvd());
939  Svd->XVV=_XVV;
940  Svd->YV=_YV;
941  if (_SigV.Empty()){
942  Svd->SigV.Gen(Svd->YV.Len());
943  Svd->SigV.PutAll(1);
944  } else {
945  Svd->SigV=_SigV;
946  }
947  Svd->Recs=Svd->XVV.GetXDim();
948  Svd->Vars=Svd->XVV.GetYDim();
949  IAssert(Svd->Recs>0);
950  IAssert(Svd->Vars>0);
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);
955  Svd->NR_svdfit();
956  return Svd;
957 }
#define IAssert(Cond)
Definition: bd.h:262
TPt< TSvd > PSvd
Definition: xmath.h:397
static void Svd(const TFltVV &InMtx, TFltVV &LSingV, TFltV &SingValV, TFltVV &RSingV)
Definition: xmath.cpp:1232
TSvd()
Definition: xmath.h:424
Definition: bd.h:196

Here is the call graph for this function:

static double TSvd::NR_FMAX ( double  maxarg1,
double  maxarg2 
)
inlinestatic

Definition at line 413 of file xmath.h.

Referenced by NR_svdcmp().

413  {
414  return maxarg1 > maxarg2 ? maxarg1 : maxarg2;}

Here is the caller graph for this function:

static int TSvd::NR_IMIN ( int  iminarg1,
int  iminarg2 
)
inlinestatic

Definition at line 415 of file xmath.h.

Referenced by NR_svdcmp().

415  {
416  return iminarg1 < iminarg2 ? iminarg1 : iminarg2;}

Here is the caller graph for this function:

double TSvd::NR_pythag ( double  a,
double  b 
)
static

Definition at line 959 of file xmath.cpp.

References TMath::Sqr().

Referenced by NR_svdcmp().

959  {
960  double absa,absb;
961  absa=fabs(a);
962  absb=fabs(b);
963  if (absa > absb){
964  return absa*sqrt(1.0+TMath::Sqr(absb/absa));
965  } else {
966  return (absb == 0.0 ? 0.0 : absb*sqrt(1.0+TMath::Sqr(absa/absb)));
967  }
968 }
static double Sqr(const double &x)
Definition: xmath.h:12

Here is the call graph for this function:

Here is the caller graph for this function:

static double TSvd::NR_SIGN ( double  a,
double  b 
)
inlinestatic

Definition at line 412 of file xmath.h.

Referenced by NR_svdcmp().

412 {return b >= 0.0 ? fabs(a) : -fabs(a);}

Here is the caller graph for this function:

void TSvd::NR_svbksb ( TFltVV u,
TFltV w,
TFltVV v,
int  m,
int  n,
TFltV b,
TFltV x 
)

Definition at line 1147 of file xmath.cpp.

References TVVec< TVal >::At().

Referenced by NR_svdfit().

1148  {
1149  int jj,j,i;
1150  double s;
1151 
1152  TFltV tmp(n+1);
1153  for (j=1;j<=n;j++) {
1154  s=0.0;
1155  if (w[j]) {
1156  for (i=1;i<=m;i++) s += u.At(i,j)*b[i];
1157  s /= w[j];
1158  }
1159  tmp[j]=s;
1160  }
1161  for (j=1;j<=n;j++) {
1162  s=0.0;
1163  for (jj=1;jj<=n;jj++) s += v.At(j,jj)*tmp[jj];
1164  x[j]=s;
1165  }
1166 }
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:2190

Here is the call graph for this function:

Here is the caller graph for this function:

void TSvd::NR_svdcmp ( TFltVV a,
int  m,
int  n,
TFltV w,
TFltVV v 
)
static

Definition at line 970 of file xmath.cpp.

References TVVec< TVal >::At(), NR_FMAX(), NR_IMIN(), NR_pythag(), NR_SIGN(), and TExcept::Throw().

Referenced by NR_svdfit(), Svd(), and Svd1Based().

970  {
971  int flag,i,its,j,jj,k,l=0,nm;
972  double anorm,c,f,g,h,s,scale,x,y,z;
973 
974  TFltV rv1(n+1);
975  g=scale=anorm=0.0;
976  for (i=1;i<=n;i++) {
977  l=i+1;
978  rv1[i]=scale*g;
979  g=s=scale=0.0;
980  if (i <= m) {
981  for (k=i;k<=m;k++) scale += fabs(double(a.At(k,i)));
982  if (scale) {
983  for (k=i;k<=m;k++) {
984  a.At(k,i) /= scale;
985  s += a.At(k,i)*a.At(k,i);
986  }
987  f=a.At(i,i);
988  g = -NR_SIGN(sqrt(s),f);
989  h=f*g-s;
990  a.At(i,i)=f-g;
991  for (j=l;j<=n;j++) {
992  for (s=0.0,k=i;k<=m;k++) s += a.At(k,i)*a(k,j);
993  f=s/h;
994  for (k=i;k<=m;k++) a.At(k,j) += f*a.At(k,i);
995  }
996  for (k=i;k<=m;k++) a.At(k,i) *= scale;
997  }
998  }
999  w[i]=scale *g;
1000  g=s=scale=0.0;
1001  if (i <= m && i != n) {
1002  for (k=l;k<=n;k++) scale += fabs(double(a.At(i,k)));
1003  if (scale) {
1004  for (k=l;k<=n;k++) {
1005  a.At(i,k) /= scale;
1006  s += a.At(i,k)*a.At(i,k);
1007  }
1008  f=a.At(i,l);
1009  g = -NR_SIGN(sqrt(s),f);
1010  h=f*g-s;
1011  a.At(i,l)=f-g;
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];
1016  }
1017  for (k=l;k<=n;k++) a.At(i,k) *= scale;
1018  }
1019  }
1020  anorm=NR_FMAX(anorm,(fabs(double(w[i]))+fabs(double(rv1[i]))));
1021  }
1022  for (i=n;i>=1;i--) {
1023  if (i < n) {
1024  if (g) {
1025  for (j=l;j<=n;j++)
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);
1030  }
1031  }
1032  for (j=l;j<=n;j++) v.At(i,j)=v.At(j,i)=0.0;
1033  }
1034  v.At(i,i)=1.0;
1035  g=rv1[i];
1036  l=i;
1037  }
1038  for (i=NR_IMIN(m,n);i>=1;i--) {
1039  l=i+1;
1040  g=w[i];
1041  for (j=l;j<=n;j++) a.At(i,j)=0.0;
1042  if (g) {
1043  g=1.0/g;
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);
1046  f=(s/a.At(i,i))*g;
1047  for (k=i;k<=m;k++) a.At(k,j) += f*a.At(k,i);
1048  }
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;
1051  a.At(i,i)++;
1052  }
1053  for (k=n;k>=1;k--) {
1054  for (its=1;its<=30;its++) {
1055  flag=1;
1056  for (l=k;l>=1;l--) {
1057  nm=l-1;
1058  if ((double)(fabs(double(rv1[l])+anorm)) == anorm) {
1059  flag=0;
1060  break;
1061  }
1062  if ((double)(fabs(double(w[nm]))+anorm) == anorm) break;
1063  }
1064  if (flag) {
1065  c=0.0;
1066  s=1.0;
1067  for (i=l;i<=k;i++) {
1068  f=s*rv1[i];
1069  rv1[i]=c*rv1[i];
1070  if ((double)(fabs(f)+anorm) == anorm) break;
1071  g=w[i];
1072  h=NR_pythag(f,g);
1073  w[i]=h;
1074  h=1.0/h;
1075  c=g*h;
1076  s = -f*h;
1077  for (j=1;j<=m;j++) {
1078  y=a.At(j,nm);
1079  z=a.At(j,i);
1080  a.At(j,nm)=y*c+z*s;
1081  a.At(j,i)=z*c-y*s;
1082  }
1083  }
1084  }
1085  z=w[k];
1086  if (l == k) {
1087  if (z < 0.0) {
1088  w[k] = -z;
1089  for (j=1;j<=n;j++) v.At(j,k) = -v.At(j,k);
1090  }
1091  break;
1092  }
1093  if (its==30){
1094  TExcept::Throw("no convergence in 30 svdcmp iterations");}
1095  x=w[l];
1096  nm=k-1;
1097  y=w[nm];
1098  g=rv1[nm];
1099  h=rv1[k];
1100  f=((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y);
1101  g=NR_pythag(f,1.0);
1102  f=((x-z)*(x+z)+h*((y/(f+NR_SIGN(g,f)))-h))/x;
1103  c=s=1.0;
1104  for (j=l;j<=nm;j++) {
1105  i=j+1;
1106  g=rv1[i];
1107  y=w[i];
1108  h=s*g;
1109  g=c*g;
1110  z=NR_pythag(f,h);
1111  rv1[j]=z;
1112  c=f/z;
1113  s=h/z;
1114  f=x*c+g*s;
1115  g = g*c-x*s;
1116  h=y*s;
1117  y *= c;
1118  for (jj=1;jj<=n;jj++) {
1119  x=v.At(jj,j);
1120  z=v.At(jj,i);
1121  v.At(jj,j)=x*c+z*s;
1122  v.At(jj,i)=z*c-x*s;
1123  }
1124  z=NR_pythag(f,h);
1125  w[j]=z;
1126  if (z) {
1127  z=1.0/z;
1128  c=f*z;
1129  s=h*z;
1130  }
1131  f=c*g+s*y;
1132  x=c*y-s*g;
1133  for (jj=1;jj<=m;jj++) {
1134  y=a.At(jj,j);
1135  z=a.At(jj,i);
1136  a.At(jj,j)=y*c+z*s;
1137  a.At(jj,i)=z*c-y*s;
1138  }
1139  }
1140  rv1[l]=0.0;
1141  rv1[k]=f;
1142  w[k]=x;
1143  }
1144  }
1145 }
static double NR_pythag(double a, double b)
Definition: xmath.cpp:959
static int NR_IMIN(int iminarg1, int iminarg2)
Definition: xmath.h:415
static double NR_FMAX(double maxarg1, double maxarg2)
Definition: xmath.h:413
static void Throw(const TStr &MsgStr)
Definition: ut.h:187
static double NR_SIGN(double a, double b)
Definition: xmath.h:412
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:2190

Here is the call graph for this function:

Here is the caller graph for this function:

void TSvd::NR_svdfit ( )

Definition at line 1185 of file xmath.cpp.

References TVVec< TVal >::At(), CfV, ChiSq, CovarVV, TVVec< TVal >::Gen(), GetSig(), GetXV(), GetY(), NR_svbksb(), NR_svdcmp(), NR_svdvar(), Recs, and Vars.

1185  {
1186  int j,i;
1187  double wmax,tmp,thresh,sum;
1188  double TOL=1.0e-5;
1189 
1190  TFltVV u(Recs+1, Vars+1);
1191  TFltVV v(Vars+1, Vars+1);
1192  TFltV w(Vars+1);
1193  TFltV b(Recs+1);
1194  TFltV afunc(Vars+1);
1195  for (i=1;i<=Recs;i++) {
1196  GetXV(i, afunc); // (*funcs)(x[i],afunc,Vars);
1197  tmp=1.0/GetSig(i);
1198  for (j=1;j<=Vars;j++){u.At(i,j)=afunc[j]*tmp;}
1199  b[i]=GetY(i)*tmp;
1200  }
1201  NR_svdcmp(u,Recs,Vars,w,v);
1202  wmax=0.0;
1203  for (j=1;j<=Vars;j++){
1204  if (w[j] > wmax){wmax=w[j];}}
1205  thresh=TOL*wmax;
1206  for (j=1;j<=Vars;j++){
1207  if (double(w[j])<thresh){w[j]=0.0;}}
1208  NR_svbksb(u,w,v,Recs,Vars,b,CfV);
1209  ChiSq=0.0;
1210  for (i=1;i<=Recs;i++) {
1211  GetXV(i, afunc); // (*funcs)(x[i],afunc,Vars);
1212  for (sum=0.0,j=1;j<=Vars;j++){sum += CfV[j]*afunc[j];}
1213  ChiSq += (tmp=(GetY(i)-sum)/GetSig(i),tmp*tmp);
1214  }
1215  // covariance matrix calculation
1216  CovarVV.Gen(Vars+1, Vars+1);
1217  NR_svdvar(v, Vars, w, CovarVV);
1218 }
int Recs
Definition: xmath.h:402
void GetXV(const int RecN, TFltV &VarV) const
Definition: xmath.h:406
static void NR_svdcmp(TFltVV &a, int m, int n, TFltV &w, TFltVV &v)
Definition: xmath.cpp:970
TFltV CfV
Definition: xmath.h:404
Definition: ds.h:2157
double ChiSq
Definition: xmath.h:405
void Gen(const int &_XDim, const int &_YDim)
Definition: ds.h:2181
TFltVV CovarVV
Definition: xmath.h:403
void NR_svdvar(TFltVV &v, int ma, TFltV &w, TFltVV &cvm)
Definition: xmath.cpp:1168
void NR_svbksb(TFltVV &u, TFltV &w, TFltVV &v, int m, int n, TFltV &b, TFltV &x)
Definition: xmath.cpp:1147
int Vars
Definition: xmath.h:402
double GetY(const int RecN) const
Definition: xmath.h:410
double GetSig(const int RecN) const
Definition: xmath.h:411

Here is the call graph for this function:

void TSvd::NR_svdvar ( TFltVV v,
int  ma,
TFltV w,
TFltVV cvm 
)

Definition at line 1168 of file xmath.cpp.

References TVVec< TVal >::At().

Referenced by NR_svdfit().

1168  {
1169  int k,j,i;
1170  double sum;
1171 
1172  TFltV wti(ma+1);
1173  for (i=1;i<=ma;i++) {
1174  wti[i]=0.0;
1175  if (w[i]) wti[i]=1.0/(w[i]*w[i]);
1176  }
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;
1181  }
1182  }
1183 }
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:2190

Here is the call graph for this function:

Here is the caller graph for this function:

TSvd& TSvd::operator= ( const TSvd )
inline

Definition at line 432 of file xmath.h.

References Fail.

432 {Fail; return *this;}
#define Fail
Definition: bd.h:238
void TSvd::Save ( TSOut )
inline

Definition at line 430 of file xmath.h.

References Fail.

430 {Fail;}
#define Fail
Definition: bd.h:238
void TSvd::Svd ( const TFltVV InMtx,
TFltVV LSingV,
TFltV SingValV,
TFltVV RSingV 
)
static

Definition at line 1232 of file xmath.cpp.

References TVVec< TVal >::At(), TVec< TVal, TSizeTy >::Del(), TVVec< TVal >::DelX(), TVVec< TVal >::DelY(), TVec< TVal, TSizeTy >::Gen(), TVVec< TVal >::Gen(), TVVec< TVal >::GetXDim(), TVVec< TVal >::GetYDim(), and NR_svdcmp().

Referenced by TLinAlg::InverseSVD(), New(), and TGraphKey::TakeSig().

1232  {
1233  //LSingV = InMtx;
1234  LSingV.Gen(InMtx.GetYDim()+1, InMtx.GetYDim()+1);
1235  // create 1 based adjacency matrix
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);
1239  }
1240  }
1241  RSingV.Gen(InMtx.GetYDim()+1, InMtx.GetYDim()+1);
1242  SingValV.Gen(InMtx.GetYDim()+1);
1243  TSvd::NR_svdcmp(LSingV, InMtx.GetXDim(), InMtx.GetYDim(), SingValV, RSingV);
1244  // 0-th singular value/vector is full of zeros, delete it
1245  SingValV.Del(0);
1246  LSingV.DelX(0); LSingV.DelY(0);
1247  RSingV.DelX(0); RSingV.DelY(0);
1248 }
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
Definition: ds.h:1130
int GetXDim() const
Definition: ds.h:2184
static void NR_svdcmp(TFltVV &a, int m, int n, TFltV &w, TFltVV &v)
Definition: xmath.cpp:970
void Gen(const int &_XDim, const int &_YDim)
Definition: ds.h:2181
void DelY(const int &Y)
Definition: ds.h:2304
void DelX(const int &X)
Definition: ds.h:2292
int GetYDim() const
Definition: ds.h:2185
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:2190

Here is the call graph for this function:

Here is the caller graph for this function:

void TSvd::Svd1Based ( const TFltVV InMtx1,
TFltVV LSingV,
TFltV SingValV,
TFltVV RSingV 
)
static

Definition at line 1252 of file xmath.cpp.

References TVec< TVal, TSizeTy >::Del(), TVVec< TVal >::DelX(), TVVec< TVal >::DelY(), TVec< TVal, TSizeTy >::Gen(), TVVec< TVal >::Gen(), TVVec< TVal >::GetXDim(), TVVec< TVal >::GetYDim(), and NR_svdcmp().

Referenced by TSnap::GetSngVals(), and TSnap::GetSngVec().

1252  {
1253  LSingV = InMtx1;
1254  SingValV.Gen(InMtx1.GetYDim());
1255  RSingV.Gen(InMtx1.GetYDim(), InMtx1.GetYDim());
1256  TSvd::NR_svdcmp(LSingV, InMtx1.GetXDim()-1, InMtx1.GetYDim()-1, SingValV, RSingV);
1257  // 0-th singular value/vector is full of zeros, delete it
1258  SingValV.Del(0);
1259  LSingV.DelX(0); LSingV.DelY(0);
1260  RSingV.DelX(0); RSingV.DelY(0);
1261 }
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
Definition: ds.h:1130
int GetXDim() const
Definition: ds.h:2184
static void NR_svdcmp(TFltVV &a, int m, int n, TFltV &w, TFltVV &v)
Definition: xmath.cpp:970
void Gen(const int &_XDim, const int &_YDim)
Definition: ds.h:2181
void DelY(const int &Y)
Definition: ds.h:2304
void DelX(const int &X)
Definition: ds.h:2292
int GetYDim() const
Definition: ds.h:2185
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495

Here is the call graph for this function:

Here is the caller graph for this function:

void TSvd::Wr ( ) const

Definition at line 1263 of file xmath.cpp.

References GetCf(), GetCfUncer(), GetChiSq(), GetCovar(), and Vars.

1263  {
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",
1267  i+1, GetCf(i), GetCfUncer(i));
1268  }
1269  printf("chi-squared = %12f\n", GetChiSq());
1270 
1271  printf("full covariance matrix\n");
1272  {for (int i=0;i<Vars;i++){
1273  for (int j=0;j<Vars;j++){
1274  printf("%12f", GetCovar(i, j));}
1275  printf("\n");
1276  }}
1277 }
double GetCovar(const int &VarN1, const int &VarN2) const
Definition: xmath.h:440
double GetChiSq() const
Definition: xmath.h:443
double GetCfUncer(const int &VarN) const
Definition: xmath.h:438
double GetCf(const int &VarN) const
Definition: xmath.h:437
int Vars
Definition: xmath.h:402

Here is the call graph for this function:

Friends And Related Function Documentation

friend class TPt< TSvd >
friend

Definition at line 397 of file xmath.h.

Member Data Documentation

TFltV TSvd::CfV

Definition at line 404 of file xmath.h.

Referenced by GetCfV(), and NR_svdfit().

double TSvd::ChiSq

Definition at line 405 of file xmath.h.

Referenced by NR_svdfit().

TFltVV TSvd::CovarVV

Definition at line 403 of file xmath.h.

Referenced by NR_svdfit().

TCRef TSvd::CRef
private

Definition at line 397 of file xmath.h.

int TSvd::Recs

Definition at line 402 of file xmath.h.

Referenced by NR_svdfit().

TFltV TSvd::SigV

Definition at line 401 of file xmath.h.

int TSvd::Vars

Definition at line 402 of file xmath.h.

Referenced by GetCfUncerV(), NR_svdfit(), and Wr().

TFltVV TSvd::XVV

Definition at line 399 of file xmath.h.

TFltV TSvd::YV

Definition at line 400 of file xmath.h.


The documentation for this class was generated from the following files: