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
109 110 111 |
# File 'lib/statsample/matrix.rb', line 109 def column_size size2 end |
#determinant ⇒ Object
113 114 115 |
# File 'lib/statsample/matrix.rb', line 113 def determinant det end |
#eigenpairs ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/statsample/matrix.rb', line 142 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
121 122 123 |
# File 'lib/statsample/matrix.rb', line 121 def eigenvalues eigenpairs.collect {|v| v[0]} end |
#eigenvectors ⇒ Object
125 126 127 |
# File 'lib/statsample/matrix.rb', line 125 def eigenvectors eigenpairs.collect {|v| v[1]} end |
#eigenvectors_matrix ⇒ Object
136 137 138 139 140 |
# File 'lib/statsample/matrix.rb', line 136 def eigenvectors_matrix eigval, eigvec= GSL::Eigen.symmv(self) GSL::Eigen::symmv_sort(eigval, eigvec, GSL::Eigen::SORT_VAL_DESC) eigvec end |
#inverse ⇒ Object
117 118 119 |
# File 'lib/statsample/matrix.rb', line 117 def inverse GSL::Linalg::LU.invert(self) end |
#mssq ⇒ Object
Matrix sum of squares
130 131 132 133 134 |
# File 'lib/statsample/matrix.rb', line 130 def mssq sum=0 to_v.each {|i| sum+=i**2} sum end |
#row_size ⇒ Object
105 106 107 |
# File 'lib/statsample/matrix.rb', line 105 def row_size size1 end |
#square? ⇒ Boolean
def eigenpairs_ruby
self.to_matrix.eigenpairs_ruby
end
153 154 155 |
# File 'lib/statsample/matrix.rb', line 153 def square? size1==size2 end |
#to_dataframe ⇒ Object Also known as: to_dataset
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/statsample/matrix.rb', line 88 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.update ds.rename(self.name) if self.respond_to? :name ds end |
#to_gsl ⇒ Object
84 85 86 |
# File 'lib/statsample/matrix.rb', line 84 def to_gsl self end |
#to_matrix ⇒ Object
157 158 159 160 161 162 |
# File 'lib/statsample/matrix.rb', line 157 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
164 165 166 167 168 169 170 171 172 |
# File 'lib/statsample/matrix.rb', line 164 def total_sum sum=0 size1.times {|i| size2.times {|j| sum+=self[i,j] } } sum end |