Class: GSL::Matrix
Instance Method Summary collapse
- #column_size ⇒ Object
- #determinant ⇒ Object
- #eigenpairs ⇒ Object
- #eigenvalues ⇒ Object
- #eigenvectors ⇒ Object
- #eigenvectors_matrix ⇒ Object
- #inverse ⇒ Object
-
#mssq ⇒ Object
Matrix sum of squares.
- #row_size ⇒ Object
-
#square? ⇒ Boolean
def eigenpairs_ruby self.to_matrix.eigenpairs_ruby end.
- #to_dataframe ⇒ Object (also: #to_dataset)
- #to_gsl ⇒ Object
- #to_matrix ⇒ Object
- #total_sum ⇒ Object
Instance Method Details
#column_size ⇒ Object
107 108 109 |
# File 'lib/statsample/matrix.rb', line 107 def column_size size2 end |
#determinant ⇒ Object
111 112 113 |
# File 'lib/statsample/matrix.rb', line 111 def determinant det end |
#eigenpairs ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/statsample/matrix.rb', line 140 def eigenpairs eigval, eigvec= GSL::Eigen.symmv(self) GSL::Eigen::symmv_sort(eigval, eigvec, GSL::Eigen::SORT_VAL_DESC) @eigenpairs=eigval.size.times.map {|i| [eigval[i],eigvec.get_col(i)] } end |
#eigenvalues ⇒ Object
119 120 121 |
# File 'lib/statsample/matrix.rb', line 119 def eigenvalues eigenpairs.collect {|v| v[0]} end |
#eigenvectors ⇒ Object
123 124 125 |
# File 'lib/statsample/matrix.rb', line 123 def eigenvectors eigenpairs.collect {|v| v[1]} end |
#eigenvectors_matrix ⇒ Object
134 135 136 137 138 |
# File 'lib/statsample/matrix.rb', line 134 def eigenvectors_matrix eigval, eigvec= GSL::Eigen.symmv(self) GSL::Eigen::symmv_sort(eigval, eigvec, GSL::Eigen::SORT_VAL_DESC) eigvec end |
#inverse ⇒ Object
115 116 117 |
# File 'lib/statsample/matrix.rb', line 115 def inverse GSL::Linalg::LU.invert(self) end |
#mssq ⇒ Object
Matrix sum of squares
128 129 130 131 132 |
# File 'lib/statsample/matrix.rb', line 128 def mssq sum=0 to_v.each {|i| sum+=i**2} sum end |
#row_size ⇒ Object
103 104 105 |
# File 'lib/statsample/matrix.rb', line 103 def row_size size1 end |
#square? ⇒ Boolean
def eigenpairs_ruby
self.to_matrix.eigenpairs_ruby
end
151 152 153 |
# File 'lib/statsample/matrix.rb', line 151 def square? size1==size2 end |
#to_dataframe ⇒ Object Also known as: to_dataset
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/statsample/matrix.rb', line 87 def to_dataframe f = (self.respond_to? :fields_y) ? fields_y : column_size.times.map { |i| "VAR_#{i+1}".to_sym } 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_gsl ⇒ Object
83 84 85 |
# File 'lib/statsample/matrix.rb', line 83 def to_gsl self end |
#to_matrix ⇒ Object
155 156 157 158 159 160 |
# File 'lib/statsample/matrix.rb', line 155 def to_matrix rows=self.size1 cols=self.size2 out=(0...rows).collect{|i| (0...cols).collect {|j| self[i,j]} } ::Matrix.rows(out) end |
#total_sum ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/statsample/matrix.rb', line 162 def total_sum sum=0 size1.times {|i| size2.times {|j| sum+=self[i,j] } } sum end |