Class: Matrix

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

Instance Method Summary collapse

Instance Method Details

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


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

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

#eigenpairsObject

Optimize eigenpairs of extendmatrix module using gsl


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

def eigenpairs
  to_gsl.eigenpairs
end

#eigenpairs_rubyObject


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

alias_method :eigenpairs_ruby, :eigenpairs

#eigenvaluesObject


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

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

#eigenvectorsObject


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

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

#eigenvectors_matrixObject


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

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
# 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.rename(self.name) if self.respond_to? :name
  ds
end

#to_gslObject


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

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