Class: Matrix

Inherits:
Object show all
Defined in:
lib/statsample/matrix.rb

Instance Method Summary collapse

Instance Method Details

#[]=(i, j, x) ⇒ Object



62
63
64
# File 'lib/statsample/matrix.rb', line 62

def []=(i, j, x)
  @rows[i][j] = x
end

#eigenpairsObject

Optimize eigenpairs of extendmatrix module using gsl



37
38
39
# File 'lib/statsample/matrix.rb', line 37

def eigenpairs
  to_gsl.eigenpairs
end

#eigenpairs_rubyObject



32
# File 'lib/statsample/matrix.rb', line 32

alias_method :eigenpairs_ruby, :eigenpairs

#eigenvaluesObject



42
43
44
# File 'lib/statsample/matrix.rb', line 42

def eigenvalues
  eigenpairs.collect {|v| v[0]}
end

#eigenvectorsObject



46
47
48
# File 'lib/statsample/matrix.rb', line 46

def eigenvectors
  eigenpairs.collect {|v| v[1]}
end

#eigenvectors_matrixObject



50
51
52
# File 'lib/statsample/matrix.rb', line 50

def eigenvectors_matrix
  Matrix.columns(eigenvectors)
end

#to_dataframeObject Also known as: to_dataset



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/statsample/matrix.rb', line 14

def to_dataframe
  f = (self.respond_to? :fields_y) ? fields_y : column_size.times.map {|i| "VAR_#{i+1}".to_sym }
  f = [f] unless f.is_a?(Array)
  ds = Daru::DataFrame.new({}, order: f)
  f.each do |ff|
    ds[ff].rename ff
  end
  row_size.times {|i|
    ds.add_row(self.row(i).to_a)
  }
  ds.update
  ds.rename(self.name) if self.respond_to? :name
  ds
end

#to_gslObject



54
55
56
57
58
59
60
# File 'lib/statsample/matrix.rb', line 54

def to_gsl
  out=[]
  self.row_size.times{|i|
    out[i]=self.row(i).to_a
  }
  GSL::Matrix[*out]
end

#to_matrixObject



10
11
12
# File 'lib/statsample/matrix.rb', line 10

def to_matrix
  self
end