SNAP Library 2.4, Developer Reference  2015-05-11 19:40:56
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
TLinAlg Class Reference

#include <linalg.h>

Public Types

enum  TLinAlgGemmTranspose { GEMM_NO_T = 0, GEMM_A_T = 1, GEMM_B_T = 2, GEMM_C_T = 4 }
 
enum  TLinAlgInverseType { DECOMP_SVD }
 

Static Public Member Functions

static double DotProduct (const TFltV &x, const TFltV &y)
 
static double DotProduct (const TFltVV &X, int ColIdX, const TFltVV &Y, int ColIdY)
 
static double DotProduct (const TFltVV &X, int ColId, const TFltV &Vec)
 
static double DotProduct (const TIntFltKdV &x, const TIntFltKdV &y)
 
static double DotProduct (const TFltV &x, const TIntFltKdV &y)
 
static double DotProduct (const TFltVV &X, int ColId, const TIntFltKdV &y)
 
static void LinComb (const double &p, const TFltV &x, const double &q, const TFltV &y, TFltV &z)
 
static void ConvexComb (const double &p, const TFltV &x, const TFltV &y, TFltV &z)
 
static void AddVec (const double &k, const TFltV &x, const TFltV &y, TFltV &z)
 
static void AddVec (const double &k, const TIntFltKdV &x, const TFltV &y, TFltV &z)
 
static void AddVec (const double &k, const TIntFltKdV &x, TFltV &y)
 
static void AddVec (double k, const TFltVV &X, int ColIdX, TFltVV &Y, int ColIdY)
 
static void AddVec (double k, const TFltVV &X, int ColId, TFltV &Result)
 
static void AddVec (const TIntFltKdV &x, const TIntFltKdV &y, TIntFltKdV &z)
 
static double SumVec (const TFltV &x)
 
static double SumVec (double k, const TFltV &x, const TFltV &y)
 
static double EuclDist2 (const TFltV &x, const TFltV &y)
 
static double EuclDist2 (const TFltPr &x, const TFltPr &y)
 
static double EuclDist (const TFltV &x, const TFltV &y)
 
static double EuclDist (const TFltPr &x, const TFltPr &y)
 
static double Norm2 (const TFltV &x)
 
static double Norm (const TFltV &x)
 
static void Normalize (TFltV &x)
 
static double Norm2 (const TIntFltKdV &x)
 
static double Norm (const TIntFltKdV &x)
 
static void Normalize (TIntFltKdV &x)
 
static double Norm2 (const TFltVV &X, int ColId)
 
static double Norm (const TFltVV &X, int ColId)
 
static double NormL1 (const TFltV &x)
 
static double NormL1 (double k, const TFltV &x, const TFltV &y)
 
static double NormL1 (const TIntFltKdV &x)
 
static void NormalizeL1 (TFltV &x)
 
static void NormalizeL1 (TIntFltKdV &x)
 
static double NormLinf (const TFltV &x)
 
static double NormLinf (const TIntFltKdV &x)
 
static void NormalizeLinf (TFltV &x)
 
static void NormalizeLinf (TIntFltKdV &x)
 
static void MultiplyScalar (const double &k, const TFltV &x, TFltV &y)
 
static void MultiplyScalar (const double &k, const TIntFltKdV &x, TIntFltKdV &y)
 
static void Multiply (const TFltVV &A, const TFltV &x, TFltV &y)
 
static void Multiply (const TFltVV &A, const TFltV &x, TFltVV &C, int ColId)
 
static void Multiply (const TFltVV &A, const TFltVV &B, int ColId, TFltV &y)
 
static void Multiply (const TFltVV &A, const TFltVV &B, int ColIdB, TFltVV &C, int ColIdC)
 
static void MultiplyT (const TFltVV &A, const TFltV &x, TFltV &y)
 
static void Multiply (const TFltVV &A, const TFltVV &B, TFltVV &C)
 
static void Gemm (const double &Alpha, const TFltVV &A, const TFltVV &B, const double &Beta, const TFltVV &C, TFltVV &D, const int &TransposeFlags)
 
static void Inverse (const TFltVV &A, TFltVV &B, const TLinAlgInverseType &DecompType)
 
static void InverseSVD (const TFltVV &A, TFltVV &B)
 
static void Transpose (const TFltVV &A, TFltVV &B)
 
static void GS (TVec< TFltV > &Q)
 
static void GS (TFltVV &Q)
 
static void Rotate (const double &OldX, const double &OldY, const double &Angle, double &NewX, double &NewY)
 
static void AssertOrtogonality (const TVec< TFltV > &Vecs, const double &Threshold)
 
static void AssertOrtogonality (const TFltVV &Vecs, const double &Threshold)
 

Detailed Description

Definition at line 156 of file linalg.h.

Member Enumeration Documentation

Enumerator
GEMM_NO_T 
GEMM_A_T 
GEMM_B_T 
GEMM_C_T 

Definition at line 263 of file linalg.h.

Enumerator
DECOMP_SVD 

Definition at line 268 of file linalg.h.

Member Function Documentation

void TLinAlg::AddVec ( const double &  k,
const TFltV x,
const TFltV y,
TFltV z 
)
static

Definition at line 232 of file linalg.cpp.

References LinComb().

Referenced by GS(), TSparseSVD::Lanczos(), TSparseSVD::Lanczos2(), TFullColMatrix::PMultiply(), and TSparseSVD::SimpleLanczos().

232  {
233  LinComb(k, x, 1.0, y, z);
234 }
static void LinComb(const double &p, const TFltV &x, const double &q, const TFltV &y, TFltV &z)
Definition: linalg.cpp:218

Here is the call graph for this function:

Here is the caller graph for this function:

void TLinAlg::AddVec ( const double &  k,
const TIntFltKdV x,
const TFltV y,
TFltV z 
)
static

Definition at line 236 of file linalg.cpp.

References Assert, and TVec< TVal, TSizeTy >::Len().

236  {
237  Assert(y.Len() == z.Len());
238  z = y; // first we set z to be y
239  // and than we add x to z (==y)
240  const int xLen = x.Len(), yLen = y.Len();
241  for (int i = 0; i < xLen; i++) {
242  const int ii = x[i].Key;
243  if (ii < yLen) {
244  z[ii] = k * x[i].Dat + y[ii];
245  }
246  }
247 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#define Assert(Cond)
Definition: bd.h:251

Here is the call graph for this function:

void TLinAlg::AddVec ( const double &  k,
const TIntFltKdV x,
TFltV y 
)
static

Definition at line 249 of file linalg.cpp.

References TVec< TVal, TSizeTy >::Len().

249  {
250  const int xLen = x.Len(), yLen = y.Len();
251  for (int i = 0; i < xLen; i++) {
252  const int ii = x[i].Key;
253  if (ii < yLen) {
254  y[ii] += k * x[i].Dat;
255  }
256  }
257 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535

Here is the call graph for this function:

void TLinAlg::AddVec ( double  k,
const TFltVV X,
int  ColIdX,
TFltVV Y,
int  ColIdY 
)
static

Definition at line 259 of file linalg.cpp.

References Assert, and TVVec< TVal >::GetRows().

259  {
260  Assert(X.GetRows() == Y.GetRows());
261  const int len = Y.GetRows();
262  for (int i = 0; i < len; i++) {
263  Y(i,ColIdY) = Y(i,ColIdY) + k * X(i, ColIdX);
264  }
265 }
#define Assert(Cond)
Definition: bd.h:251
int GetRows() const
Definition: ds.h:2138

Here is the call graph for this function:

void TLinAlg::AddVec ( double  k,
const TFltVV X,
int  ColId,
TFltV Result 
)
static

Definition at line 267 of file linalg.cpp.

References Assert, TVVec< TVal >::GetRows(), and TVec< TVal, TSizeTy >::Len().

267  {
268  Assert(X.GetRows() == Result.Len());
269  const int len = Result.Len();
270  for (int i = 0; i < len; i++) {
271  Result[i] = Result[i] + k * X(i, ColId);
272  }
273 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#define Assert(Cond)
Definition: bd.h:251
int GetRows() const
Definition: ds.h:2138

Here is the call graph for this function:

void TLinAlg::AddVec ( const TIntFltKdV x,
const TIntFltKdV y,
TIntFltKdV z 
)
static

Definition at line 275 of file linalg.cpp.

References TSparseOps< TKey, TDat >::SparseMerge().

275  {
277 }
static void SparseMerge(const TKeyDatV &SrcV1, const TKeyDatV &SrcV2, TKeyDatV &DstV)
Definition: linalg.h:548

Here is the call graph for this function:

void TLinAlg::AssertOrtogonality ( const TVec< TFltV > &  Vecs,
const double &  Threshold 
)
static

Definition at line 616 of file linalg.cpp.

References TFlt::Abs(), DotProduct(), TVec< TVal, TSizeTy >::Len(), and Norm2().

616  {
617  int m = Vecs.Len();
618  for (int i = 0; i < m; i++) {
619  for (int j = 0; j < i; j++) {
620  double res = DotProduct(Vecs[i], Vecs[j]);
621  if (TFlt::Abs(res) > Threshold)
622  printf("<%d,%d> = %.5f", i,j,res);
623  }
624  double norm = Norm2(Vecs[i]);
625  if (TFlt::Abs(norm-1) > Threshold)
626  printf("||%d|| = %.5f", i, norm);
627  }
628 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
static double Norm2(const TFltV &x)
Definition: linalg.cpp:320
static double Abs(const double &Flt)
Definition: dt.h:1335
static double DotProduct(const TFltV &x, const TFltV &y)
Definition: linalg.cpp:165

Here is the call graph for this function:

void TLinAlg::AssertOrtogonality ( const TFltVV Vecs,
const double &  Threshold 
)
static

Definition at line 630 of file linalg.cpp.

References TFlt::Abs(), DotProduct(), TVVec< TVal >::GetCols(), and Norm2().

630  {
631  int m = Vecs.GetCols();
632  for (int i = 0; i < m; i++) {
633  for (int j = 0; j < i; j++) {
634  double res = DotProduct(Vecs, i, Vecs, j);
635  if (TFlt::Abs(res) > Threshold)
636  printf("<%d,%d> = %.5f", i, j, res);
637  }
638  double norm = Norm2(Vecs, i);
639  if (TFlt::Abs(norm-1) > Threshold)
640  printf("||%d|| = %.5f", i, norm);
641  }
642  printf("\n");
643 }
static double Norm2(const TFltV &x)
Definition: linalg.cpp:320
static double Abs(const double &Flt)
Definition: dt.h:1335
static double DotProduct(const TFltV &x, const TFltV &y)
Definition: linalg.cpp:165
int GetCols() const
Definition: ds.h:2139

Here is the call graph for this function:

void TLinAlg::ConvexComb ( const double &  p,
const TFltV x,
const TFltV y,
TFltV z 
)
static

Definition at line 227 of file linalg.cpp.

References AssertR, TFlt::GetStr(), and LinComb().

227  {
228  AssertR(0.0 <= p && p <= 1.0, TFlt::GetStr(p));
229  LinComb(p, x, 1.0 - p, y, z);
230 }
#define AssertR(Cond, Reason)
Definition: bd.h:258
TStr GetStr() const
Definition: dt.h:1367
static void LinComb(const double &p, const TFltV &x, const double &q, const TFltV &y, TFltV &z)
Definition: linalg.cpp:218

Here is the call graph for this function:

double TLinAlg::DotProduct ( const TFltV x,
const TFltV y 
)
static

Definition at line 165 of file linalg.cpp.

References TStr::Fmt(), IAssertR, and TVec< TVal, TSizeTy >::Len().

Referenced by AssertOrtogonality(), TLogRegFit::GetStepSizeByLineSearch(), TAGMFit::GetStepSizeByLineSearchForLambda(), TCesna::GetStepSizeByLineSearchForWK(), GS(), TSparseSVD::Lanczos(), TSparseSVD::Lanczos2(), TLogRegFit::MLENewton(), Norm2(), TFullColMatrix::PMultiplyT(), and TSparseSVD::SimpleLanczos().

165  {
166  IAssertR(x.Len() == y.Len(), TStr::Fmt("%d != %d", x.Len(), y.Len()));
167  double result = 0.0; int Len = x.Len();
168  for (int i = 0; i < Len; i++)
169  result += x[i] * y[i];
170  return result;
171 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599

Here is the call graph for this function:

Here is the caller graph for this function:

double TLinAlg::DotProduct ( const TFltVV X,
int  ColIdX,
const TFltVV Y,
int  ColIdY 
)
static

Definition at line 173 of file linalg.cpp.

References Assert, and TVVec< TVal >::GetRows().

173  {
174  Assert(X.GetRows() == Y.GetRows());
175  double result = 0.0, len = X.GetRows();
176  for (int i = 0; i < len; i++)
177  result = result + X(i,ColIdX) * Y(i,ColIdY);
178  return result;
179 }
#define Assert(Cond)
Definition: bd.h:251
int GetRows() const
Definition: ds.h:2138

Here is the call graph for this function:

double TLinAlg::DotProduct ( const TFltVV X,
int  ColId,
const TFltV Vec 
)
static

Definition at line 181 of file linalg.cpp.

References Assert, TVVec< TVal >::GetRows(), and TVec< TVal, TSizeTy >::Len().

181  {
182  Assert(X.GetRows() == Vec.Len());
183  double result = 0.0; int Len = X.GetRows();
184  for (int i = 0; i < Len; i++)
185  result += X(i,ColId) * Vec[i];
186  return result;
187 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#define Assert(Cond)
Definition: bd.h:251
int GetRows() const
Definition: ds.h:2138

Here is the call graph for this function:

double TLinAlg::DotProduct ( const TIntFltKdV x,
const TIntFltKdV y 
)
static

Definition at line 189 of file linalg.cpp.

References TVec< TVal, TSizeTy >::Len().

189  {
190  const int xLen = x.Len(), yLen = y.Len();
191  double Res = 0.0; int i1 = 0, i2 = 0;
192  while (i1 < xLen && i2 < yLen) {
193  if (x[i1].Key < y[i2].Key) i1++;
194  else if (x[i1].Key > y[i2].Key) i2++;
195  else { Res += x[i1].Dat * y[i2].Dat; i1++; i2++; }
196  }
197  return Res;
198 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535

Here is the call graph for this function:

double TLinAlg::DotProduct ( const TFltV x,
const TIntFltKdV y 
)
static

Definition at line 200 of file linalg.cpp.

References TVec< TVal, TSizeTy >::Len().

200  {
201  double Res = 0.0; const int xLen = x.Len(), yLen = y.Len();
202  for (int i = 0; i < yLen; i++) {
203  const int key = y[i].Key;
204  if (key < xLen) Res += y[i].Dat * x[key];
205  }
206  return Res;
207 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535

Here is the call graph for this function:

double TLinAlg::DotProduct ( const TFltVV X,
int  ColId,
const TIntFltKdV y 
)
static

Definition at line 209 of file linalg.cpp.

References TVVec< TVal >::GetRows(), and TVec< TVal, TSizeTy >::Len().

209  {
210  double Res = 0.0; const int n = X.GetRows(), yLen = y.Len();
211  for (int i = 0; i < yLen; i++) {
212  const int key = y[i].Key;
213  if (key < n) Res += y[i].Dat * X(key,ColId);
214  }
215  return Res;
216 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
int GetRows() const
Definition: ds.h:2138

Here is the call graph for this function:

double TLinAlg::EuclDist ( const TFltV x,
const TFltV y 
)
static

Definition at line 312 of file linalg.cpp.

References EuclDist2().

312  {
313  return sqrt(EuclDist2(x, y));
314 }
static double EuclDist2(const TFltV &x, const TFltV &y)
Definition: linalg.cpp:298

Here is the call graph for this function:

double TLinAlg::EuclDist ( const TFltPr x,
const TFltPr y 
)
static

Definition at line 316 of file linalg.cpp.

References EuclDist2().

316  {
317  return sqrt(EuclDist2(x, y));
318 }
static double EuclDist2(const TFltV &x, const TFltV &y)
Definition: linalg.cpp:298

Here is the call graph for this function:

double TLinAlg::EuclDist2 ( const TFltV x,
const TFltV y 
)
static

Definition at line 298 of file linalg.cpp.

References Assert, TVec< TVal, TSizeTy >::Len(), and TMath::Sqr().

Referenced by EuclDist().

298  {
299  Assert(x.Len() == y.Len());
300  const int len = x.Len();
301  double Res = 0.0;
302  for (int i = 0; i < len; i++) {
303  Res += TMath::Sqr(x[i] - y[i]);
304  }
305  return Res;
306 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
static double Sqr(const double &x)
Definition: xmath.h:12
#define Assert(Cond)
Definition: bd.h:251

Here is the call graph for this function:

Here is the caller graph for this function:

double TLinAlg::EuclDist2 ( const TFltPr x,
const TFltPr y 
)
static

Definition at line 308 of file linalg.cpp.

References TMath::Sqr(), TPair< TVal1, TVal2 >::Val1, and TPair< TVal1, TVal2 >::Val2.

308  {
309  return TMath::Sqr(x.Val1 - y.Val1) + TMath::Sqr(x.Val2 - y.Val2);
310 }
static double Sqr(const double &x)
Definition: xmath.h:12
TVal1 Val1
Definition: ds.h:34
TVal2 Val2
Definition: ds.h:35

Here is the call graph for this function:

void TLinAlg::Gemm ( const double &  Alpha,
const TFltVV A,
const TFltVV B,
const double &  Beta,
const TFltVV C,
TFltVV D,
const int &  TransposeFlags 
)
static

Definition at line 493 of file linalg.cpp.

References Assert, TVVec< TVal >::At(), GEMM_A_T, GEMM_B_T, GEMM_C_T, TVVec< TVal >::GetCols(), and TVVec< TVal >::GetRows().

494  {
495 
496  bool tA = (TransposeFlags & GEMM_A_T) == GEMM_A_T;
497  bool tB = (TransposeFlags & GEMM_B_T) == GEMM_B_T;
498  bool tC = (TransposeFlags & GEMM_C_T) == GEMM_C_T;
499 
500  // setting dimensions
501  int a_i = tA ? A.GetRows() : A.GetCols();
502  int a_j = tA ? A.GetCols() : A.GetRows();
503 
504  int b_i = tB ? A.GetRows() : A.GetCols();
505  int b_j = tB ? A.GetCols() : A.GetRows();
506 
507  int c_i = tC ? A.GetRows() : A.GetCols();
508  int c_j = tC ? A.GetCols() : A.GetRows();
509 
510  int d_i = D.GetCols();
511  int d_j = D.GetRows();
512 
513  // assertions for dimensions
514  bool Cnd = a_i == c_j && b_i == c_i && a_i == b_j && c_i == d_i && c_j == d_j;
515  if (!Cnd) {
516  Assert(Cnd);
517  }
518 
519  double Aij, Bij, Cij;
520 
521  // rows
522  for (int j = 0; j < a_j; j++) {
523  // cols
524  for (int i = 0; i < a_i; i++) {
525  // not optimized for speed (!)
526  double sum = 0;
527  for (int k = 0; k < a_i; k++) {
528  Aij = tA ? A.At(j, k) : A.At(k, j);
529  Bij = tB ? B.At(k, i) : B.At(i, k);
530  sum += Alpha * Aij * Bij;
531  }
532  Cij = tC ? C.At(i, j) : C.At(j, i);
533  sum += Beta * Cij;
534  D.At(i, j) = sum;
535  }
536  }
537 }
#define Assert(Cond)
Definition: bd.h:251
int GetCols() const
Definition: ds.h:2139
int GetRows() const
Definition: ds.h:2138
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:2142

Here is the call graph for this function:

void TLinAlg::GS ( TVec< TFltV > &  Q)
static

Definition at line 584 of file linalg.cpp.

References AddVec(), DotProduct(), IAssert, TVec< TVal, TSizeTy >::Len(), and Normalize().

Referenced by TSparseSVD::OrtoIterSVD().

584  {
585  IAssert(Q.Len() > 0);
586  int m = Q.Len(); // int n = Q[0].Len();
587  for (int i = 0; i < m; i++) {
588  printf("%d\r",i);
589  for (int j = 0; j < i; j++) {
590  double r = TLinAlg::DotProduct(Q[i], Q[j]);
591  TLinAlg::AddVec(-r,Q[j],Q[i],Q[i]);
592  }
593  TLinAlg::Normalize(Q[i]);
594  }
595  printf("\n");
596 }
#define IAssert(Cond)
Definition: bd.h:262
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
static void Normalize(TFltV &x)
Definition: linalg.cpp:328
static void AddVec(const double &k, const TFltV &x, const TFltV &y, TFltV &z)
Definition: linalg.cpp:232
static double DotProduct(const TFltV &x, const TFltV &y)
Definition: linalg.cpp:165

Here is the call graph for this function:

Here is the caller graph for this function:

void TLinAlg::GS ( TFltVV Q)
static

Definition at line 598 of file linalg.cpp.

References AddVec(), DotProduct(), TVVec< TVal >::GetCols(), TVVec< TVal >::GetRows(), and Norm().

598  {
599  int m = Q.GetCols(), n = Q.GetRows();
600  for (int i = 0; i < m; i++) {
601  for (int j = 0; j < i; j++) {
602  double r = TLinAlg::DotProduct(Q, i, Q, j);
603  TLinAlg::AddVec(-r,Q,j,Q,i);
604  }
605  double nr = TLinAlg::Norm(Q,i);
606  for (int k = 0; k < n; k++)
607  Q(k,i) = Q(k,i) / nr;
608  }
609 }
static double Norm(const TFltV &x)
Definition: linalg.cpp:324
static void AddVec(const double &k, const TFltV &x, const TFltV &y, TFltV &z)
Definition: linalg.cpp:232
static double DotProduct(const TFltV &x, const TFltV &y)
Definition: linalg.cpp:165
int GetCols() const
Definition: ds.h:2139
int GetRows() const
Definition: ds.h:2138

Here is the call graph for this function:

void TLinAlg::Inverse ( const TFltVV A,
TFltVV B,
const TLinAlgInverseType DecompType 
)
static

Definition at line 548 of file linalg.cpp.

References DECOMP_SVD, and InverseSVD().

548  {
549  switch (DecompType) {
550  case DECOMP_SVD:
551  InverseSVD(A, B);
552  }
553 }
static void InverseSVD(const TFltVV &A, TFltVV &B)
Definition: linalg.cpp:555

Here is the call graph for this function:

void TLinAlg::InverseSVD ( const TFltVV A,
TFltVV B 
)
static

Definition at line 555 of file linalg.cpp.

References TVVec< TVal >::At(), TVVec< TVal >::Gen(), TVVec< TVal >::GetCols(), TVVec< TVal >::GetRows(), TVec< TVal, TSizeTy >::Len(), and TSvd::Svd().

Referenced by Inverse().

555  {
556  // create temp matrices
557  TFltVV U, V;
558  TFltV E;
559  TSvd SVD;
560 
561  U.Gen(M.GetRows(), M.GetRows());
562  V.Gen(M.GetCols(), M.GetCols());
563 
564  // do the SVD decompostion
565  SVD.Svd(M, U, E, V);
566 
567  // calculate reciprocal values for diagonal matrix = inverse diagonal
568  for (int i = 0; i < E.Len(); i++) {
569  E[i] = 1 / E[i];
570  }
571 
572  // calculate pseudoinverse: M^(-1) = V * E^(-1) * U'
573  for (int i = 0; i < U.GetCols(); i++) {
574  for (int j = 0; j < V.GetRows(); j++) {
575  double sum = 0;
576  for (int k = 0; k < U.GetCols(); k++) {
577  sum += E[k] * V.At(i, k) * U.At(j, k);
578  }
579  B.At(i, j) = sum;
580  }
581  }
582 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
static void Svd(const TFltVV &InMtx, TFltVV &LSingV, TFltV &SingValV, TFltVV &RSingV)
Definition: xmath.cpp:1232
Definition: xmath.h:397
void Gen(const int &_XDim, const int &_YDim)
Definition: ds.h:2133
int GetCols() const
Definition: ds.h:2139
int GetRows() const
Definition: ds.h:2138
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:2142

Here is the call graph for this function:

Here is the caller graph for this function:

void TLinAlg::LinComb ( const double &  p,
const TFltV x,
const double &  q,
const TFltV y,
TFltV z 
)
static

Definition at line 218 of file linalg.cpp.

References Assert, and TVec< TVal, TSizeTy >::Len().

Referenced by AddVec(), and ConvexComb().

219  {
220 
221  Assert(x.Len() == y.Len() && y.Len() == z.Len());
222  const int Len = x.Len();
223  for (int i = 0; i < Len; i++) {
224  z[i] = p * x[i] + q * y[i]; }
225 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#define Assert(Cond)
Definition: bd.h:251

Here is the call graph for this function:

Here is the caller graph for this function:

void TLinAlg::Multiply ( const TFltVV A,
const TFltV x,
TFltV y 
)
static

Definition at line 428 of file linalg.cpp.

References Assert, TVVec< TVal >::GetCols(), TVVec< TVal >::GetRows(), and TVec< TVal, TSizeTy >::Len().

Referenced by CalcDescriptionLength(), CalcNonNegativeFactorization(), TSparseSVD::Lanczos(), and TSparseSVD::Lanczos2().

428  {
429  Assert(A.GetCols() == x.Len() && A.GetRows() == y.Len());
430  int n = A.GetRows(), m = A.GetCols();
431  for (int i = 0; i < n; i++) {
432  y[i] = 0.0;
433  for (int j = 0; j < m; j++)
434  y[i] += A(i,j) * x[j];
435  }
436 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#define Assert(Cond)
Definition: bd.h:251
int GetCols() const
Definition: ds.h:2139
int GetRows() const
Definition: ds.h:2138

Here is the call graph for this function:

Here is the caller graph for this function:

void TLinAlg::Multiply ( const TFltVV A,
const TFltV x,
TFltVV C,
int  ColId 
)
static

Definition at line 438 of file linalg.cpp.

References Assert, TVVec< TVal >::GetCols(), TVVec< TVal >::GetRows(), and TVec< TVal, TSizeTy >::Len().

438  {
439  Assert(A.GetCols() == x.Len() && A.GetRows() == C.GetRows());
440  int n = A.GetRows(), m = A.GetCols();
441  for (int i = 0; i < n; i++) {
442  C(i,ColId) = 0.0;
443  for (int j = 0; j < m; j++)
444  C(i,ColId) += A(i,j) * x[j];
445  }
446 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#define Assert(Cond)
Definition: bd.h:251
int GetCols() const
Definition: ds.h:2139
int GetRows() const
Definition: ds.h:2138

Here is the call graph for this function:

void TLinAlg::Multiply ( const TFltVV A,
const TFltVV B,
int  ColId,
TFltV y 
)
static

Definition at line 448 of file linalg.cpp.

References Assert, TVVec< TVal >::GetCols(), TVVec< TVal >::GetRows(), and TVec< TVal, TSizeTy >::Len().

448  {
449  Assert(A.GetCols() == B.GetRows() && A.GetRows() == y.Len());
450  int n = A.GetRows(), m = A.GetCols();
451  for (int i = 0; i < n; i++) {
452  y[i] = 0.0;
453  for (int j = 0; j < m; j++)
454  y[i] += A(i,j) * B(j,ColId);
455  }
456 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#define Assert(Cond)
Definition: bd.h:251
int GetCols() const
Definition: ds.h:2139
int GetRows() const
Definition: ds.h:2138

Here is the call graph for this function:

void TLinAlg::Multiply ( const TFltVV A,
const TFltVV B,
int  ColIdB,
TFltVV C,
int  ColIdC 
)
static

Definition at line 458 of file linalg.cpp.

References Assert, TVVec< TVal >::GetCols(), and TVVec< TVal >::GetRows().

458  {
459  Assert(A.GetCols() == B.GetRows() && A.GetRows() == C.GetRows());
460  int n = A.GetRows(), m = A.GetCols();
461  for (int i = 0; i < n; i++) {
462  C(i,ColIdC) = 0.0;
463  for (int j = 0; j < m; j++)
464  C(i,ColIdC) += A(i,j) * B(j,ColIdB);
465  }
466 }
#define Assert(Cond)
Definition: bd.h:251
int GetCols() const
Definition: ds.h:2139
int GetRows() const
Definition: ds.h:2138

Here is the call graph for this function:

void TLinAlg::Multiply ( const TFltVV A,
const TFltVV B,
TFltVV C 
)
static

Definition at line 478 of file linalg.cpp.

References Assert, TVVec< TVal >::GetCols(), and TVVec< TVal >::GetRows().

478  {
479  Assert(A.GetRows() == C.GetRows() && B.GetCols() == C.GetCols() && A.GetCols() == B.GetRows());
480 
481  int n = C.GetRows(), m = C.GetCols(), l = A.GetCols();
482  for (int i = 0; i < n; i++) {
483  for (int j = 0; j < m; j++) {
484  double sum = 0.0;
485  for (int k = 0; k < l; k++)
486  sum += A(i,k)*B(k,j);
487  C(i,j) = sum;
488  }
489  }
490 }
#define Assert(Cond)
Definition: bd.h:251
int GetCols() const
Definition: ds.h:2139
int GetRows() const
Definition: ds.h:2138

Here is the call graph for this function:

void TLinAlg::MultiplyScalar ( const double &  k,
const TFltV x,
TFltV y 
)
static

Definition at line 414 of file linalg.cpp.

References Assert, and TVec< TVal, TSizeTy >::Len().

Referenced by Normalize(), NormalizeL1(), NormalizeLinf(), and TSparseSVD::SimpleLanczos().

414  {
415  Assert(x.Len() == y.Len());
416  int Len = x.Len();
417  for (int i = 0; i < Len; i++)
418  y[i] = k * x[i];
419 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#define Assert(Cond)
Definition: bd.h:251

Here is the call graph for this function:

Here is the caller graph for this function:

void TLinAlg::MultiplyScalar ( const double &  k,
const TIntFltKdV x,
TIntFltKdV y 
)
static

Definition at line 421 of file linalg.cpp.

References Assert, and TVec< TVal, TSizeTy >::Len().

421  {
422  Assert(x.Len() == y.Len());
423  int Len = x.Len();
424  for (int i = 0; i < Len; i++)
425  y[i].Dat = k * x[i].Dat;
426 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#define Assert(Cond)
Definition: bd.h:251

Here is the call graph for this function:

void TLinAlg::MultiplyT ( const TFltVV A,
const TFltV x,
TFltV y 
)
static

Definition at line 468 of file linalg.cpp.

References Assert, TVVec< TVal >::GetCols(), TVVec< TVal >::GetRows(), and TVec< TVal, TSizeTy >::Len().

468  {
469  Assert(A.GetRows() == x.Len() && A.GetCols() == y.Len());
470  int n = A.GetCols(), m = A.GetRows();
471  for (int i = 0; i < n; i++) {
472  y[i] = 0.0;
473  for (int j = 0; j < m; j++)
474  y[i] += A(j,i) * x[j];
475  }
476 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#define Assert(Cond)
Definition: bd.h:251
int GetCols() const
Definition: ds.h:2139
int GetRows() const
Definition: ds.h:2138

Here is the call graph for this function:

double TLinAlg::Norm ( const TFltV x)
static

Definition at line 324 of file linalg.cpp.

References Norm2().

Referenced by GS(), TSparseSVD::Lanczos(), TSparseSVD::Lanczos2(), TAGMFit::MLEGradAscentGivenCAG(), TLogRegFit::MLEGradient(), Normalize(), TSparseSVD::OrtoIterSVD(), and TSparseSVD::SimpleLanczos().

324  {
325  return sqrt(Norm2(x));
326 }
static double Norm2(const TFltV &x)
Definition: linalg.cpp:320

Here is the call graph for this function:

Here is the caller graph for this function:

double TLinAlg::Norm ( const TIntFltKdV x)
static

Definition at line 341 of file linalg.cpp.

References Norm2().

341  {
342  return sqrt(Norm2(x));
343 }
static double Norm2(const TFltV &x)
Definition: linalg.cpp:320

Here is the call graph for this function:

double TLinAlg::Norm ( const TFltVV X,
int  ColId 
)
static

Definition at line 353 of file linalg.cpp.

References Norm2().

353  {
354  return sqrt(Norm2(X, ColId));
355 }
static double Norm2(const TFltV &x)
Definition: linalg.cpp:320

Here is the call graph for this function:

double TLinAlg::Norm2 ( const TFltV x)
static

Definition at line 320 of file linalg.cpp.

References DotProduct().

Referenced by AssertOrtogonality(), TCesna::MLEGradAscent(), TCesna::MLEGradAscentParallel(), and Norm().

320  {
321  return DotProduct(x, x);
322 }
static double DotProduct(const TFltV &x, const TFltV &y)
Definition: linalg.cpp:165

Here is the call graph for this function:

Here is the caller graph for this function:

double TLinAlg::Norm2 ( const TIntFltKdV x)
static

Definition at line 333 of file linalg.cpp.

References TVec< TVal, TSizeTy >::Len(), and TMath::Sqr().

333  {
334  double Result = 0;
335  for (int i = 0; i < x.Len(); i++) {
336  Result += TMath::Sqr(x[i].Dat);
337  }
338  return Result;
339 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
static double Sqr(const double &x)
Definition: xmath.h:12

Here is the call graph for this function:

double TLinAlg::Norm2 ( const TFltVV X,
int  ColId 
)
static

Definition at line 349 of file linalg.cpp.

References DotProduct().

349  {
350  return DotProduct(X, ColId, X, ColId);
351 }
static double DotProduct(const TFltV &x, const TFltV &y)
Definition: linalg.cpp:165

Here is the call graph for this function:

void TLinAlg::Normalize ( TFltV x)
static

Definition at line 328 of file linalg.cpp.

References MultiplyScalar(), and Norm().

Referenced by GS().

328  {
329  const double xNorm = Norm(x);
330  if (xNorm > 0.0) { MultiplyScalar(1/xNorm, x, x); }
331 }
static double Norm(const TFltV &x)
Definition: linalg.cpp:324
static void MultiplyScalar(const double &k, const TFltV &x, TFltV &y)
Definition: linalg.cpp:414

Here is the call graph for this function:

Here is the caller graph for this function:

void TLinAlg::Normalize ( TIntFltKdV x)
static

Definition at line 345 of file linalg.cpp.

References MultiplyScalar(), and Norm().

345  {
346  MultiplyScalar(1/Norm(x), x, x);
347 }
static double Norm(const TFltV &x)
Definition: linalg.cpp:324
static void MultiplyScalar(const double &k, const TFltV &x, TFltV &y)
Definition: linalg.cpp:414

Here is the call graph for this function:

void TLinAlg::NormalizeL1 ( TFltV x)
static

Definition at line 380 of file linalg.cpp.

References MultiplyScalar(), and NormL1().

380  {
381  const double xNorm = NormL1(x);
382  if (xNorm > 0.0) { MultiplyScalar(1/xNorm, x, x); }
383 }
static void MultiplyScalar(const double &k, const TFltV &x, TFltV &y)
Definition: linalg.cpp:414
static double NormL1(const TFltV &x)
Definition: linalg.cpp:357

Here is the call graph for this function:

void TLinAlg::NormalizeL1 ( TIntFltKdV x)
static

Definition at line 385 of file linalg.cpp.

References MultiplyScalar(), and NormL1().

385  {
386  const double xNorm = NormL1(x);
387  if (xNorm > 0.0) { MultiplyScalar(1/xNorm, x, x); }
388 }
static void MultiplyScalar(const double &k, const TFltV &x, TFltV &y)
Definition: linalg.cpp:414
static double NormL1(const TFltV &x)
Definition: linalg.cpp:357

Here is the call graph for this function:

void TLinAlg::NormalizeLinf ( TFltV x)
static

Definition at line 404 of file linalg.cpp.

References MultiplyScalar(), and NormLinf().

404  {
405  const double xNormLinf = NormLinf(x);
406  if (xNormLinf > 0.0) { MultiplyScalar(1.0/xNormLinf, x, x); }
407 }
static void MultiplyScalar(const double &k, const TFltV &x, TFltV &y)
Definition: linalg.cpp:414
static double NormLinf(const TFltV &x)
Definition: linalg.cpp:390

Here is the call graph for this function:

void TLinAlg::NormalizeLinf ( TIntFltKdV x)
static

Definition at line 409 of file linalg.cpp.

References MultiplyScalar(), and NormLinf().

409  {
410  const double xNormLInf = NormLinf(x);
411  if (xNormLInf> 0.0) { MultiplyScalar(1.0/xNormLInf, x, x); }
412 }
static void MultiplyScalar(const double &k, const TFltV &x, TFltV &y)
Definition: linalg.cpp:414
static double NormLinf(const TFltV &x)
Definition: linalg.cpp:390

Here is the call graph for this function:

double TLinAlg::NormL1 ( const TFltV x)
static

Definition at line 357 of file linalg.cpp.

References TFlt::Abs(), and TVec< TVal, TSizeTy >::Len().

Referenced by NormalizeL1().

357  {
358  double norm = 0.0; const int Len = x.Len();
359  for (int i = 0; i < Len; i++)
360  norm += TFlt::Abs(x[i]);
361  return norm;
362 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
static double Abs(const double &Flt)
Definition: dt.h:1335

Here is the call graph for this function:

Here is the caller graph for this function:

double TLinAlg::NormL1 ( double  k,
const TFltV x,
const TFltV y 
)
static

Definition at line 364 of file linalg.cpp.

References TFlt::Abs(), Assert, and TVec< TVal, TSizeTy >::Len().

364  {
365  Assert(x.Len() == y.Len());
366  double norm = 0.0; const int len = x.Len();
367  for (int i = 0; i < len; i++) {
368  norm += TFlt::Abs(k * x[i] + y[i]);
369  }
370  return norm;
371 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#define Assert(Cond)
Definition: bd.h:251
static double Abs(const double &Flt)
Definition: dt.h:1335

Here is the call graph for this function:

double TLinAlg::NormL1 ( const TIntFltKdV x)
static

Definition at line 373 of file linalg.cpp.

References TFlt::Abs(), and TVec< TVal, TSizeTy >::Len().

373  {
374  double norm = 0.0; const int Len = x.Len();
375  for (int i = 0; i < Len; i++)
376  norm += TFlt::Abs(x[i].Dat);
377  return norm;
378 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
static double Abs(const double &Flt)
Definition: dt.h:1335

Here is the call graph for this function:

double TLinAlg::NormLinf ( const TFltV x)
static

Definition at line 390 of file linalg.cpp.

References TFlt::Abs(), TFlt::GetMx(), and TVec< TVal, TSizeTy >::Len().

Referenced by NormalizeLinf().

390  {
391  double norm = 0.0; const int Len = x.Len();
392  for (int i = 0; i < Len; i++)
393  norm = TFlt::GetMx(TFlt::Abs(x[i]), norm);
394  return norm;
395 }
static double GetMx(const double &Flt1, const double &Flt2)
Definition: dt.h:1349
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
static double Abs(const double &Flt)
Definition: dt.h:1335

Here is the call graph for this function:

Here is the caller graph for this function:

double TLinAlg::NormLinf ( const TIntFltKdV x)
static

Definition at line 397 of file linalg.cpp.

References TFlt::Abs(), TFlt::GetMx(), and TVec< TVal, TSizeTy >::Len().

397  {
398  double norm = 0.0; const int Len = x.Len();
399  for (int i = 0; i < Len; i++)
400  norm = TFlt::GetMx(TFlt::Abs(x[i].Dat), norm);
401  return norm;
402 }
static double GetMx(const double &Flt1, const double &Flt2)
Definition: dt.h:1349
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
static double Abs(const double &Flt)
Definition: dt.h:1335

Here is the call graph for this function:

void TLinAlg::Rotate ( const double &  OldX,
const double &  OldY,
const double &  Angle,
double &  NewX,
double &  NewY 
)
static

Definition at line 611 of file linalg.cpp.

611  {
612  NewX = OldX*cos(Angle) - OldY*sin(Angle);
613  NewY = OldX*sin(Angle) + OldY*cos(Angle);
614 }
double TLinAlg::SumVec ( const TFltV x)
static

Definition at line 279 of file linalg.cpp.

References TVec< TVal, TSizeTy >::Len().

Referenced by TAGMFit::Likelihood().

279  {
280  const int len = x.Len();
281  double Res = 0.0;
282  for (int i = 0; i < len; i++) {
283  Res += x[i];
284  }
285  return Res;
286 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535

Here is the call graph for this function:

Here is the caller graph for this function:

double TLinAlg::SumVec ( double  k,
const TFltV x,
const TFltV y 
)
static

Definition at line 288 of file linalg.cpp.

References Assert, and TVec< TVal, TSizeTy >::Len().

288  {
289  Assert(x.Len() == y.Len());
290  const int len = x.Len();
291  double Res = 0.0;
292  for (int i = 0; i < len; i++) {
293  Res += k * x[i] + y[i];
294  }
295  return Res;
296 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#define Assert(Cond)
Definition: bd.h:251

Here is the call graph for this function:

void TLinAlg::Transpose ( const TFltVV A,
TFltVV B 
)
static

Definition at line 539 of file linalg.cpp.

References Assert, TVVec< TVal >::At(), TVVec< TVal >::GetCols(), and TVVec< TVal >::GetRows().

539  {
540  Assert(B.GetRows() == A.GetCols() && B.GetCols() == A.GetRows());
541  for (int i = 0; i < A.GetCols(); i++) {
542  for (int j = 0; j < A.GetRows(); j++) {
543  B.At(i, j) = A.At(j, i);
544  }
545  }
546 }
#define Assert(Cond)
Definition: bd.h:251
int GetCols() const
Definition: ds.h:2139
int GetRows() const
Definition: ds.h:2138
const TVal & At(const int &X, const int &Y) const
Definition: ds.h:2142

Here is the call graph for this function:


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