Class: NuLin::SVD

Inherits:
Object
  • Object
show all
Defined in:
lib/nulin/svd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_valuesObject (readonly)

Singular values as NArray object



40
41
42
# File 'lib/nulin/svd.rb', line 40

def singular_values
  @singular_values
end

#UObject (readonly)

The matrix U



36
37
38
# File 'lib/nulin/svd.rb', line 36

def U
  @U
end

#VtObject (readonly)

Transposed matrix of the matrix V



38
39
40
# File 'lib/nulin/svd.rb', line 38

def Vt
  @Vt
end

Instance Method Details

#sigmaObject

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

#VObject

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