Programmer Guide/Command Reference/EVAL/svd: Difference between revisions

From STX Wiki
Jump to navigationJump to search
No edit summary
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
Compute the variance, covariance or covariance-matrix.
Singular value decomposition ([http://en.wikipedia.org/wiki/Singular_value_decomposition SVD]).
----
----
;Usage 1: '''<code>svd('''0''', <var>A</var>, <var>trn</var>)</code>'''
;Usage 1: <code>svd('''0''', <var>A</var>, <var>trn</var>)</code>
:;<var>A</var>:the NxM matrix to be transformed
:;<var>A</var>:the NxM matrix to be transformed
:;<var>trn</var>:transformation to be applied to A
:;<var>trn</var>:transformation to be applied to A
::{|class="einrahmen"
::{|class="einrahmen"
!''trn'' !!transformed matrix ''T'' !!description !! <code>trn(''T'')*''T'' (MxM matrix)
!''trn'' !!transformed matrix ''T'' (NxM) !!description !! <code>trn(''T'')*''T''</code><BR>(MxM)
|-
|-
|0 ||''T''[i,j] = ''A''[i,j]  
|0 ||''T''[i,j] = ''A''[i,j]  
Line 28: Line 28:
|
|
|}
|}
:;Result 1: The transformed matrix ''T''.
;Result 1: The transformed matrix ''T''.
----
----
;Usage 2: '''<code>svd('''1''', <var>A</var>, <var>trn</var>)</code>'''
;Usage 2: <code>svd('''1''', <var>A</var>, <var>trn</var>)</code>
:;<var>A</var>:the NxM matrix to be transformed
;Result 2: Returns the matrix <code>''C''=trn(''T'')*''T''</code>. ''C'' is a square matrix with M rows and columns (MxM).
:;<var>trn</var>:transformation to be applied to A (see '''Usage 1''')
----
:;Result 2: Computes the transformed matrix ''T'' and returns the matrix ''C''=<code>trn(''T'')*''T''</code>. ''C'' is a square matrix with M rows and columns (MxM).
;Usage 3: <code>svd('''2''', <var>A</var>, <var>trn</var>, <var>U</var>, <var>S</var>, <var>V</var>)</code>
 
:;<var>U</var>:contains on return the NxM matrix ''U''  
 
:;<var>S</var>:contains on return the vector ''S'' with M elements; Note: the returned vector contains the diagonal elements of the matrix &Sigma;, which are called the ''singular values''.
 
:;<var>V</var>:contains on return the MxM matrix ''V''
::{|class="einrahmen"
;Result 3: Computes the SVD of the transformed input matrix ''T''.
!''trn'' !!transformation !!description
::<code>solve: ''T'' = ''U'' * &Sigma; * trn(''V'')</code>
|0 ||''T''[i,j] = ''A''[i,j]
:The results are stored in the (optional) numerical tables (references) ''U'' (NxM), ''S'' (Mx1, diagonal of &Sigma;) and ''V'' (MxM). The return value is the NxM matrix <code>''PC''=''U'' * &Sigma;</code>.
|no transformation
----
|-
;Usage 4: <code>svd('''3''', <var>A</var>, <var>trn</var>, <var>U</var>, <var>S</var>, <var>V</var>)</code>
|1 ||''T''[i,j] = ''A''[i,j]-avr(''A'')
:;<var>S</var>:contains on return the vector ''S'' with M elements; Note: the returned vector contains the diagonal elements of the matrix &Sigma; (''singular values'').
|subtract matrix mean
:;<var>V</var>:contains on return the MxM matrix ''V''
|-
;Result 4: Computes the SVD of the transformed and squared input matrix ''T''.  
|2 ||''T''[i,j] = ''A''[i,j]-avr(''A''[*,j])  
::<code>''C'' = trn(''T'') * ''T''</code>
|subtract column mean (center columns)
::<code>solve: ''C'' = ''V'' * &Sigma; * trn(''V'')</code>
|-
:The results are stored in the (optional) numerical tables (references) ''S'' (Mx1, diagonal of &Sigma;) and ''V'' (MxM). The return value is the NxM matrix <code>''PC''=''A'' * ''V''</code>.
|3 ||''T''[i,j] = (''A''[i,j]-avr(''A''[*,j]))/dev(''A''[*,j])
|subtract column mean, devide by column deviation (center and standardize columns)
|-
|4 ||''T''[i,j] = ''A''[i,j]-(avr(''A''[i,*])+avr(''A''[*,j]))+avr(A)
|subtract row and column mean, add matrix mean (center rows and columns)
|}
 
 
;Result 1: The variance ''v'' of vector ''x''.  
:<code>''v'' = sum( (''x''-avr(''x''))?^2 ) / (nrow(''x'')-1)</code>
:<code>''v'' = (''x''-avr(''x''))^2 / (nrow(''x'')-1)</code>
----
----
;Usage 2: '''<code>var(''x''<sub>vector</sub>, ''y''<sub>vector</sub>)</code>'''
;Usage 5: <code>svd('''4''', <var>C</var>, <var>S</var>, <var>V</var>)</code>
;Result 2: The covariance ''v'' of the vectors ''x'' and ''y''.  
:;<var>C</var>:the MxM input data matrix
:<code>''v'' = sum( (''x''-avr(''x'') ?* (''y''-avr(''y'')) ) / (nrow(''x'')-1)</code>
:;<var>S</var>:contains on return the vector ''S'' with M elements; Note: the returned vector contains the diagonal elements of the matrix &Sigma; (''singular values'').
:<code>''v'' = ((''x''-avr(''x'') * (''y''-avr(''y''))) / (nrow(''x'')-1)</code>
:;<var>V</var>:contains on return the MxM matrix ''V''
;Result 5: Computes the SVD of the matrix ''C''. It is assumed that ''C'' is (optional) transformed and squared matrix derived from a NxM data matrix.
::<code>solve: ''C'' = ''V'' * &Sigma; * trn(''V'')</code>
:The results are stored in the (optional) numerical tables (references) ''S'' (Mx1, diagonal of &Sigma;) and ''V'' (MxM). The return value is always '''0'''.
----
----
;Usage 3: '''<code>var(''x''<sub>matrix</sub>)</code>'''
:'''<code>var(''x''<sub>matrix</sub>, ''y''<sub>scalar</sub>)</code>'''
:'''<code>var(''x''<sub>matrix</sub>, ''y''<sub>vector</sub>)</code>'''
;Result 3: The covariance matrix ''v'' of the column vectors of ''x''.
:<code>''v''[i,j] = sum( (''x''[*,i]-a[i]) ?* (''x''[*,j]-a[j]) ) / (nrow(''x'')-1) , with: i,j = 0..ncol(''x'')-1</code>
:The column averages a[i] are computed as follows:
::{|class="einrahmen"
|''y'' not supplied || a[i] = avr(''x''[*,i])
|-
|''y''<sub>scalar</sub> || a[i] = ''y''
|-
|''y''<sub>vector</sub> || a[i] = ''y''[i]
|-
|}
;See also: [[../var|var]], [[../corr|corr]], [[../dist|dist]], [[../haclust|haclust]], [[../modclust|modclust]]
;See also: [[../var|var]], [[../corr|corr]], [[../dist|dist]], [[../haclust|haclust]], [[../modclust|modclust]]


[[../#Functions|<function list>]]
[[../#Functions|<function list>]]

Latest revision as of 09:50, 21 April 2011

Singular value decomposition (SVD).


Usage 1
svd(0, A, trn)
A
the NxM matrix to be transformed
trn
transformation to be applied to A
trn transformed matrix T (NxM) description trn(T)*T
(MxM)
0 T[i,j] = A[i,j] no transformation "Streumatrix"
1 T[i,j] = A[i,j]-avr(A) subtract matrix mean
2 T[i,j] = A[i,j]-avr(A[*,j]) subtract column mean (center columns) covariance matrix
3 T[i,j] = (A[i,j]-avr(A[*,j]))/dev(A[*,j]) subtract column mean, devide by column deviation (center and standardize columns) correlation matrix
4 T[i,j] = A[i,j]-(avr(A[i,*])+avr(A[*,j]))+avr(A) subtract row and column mean, add matrix mean (center rows and columns)
Result 1
The transformed matrix T.

Usage 2
svd(1, A, trn)
Result 2
Returns the matrix C=trn(T)*T. C is a square matrix with M rows and columns (MxM).

Usage 3
svd(2, A, trn, U, S, V)
U
contains on return the NxM matrix U
S
contains on return the vector S with M elements; Note: the returned vector contains the diagonal elements of the matrix Σ, which are called the singular values.
V
contains on return the MxM matrix V
Result 3
Computes the SVD of the transformed input matrix T.
solve: T = U * Σ * trn(V)
The results are stored in the (optional) numerical tables (references) U (NxM), S (Mx1, diagonal of Σ) and V (MxM). The return value is the NxM matrix PC=U * Σ.

Usage 4
svd(3, A, trn, U, S, V)
S
contains on return the vector S with M elements; Note: the returned vector contains the diagonal elements of the matrix Σ (singular values).
V
contains on return the MxM matrix V
Result 4
Computes the SVD of the transformed and squared input matrix T.
C = trn(T) * T
solve: C = V * Σ * trn(V)
The results are stored in the (optional) numerical tables (references) S (Mx1, diagonal of Σ) and V (MxM). The return value is the NxM matrix PC=A * V.

Usage 5
svd(4, C, S, V)
C
the MxM input data matrix
S
contains on return the vector S with M elements; Note: the returned vector contains the diagonal elements of the matrix Σ (singular values).
V
contains on return the MxM matrix V
Result 5
Computes the SVD of the matrix C. It is assumed that C is (optional) transformed and squared matrix derived from a NxM data matrix.
solve: C = V * Σ * trn(V)
The results are stored in the (optional) numerical tables (references) S (Mx1, diagonal of Σ) and V (MxM). The return value is always 0.

See also
var, corr, dist, haclust, modclust

<function list>

Navigation menu

Personal tools