Class: NuLin::SVD
- Inherits:
-
Object
- Object
- NuLin::SVD
- Defined in:
- lib/nulin/svd.rb
Instance Attribute Summary collapse
-
#singular_values ⇒ Object
readonly
Singular values as NArray object.
-
#U ⇒ Object
readonly
The matrix U.
-
#Vt ⇒ Object
readonly
Transposed matrix of the matrix V.
Instance Method Summary collapse
-
#initialize(matrix, opts) ⇒ SVD
constructor
A new instance of SVD.
-
#sigma ⇒ Object
The matrix sigma.
-
#V ⇒ Object
The matrix V.
Constructor Details
#initialize(matrix, opts) ⇒ SVD
Returns a new instance of SVD.
25 26 27 28 29 30 31 32 33 |
# File 'lib/nulin/svd.rb', line 25 def initialize(matrix, opts) @matrix = matrix @use_U = opts.fetch(:use_U, true) @use_V = opts.fetch(:use_V, true) @full_matrix = opts.fetch(:full_matrix, true) @typecode = matrix.typecode compute end |
Instance Attribute Details
#singular_values ⇒ Object (readonly)
Singular values as NArray object
40 41 42 |
# File 'lib/nulin/svd.rb', line 40 def singular_values @singular_values end |
#U ⇒ Object (readonly)
The matrix U
36 37 38 |
# File 'lib/nulin/svd.rb', line 36 def U @U end |
#Vt ⇒ Object (readonly)
Transposed matrix of the matrix V
38 39 40 |
# File 'lib/nulin/svd.rb', line 38 def Vt @Vt end |
Instance Method Details
#sigma ⇒ Object
The matrix sigma
47 48 49 50 51 |
# File 'lib/nulin/svd.rb', line 47 def sigma return @sigma if @sigma @sigma = NMatrix.new(@matrix.typecode, *@matrix.shape) @sigma.diagonal!(@singular_values.refer) end |
#V ⇒ Object
The matrix V
42 43 44 45 |
# File 'lib/nulin/svd.rb', line 42 def V return nil unless @use_V @V ||= @Vt.transpose end |