Assignments Assignments

SVDFit.inl
Go to the documentation of this file.
1
2//
3// SVDFit.inl
4//
5// Copyright Microsoft Corporation
6//
7// Microsoft Research Graphics Group
8// Kineform Project
9//
10// Abstract: Header for SVDFit routine. This wraps up the lower level SVD
11// stuff from Ronen Barzel. This is the leve of abstraction used
12// by the outside system.
13//
14// Revision History Abstract:
15// 21May1996 ChuckR Initial code start
16// 13Apr1999 ChuckR Templatize and conform to Kineform project style
17// 25Jul1999 ppsloan SVDMat/Apply added - for saving the SVD of a matrix
19
20 template <class REAL>
21 void SVDFit (GXMatrixMNTC<REAL>& A,
22 GXMatrixMNTC<REAL>& vals,
23 GXMatrixMNTC<REAL>& coeffs)
24{
25 GXMatrixMNTC<REAL> u, w, vt;
26 unsigned int m, n, min;
27
28 m = A.Rows();
29 n = A.Cols();
30
31 min = (m < n) ? m : n;
32
33 coeffs.SetDim (n,1);
34
35 u.SetDim (m,min,0.0);
36
37 w.SetDim (min, 1, 0.0);
38
39 vt.SetDim (min,n,0.0);
40
41// num_svd<REAL> (A.Data(), m, n, u.Data(), w.Data(), vt.Data());
42 num_svd (A.Data(), m, n, u.Data(), w.Data(), vt.Data());
43 REAL wmax = ((REAL) 0.0f),
44 threshold;
45
46 for (unsigned int i = 0, cCount = w.Rows() ; i < cCount ; i++)
47 wmax = (wmax > w(i,0)) ? wmax : w(i,0);
48
49 threshold = wmax * ((REAL) 1.0e-5);
50
51// num_svd_backsubst<REAL> (m,n,u.Data(),w.Data(),vt.Data(),
52// vals.Data(),coeffs.Data(),threshold);
53 num_svd_backsubst (m,n,u.Data(),w.Data(),vt.Data(),
54 vals.Data(),coeffs.Data(),threshold);
55}
56
57
58 template <class REAL>
59 void SVDMat(GXMatrixMNTC<REAL>& A, // input - matrix to apply SVD too...
60 GXMatrixMNTC<REAL>& u, // output - SVD of matrix A...
61 GXMatrixMNTC<REAL>& w,
62 GXMatrixMNTC<REAL>& vt)
63{
64 unsigned int m, n, min;
65
66 m = A.Rows();
67 n = A.Cols();
68
69 min = (m < n) ? m : n;
70
71 u.SetDim (m,min,0.0);
72
73 w.SetDim (min, 1, 0.0);
74
75 vt.SetDim (min,n,0.0);
76
77 num_svd<REAL> (A.Data(), m, n, u.Data(), w.Data(), vt.Data());
78}
79
80 template <class REAL>
81 void SVDApply(GXMatrixMNTC<REAL>& u, // input SVD of a matrix
82 GXMatrixMNTC<REAL>& w,
83 GXMatrixMNTC<REAL>& vt,
84 GXMatrixMNTC<REAL>& vals, // input RHS
85 GXMatrixMNTC<REAL>& coeffs)// output x from Ax=b
86{
87 unsigned int m, n, min;
88
89 m = u.Rows();
90 n = vt.Cols();
91
92 min = (m < n) ? m : n;
93
94 coeffs.SetDim (n,1);
95
96 REAL wmax = ((REAL) 0.0f),
97 threshold;
98
99 for (unsigned int i = 0, cCount = w.Rows() ; i < cCount ; i++)
100 wmax = (wmax > w(i,0)) ? wmax : w(i,0);
101
102 threshold = wmax * ((REAL) 1.0e-5);
103
104 num_svd_backsubst<REAL> (m,n,u.Data(),w.Data(),vt.Data(),
105 vals.Data(),coeffs.Data(),threshold);
106}
num_svd
void num_svd(const REAL *a, int m, int n, REAL *u, REAL *w, REAL *vt)
Definition SVD.inl:728
num_svd_backsubst
void num_svd_backsubst(int m, int n, const REAL *u, const REAL *w, const REAL *vt, const REAL b[], REAL x[], REAL eps)
Definition SVD.inl:791
SVDFit
void SVDFit(GXMatrixMNTC< REAL > &A, GXMatrixMNTC< REAL > &vals, GXMatrixMNTC< REAL > &coeffs)
Definition SVDFit.inl:21
SVDMat
void SVDMat(GXMatrixMNTC< REAL > &A, GXMatrixMNTC< REAL > &u, GXMatrixMNTC< REAL > &w, GXMatrixMNTC< REAL > &vt)
Definition SVDFit.inl:59
SVDApply
void SVDApply(GXMatrixMNTC< REAL > &u, GXMatrixMNTC< REAL > &w, GXMatrixMNTC< REAL > &vt, GXMatrixMNTC< REAL > &vals, GXMatrixMNTC< REAL > &coeffs)
Definition SVDFit.inl:81
GXMatrixMNTC
Definition MatrixMNTC.h:48
GXMatrixMNTC::SetDim
void SetDim(unsigned int cRows, unsigned int cCols)
Definition MatrixMNTC.inl:199
GXMatrixMNTC::Cols
unsigned int Cols(void) const
Definition MatrixMNTC.inl:100
GXMatrixMNTC::Data
Coord * Data(void)
Definition MatrixMNTC.inl:106
GXMatrixMNTC::Rows
unsigned int Rows(void) const
Definition MatrixMNTC.inl:193